From: Hugo Villeneuve Date: Wed, 12 Feb 2014 02:54:49 +0000 (-0500) Subject: Fix checkpatch warnings X-Git-Tag: v2.0.1~18 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=5419d1bd9d2faae98c78da740634b972e8f5aac1;p=emu8051.git Fix checkpatch warnings --- diff --git a/src/cli/keyboard.c b/src/cli/keyboard.c index 44927e5..ae0cd91 100644 --- a/src/cli/keyboard.c +++ b/src/cli/keyboard.c @@ -18,17 +18,21 @@ kbhit(void) { char ch; int nread; + if (peek != -1) return 1; + newtio.c_cc[VMIN] = 0; tcsetattr(0, TCSANOW, &newtio); nread = read(0, &ch, 1); newtio.c_cc[VMIN] = 1; tcsetattr(0, TCSANOW, &newtio); + if (nread == 1) { peek = ch; return 1; } + return 0; } @@ -36,17 +40,20 @@ int getch(void) { char ch; + if (peek != -1) { ch = peek; peek = -1; return ch; } + read(0, &ch, 1); + return ch; } void -InitUnixKB(void) +keyboard_init(void) { tcgetattr(0, &orig); newtio = orig; @@ -59,7 +66,7 @@ InitUnixKB(void) } void -ResetUnixKB(void) +keyboard_reset(void) { tcsetattr(0, TCSANOW, &orig); } diff --git a/src/cli/keyboard.h b/src/cli/keyboard.h index 42f5479..c89cc92 100644 --- a/src/cli/keyboard.h +++ b/src/cli/keyboard.h @@ -17,9 +17,9 @@ int getch(void); void -InitUnixKB(void); +keyboard_init(void); void -ResetUnixKB(void); +keyboard_reset(void); #endif /* _KEYBOARD_H_ */ diff --git a/src/cli/main.c b/src/cli/main.c index 216a1d2..fca5d9e 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -31,7 +31,7 @@ main(int argc, char **argv) cpu8051_init(); if (options.filename != NULL) { - rc = LoadHexFile(options.filename); + rc = hexfile_load(options.filename); if (rc == false) exit(1); } diff --git a/src/cli/menu.c b/src/cli/menu.c index bc8a3fd..579e950 100644 --- a/src/cli/menu.c +++ b/src/cli/menu.c @@ -39,34 +39,34 @@ extern struct options_t options; int menu_get_input(char *buf, ssize_t size) { - char *line; + char *line; int max_len; max_len = size - 2; - if (feof(yyin)) - return YY_NULL; + if (feof(yyin)) + return YY_NULL; #ifdef HAVE_LIBREADLINE /* Get the input line, and if non-empty, place it in the history. */ line = readline(MENU_PROMPT); - if (!line) - return YY_NULL; + if (!line) + return YY_NULL; if (line && *line) add_history(line); - if ((int) strlen(line) > max_len) { - printf("input line too long"); - return YY_NULL; - } + if ((int) strlen(line) > max_len) { + printf("input line too long"); + return YY_NULL; + } - strcpy(buf, line); + strcpy(buf, line); /* Readline never gives you the last '\n', so add it back for Lex. */ - strcat(buf, "\n"); + strcat(buf, "\n"); - free(line); + free(line); #else /* It's okay to print a prompt if we are redirecting stdout, * as long as stdin is still a tty. Otherwise, don't print @@ -79,7 +79,7 @@ menu_get_input(char *buf, ssize_t size) return YY_NULL; #endif - return strlen(buf); + return strlen(buf); } void @@ -124,23 +124,23 @@ menu_display_usage(void) /* Disassemble NumberInst instructions at Address */ void -DisasmN(unsigned int Address, int NumberInst) +disassemble_num(unsigned int address, int num) { - char TextTmp[255]; - int Row; + char str[255]; + int row; - for (Row = 0; Row < NumberInst ; Row++) { - Address += cpu8051_Disasm(Address, TextTmp); - printf("%s\n", TextTmp); + for (row = 0; row < num; row++) { + address += cpu8051_disasm(address, str); + printf("%s\n", str); - if (Address > 0xFFFF) + if (address > 0xFFFF) return; } } /* Capitalize all letters in buffer */ static void -Capitalize(char *buffer) +uppercase(char *buffer) { size_t k; @@ -150,22 +150,22 @@ Capitalize(char *buffer) /* Set NewValue to Register */ void -SetRegister(char *register_name, int new) +register_set(char *name, int value) { struct regwin_infos_t *regwin_infos; - Capitalize(register_name); + uppercase(name); - log_debug(" Modify register %s to $%04X", register_name, new); + log_debug(" Modify register %s to $%04X", name, value); - regwin_infos = sfr_get_infos(register_name); + regwin_infos = sfr_get_infos(name); if (regwin_infos == NULL) { printf("Invalid register name\n"); return; } - regwin_write(regwin_infos, new); + regwin_write(regwin_infos, value); } /* CPU reset and Console UI update */ @@ -173,40 +173,41 @@ void console_reset(void) { log_info("Resetting..."); - cpu8051_Reset(); + cpu8051_reset(); log_info("Done"); } /* * CPU exec and Console UI update - * NbInst = -1: run to infinity + * num = number of instructions to execute. + * set to -1: run to infinity */ void -console_exec(int NbInst) +console_exec(int num) { - InitUnixKB(); + keyboard_init(); log_info("Program executing..."); - cpu8051_run(NbInst, kbhit); + cpu8051_run(num, kbhit); if (kbhit()) { (void) getch(); /* Flush key */ log_info("Caught break signal!"); } - ResetUnixKB(); + keyboard_reset(); console_show_registers(); - DisasmN(cpu8051.pc, 1); + disassemble_num(cpu8051.pc, 1); } /* CPU trace and Console UI update */ void console_trace(void) { - cpu8051_Exec(); + cpu8051_exec(); console_show_registers(); - DisasmN(cpu8051.pc, 1); + disassemble_num(cpu8051.pc, 1); } /* Show CPU registers, one per line */ @@ -239,47 +240,39 @@ console_dump_sfr_registers_compact(void) { int id; unsigned char PSW = cpu8051_ReadD(_PSW_); - int BankSelect = (PSW & 0x18); + int bank_sel = (PSW & 0x18); - printf("---------------------------------------------------------------" - "-------\n"); - printf("| PC | SP | DPTR | ACC | B | PSW: CY AC F0 RS1 RS0 OV" - " - P |\n"); + 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(_SP_), 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, (PSW >> 3) & 1, (PSW >> 2) & 1, (PSW >> 1) & 1, PSW & 1); printf("\n"); - printf("---------------------------------------------------------------" - "-------\n"); + printf("----------------------------------------------------------------------\n"); - printf("| TCON | TMOD | IE | IP | R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7" - " | |\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 ", - cpu8051_ReadD(BankSelect + _R0_), - cpu8051_ReadD(BankSelect + _R1_), - cpu8051_ReadD(BankSelect + _R2_), - cpu8051_ReadD(BankSelect + _R3_)); + cpu8051_ReadD(bank_sel + _R0_), + cpu8051_ReadD(bank_sel + _R1_), + cpu8051_ReadD(bank_sel + _R2_), + cpu8051_ReadD(bank_sel + _R3_)); printf("| %.2X | %.2X | %.2X | %.2X ", - cpu8051_ReadD(BankSelect + _R4_), - cpu8051_ReadD(BankSelect + _R5_), - cpu8051_ReadD(BankSelect + _R6_), - cpu8051_ReadD(BankSelect + _R7_)); + cpu8051_ReadD(bank_sel + _R4_), + cpu8051_ReadD(bank_sel + _R5_), + cpu8051_ReadD(bank_sel + _R6_), + cpu8051_ReadD(bank_sel + _R7_)); printf("| |\n"); - printf("---------------------------------------------------------------" - "-------\n"); + printf("----------------------------------------------------------------------\n"); for (id = 0; id < GP_TIMERS_COUNT; id++) printf("| Emulator timer %c: %08d |\n", 'A' + id, gp_timer_read(id)); printf("------------------------------\n"); - - } /* Show CPU registers */ diff --git a/src/cli/menu.h b/src/cli/menu.h index 5ec9da5..78afc19 100644 --- a/src/cli/menu.h +++ b/src/cli/menu.h @@ -23,18 +23,18 @@ void console_show_registers(void); void -SetRegister(char *Register, int NewValue); +register_set(char *name, int value); void console_reset(void); void -console_exec(int NbInst); +console_exec(int num); void console_trace(void); void -DisasmN(unsigned int Address, int NumberInst); +disassemble_num(unsigned int address, int num); #endif /* _MENU_H_ */ diff --git a/src/cli/parser.y b/src/cli/parser.y index a28f29e..cd813b6 100644 --- a/src/cli/parser.y +++ b/src/cli/parser.y @@ -86,19 +86,19 @@ breakpoint_clr: TOK_RB NUMBER TOK_ENTER { log_debug(" Remove breakpoint at $%04X", $2); - ClearBreakpoint($2); + breakpoint_clr($2); } | TOK_RB TOK_ENTER { log_debug(" Remove breakpoint at PC"); - ClearBreakpoint(cpu8051.pc); + breakpoint_clr(cpu8051.pc); } | TOK_RB TOK_ALL TOK_ENTER { log_debug(" Remove all breakpoints"); - ClearAllBreakpoints(); + breakpoints_clr_all(); } ; @@ -106,14 +106,14 @@ breakpoint_set: TOK_SB TOK_ENTER { log_debug(" Set breakpoint at PC"); - SetBreakpoint(cpu8051.pc); + breakpoint_set(cpu8051.pc); } | TOK_SB NUMBER TOK_ENTER { log_debug(" Set breakpoint at $%04X", $2); - SetBreakpoint($2); + breakpoint_set($2); } ; @@ -121,7 +121,7 @@ breakpoint_display: TOK_DB TOK_ENTER { log_debug(" Display breakpoints"); - ShowBreakpoints(); + breakpoints_show(); } ; @@ -174,7 +174,7 @@ modify: | TOK_MOD_REG WORD NUMBER TOK_ENTER { - SetRegister($2, $3); + register_set($2, $3); } ; @@ -210,7 +210,7 @@ help: reset: TOK_RST TOK_ENTER { - cpu8051_Reset(); + cpu8051_reset(); } | TOK_RST_TIMER TOK_A TOK_ENTER @@ -244,18 +244,18 @@ step: unasm: TOK_UNASM NUMBER NUMBER TOK_ENTER { - DisasmN($2, $3); + disassemble_num($2, $3); } | TOK_UNASM NUMBER TOK_ENTER { - DisasmN(cpu8051.pc, $2); + disassemble_num(cpu8051.pc, $2); } ; | TOK_UNASM TOK_ENTER { - DisasmN(cpu8051.pc, 16); + disassemble_num(cpu8051.pc, 16); } ; diff --git a/src/common/common.h b/src/common/common.h index ce9c83d..345a21a 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -38,10 +38,6 @@ /* Returns TRUE if the first 'c' characters of strings 'a' and 'b' are equal. */ #define STREQ_LEN(a, b, c) (strncasecmp((a), (b), (c)) == 0) - -inline void -ErrorLocation(const char *file, int line); - void * xmalloc(size_t size, const char *filename, int line_number); diff --git a/src/common/cpu8051.c b/src/common/cpu8051.c index d789bd6..7eb3db9 100644 --- a/src/common/cpu8051.c +++ b/src/common/cpu8051.c @@ -28,7 +28,7 @@ extern struct options_t options; /* Check if the address is a breakpoint */ int -IsBreakpoint(unsigned int address) +breakpoint_is_defined(unsigned int address) { int k; @@ -41,19 +41,9 @@ IsBreakpoint(unsigned int address) return false; } -/* Check if the address is a stop point */ -int -IsStoppoint(unsigned int address) -{ - if ((options.stop_address != 0) && (options.stop_address == address)) - return true; - else - return false; -} - /* Show Breakpoints list */ void -ShowBreakpoints(void) +breakpoints_show(void) { int k; @@ -61,39 +51,40 @@ ShowBreakpoints(void) printf("Breakpoints:\n"); for (k = 0; k < cpu8051.bp_count; k++) printf(" $%.4X\n", cpu8051.bp[k]); - } else + } else { printf("No breakpoints defined\n"); + } } /* Set Breakpoint at address at the end of the breakpoint list */ void -SetBreakpoint(unsigned int address) +breakpoint_set(unsigned int address) { int rc; rc = memory_check_address(PGM_MEM_ID, address, DISPLAY_ERROR_YES); - if (rc == false) + if (!rc) return; /* Error */ /* Check if breakpoint is already defined. */ - if ((IsBreakpoint(address) == false) && + if ((breakpoint_is_defined(address) == false) && (cpu8051.bp_count < MAXBP)) cpu8051.bp[cpu8051.bp_count++] = address; } /* Clear Breakpoint at Address from list */ void -ClearBreakpoint(unsigned int address) +breakpoint_clr(unsigned int address) { int k; int rc; rc = memory_check_address(PGM_MEM_ID, address, DISPLAY_ERROR_YES); - if (rc == false) + if (!rc) return; /* Error */ /* Check if breakpoint is defined. */ - if (IsBreakpoint(address) == false) { + if (breakpoint_is_defined(address) == false) { log_err("No breakpoint defined at address $%X", address); return; } @@ -109,19 +100,29 @@ ClearBreakpoint(unsigned int address) /* Clear all breakpoints */ void -ClearAllBreakpoints(void) +breakpoints_clr_all(void) { cpu8051.bp_count = 0; } /* Toggle the breakpoint at Address. */ void -ToggleBreakpoint(unsigned int address) +breakpoint_toggle(unsigned int address) { - if (IsBreakpoint(address)) - ClearBreakpoint(address); + if (breakpoint_is_defined(address)) + breakpoint_clr(address); else - SetBreakpoint(address); + breakpoint_set(address); +} + +/* Check if the address is a stop point */ +static int +stop_point_is_defined(unsigned int address) +{ + if ((options.stop_address != 0) && (options.stop_address == address)) + return true; + else + return false; } void @@ -142,7 +143,7 @@ cpu8051_init(void) /* Reset the registers and CPU state */ void -cpu8051_Reset(void) +cpu8051_reset(void) { cpu8051.pc = 0; cpu8051.clock = 0; @@ -177,21 +178,21 @@ cpu8051_convert_bit_address(uint8_t bit_address, uint8_t *byte_address, /* Write with a direct addressing mode at Address the new Value */ void -cpu8051_WriteD(unsigned int Address, unsigned char Value) +cpu8051_WriteD(unsigned int address, unsigned char value) { - memory_write8(INT_MEM_ID, Address, 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) +cpu8051_WriteI(unsigned int address, unsigned char value) { - if (Address > 0x7F) { - memory_write8(EXT_MEM_ID, Address, Value); + if (address > 0x7F) { + memory_write8(EXT_MEM_ID, address, value); return; } - memory_write8(INT_MEM_ID, Address, Value); + memory_write8(INT_MEM_ID, address, value); } /* Write with a bit addressing mode at BitAddress the new Value */ @@ -200,34 +201,34 @@ cpu8051_WriteB(uint8_t bit_address, uint8_t value) { uint8_t byte_address; uint8_t bit_number; - unsigned char ByteValue, ByteMask; + unsigned char byte_val, byte_mask; cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); - ByteMask = ((1 << bit_number) ^ 0xFF); - ByteValue = cpu8051_ReadD(byte_address) & ByteMask; - ByteValue += value << bit_number; - cpu8051_WriteD(byte_address, ByteValue); + 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) +cpu8051_ReadD(unsigned int address) { - if (Address > 0xFF) - return memory_read8(EXT_MEM_ID, Address); + if (address > 0xFF) + return memory_read8(EXT_MEM_ID, address); else - return memory_read8(INT_MEM_ID, Address); + return memory_read8(INT_MEM_ID, address); } /* Read with a indirect addressing mode at Address */ unsigned char -cpu8051_ReadI(unsigned int Address) +cpu8051_ReadI(unsigned int address) { - if (Address > 0x7F) - return memory_read8(EXT_MEM_ID, Address); + if (address > 0x7F) + return memory_read8(EXT_MEM_ID, address); else - return memory_read8(INT_MEM_ID, Address); + return memory_read8(INT_MEM_ID, address); } /* Read with a bit addressing mode at BitAddress */ @@ -236,13 +237,13 @@ cpu8051_ReadB(uint8_t bit_address) { uint8_t byte_address; uint8_t bit_number; - unsigned char BitValue; + unsigned char bit_value; cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); - BitValue = (cpu8051_ReadD(byte_address) >> bit_number); - BitValue &= 1; - return BitValue; + bit_value = (cpu8051_ReadD(byte_address) >> bit_number); + bit_value &= 1; + return bit_value; } static int @@ -271,7 +272,7 @@ cpu8051_process_interrupt(int pc, int pri) /* Check interrupts state and process them as needed */ static void -cpu8051_CheckInterrupts(void) +cpu8051_check_interrupts(void) { int i; @@ -283,7 +284,7 @@ cpu8051_CheckInterrupts(void) /* Interrupt timer 0 */ if (cpu8051_interrupt_enabled(INTERRUPT_1) && cpu8051_interrupt_fire(INTERRUPT_1, i) && - (cpu8051_ReadD(_TCON_) & 0x20)) { + (cpu8051_ReadD(_TCON_) & 0x20)) { cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) & 0xDF); cpu8051_process_interrupt(0x0B, i); @@ -318,7 +319,7 @@ cpu8051_CheckInterrupts(void) /* Execute at address cpu8051.pc from PGMMem */ int -cpu8051_Exec(void) +cpu8051_exec(void) { int i; int rc; @@ -327,7 +328,7 @@ cpu8051_Exec(void) /* Basic address check (may fail later if opcode has operands). */ rc = memory_check_address(PGM_MEM_ID, cpu8051.pc, DISPLAY_ERROR_NO); - if (rc == false) { + if (!rc) { log_err("Trying to run past program memory limit"); return false; /* Error */ } @@ -345,7 +346,7 @@ cpu8051_Exec(void) gp_timers_increment(insttiming); for (i = 0; i < insttiming; i++) { - cpu8051_CheckInterrupts(); + cpu8051_check_interrupts(); timers_check(); cpu8051.clock++; } @@ -365,36 +366,36 @@ int cpu8051_run(int instr_count, int (*interface_stop)(void)) { int rc; - int stop = false; + int run = true; int breakpoint_hit = false; - while (stop == false) { - rc = cpu8051_Exec(); - if (rc == false) - stop = true; - else { + while (run) { + rc = cpu8051_exec(); + if (!rc) { + run = false; + } else { if (instr_count > 0) instr_count--; if (instr_count == 0) { - stop = true; + run = false; log_info("Number of instructions reached"); } - if (IsBreakpoint(cpu8051.pc)) { - stop = true; + if (breakpoint_is_defined(cpu8051.pc)) { + run = false; breakpoint_hit = true; log_info("Breakpoint hit at %.4X", cpu8051.pc); } - if (IsStoppoint(cpu8051.pc)) { - stop = true; + if (stop_point_is_defined(cpu8051.pc)) { + run = false; log_info("Stoppoint hit at %.4X", cpu8051.pc); } if (interface_stop != NULL) { if (interface_stop()) { - stop = true; + run = false; log_info("Caught break signal"); } } @@ -441,42 +442,42 @@ cpu8051_run(int instr_count, int (*interface_stop)(void)) /* Return as Text the name of the SFR register at Address if any */ static int -cpu8051_SFRMemInfo(unsigned int Address, char *Text) +cpu8051_sfr_mem_info(unsigned int address, char *text) { - switch (Address) { - case 0x80: return sprintf(Text, "P0"); - case 0x81: return sprintf(Text, "SP"); - case 0x82: return sprintf(Text, "DPL"); - case 0x83: return sprintf(Text, "DPH"); - case 0x87: return sprintf(Text, "PCON"); - case 0x88: return sprintf(Text, "TCON"); - case 0x89: return sprintf(Text, "TMOD"); - case 0x8A: return sprintf(Text, "TL0"); - case 0x8B: return sprintf(Text, "TL1"); - case 0x8C: return sprintf(Text, "TH0"); - case 0x8D: return sprintf(Text, "TH1"); - case 0x90: return sprintf(Text, "P1"); - case 0x98: return sprintf(Text, "SCON"); - case 0x99: return sprintf(Text, "SBUF"); - case 0xA0: return sprintf(Text, "P2"); - case 0xA8: return sprintf(Text, "IE"); - case 0xB0: return sprintf(Text, "P3"); - case 0xB8: return sprintf(Text, "IP"); - case 0xC8: return sprintf(Text, "T2CON"); - case 0xCA: return sprintf(Text, "RCAP2L"); - case 0xCB: return sprintf(Text, "RCAP2H"); - case 0xCC: return sprintf(Text, "TL2"); - case 0xCD: return sprintf(Text, "TH2"); - case 0xD0: return sprintf(Text, "PSW"); - case 0xE0: return sprintf(Text, "ACC"); - case 0xF0: return sprintf(Text, "B"); - default: return sprintf(Text, "%.2XH", Address); + switch (address) { + case 0x80: return sprintf(text, "P0"); + case 0x81: return sprintf(text, "SP"); + case 0x82: return sprintf(text, "DPL"); + case 0x83: return sprintf(text, "DPH"); + case 0x87: return sprintf(text, "PCON"); + case 0x88: return sprintf(text, "TCON"); + case 0x89: return sprintf(text, "TMOD"); + case 0x8A: return sprintf(text, "TL0"); + case 0x8B: return sprintf(text, "TL1"); + case 0x8C: return sprintf(text, "TH0"); + case 0x8D: return sprintf(text, "TH1"); + case 0x90: return sprintf(text, "P1"); + case 0x98: return sprintf(text, "SCON"); + case 0x99: return sprintf(text, "SBUF"); + case 0xA0: return sprintf(text, "P2"); + case 0xA8: return sprintf(text, "IE"); + case 0xB0: return sprintf(text, "P3"); + case 0xB8: return sprintf(text, "IP"); + case 0xC8: return sprintf(text, "T2CON"); + case 0xCA: return sprintf(text, "RCAP2L"); + case 0xCB: return sprintf(text, "RCAP2H"); + case 0xCC: return sprintf(text, "TL2"); + case 0xCD: return sprintf(text, "TH2"); + case 0xD0: return sprintf(text, "PSW"); + case 0xE0: return sprintf(text, "ACC"); + case 0xF0: return sprintf(text, "B"); + default: return sprintf(text, "%.2XH", address); } } -/* Return as Text the decoded BitAddress */ +/* Return as text the decoded bit address */ static void -cpu8051_IntMemBitInfo(uint8_t bit_address, char *text) +cpu8051_int_mem_bit_info(uint8_t bit_address, char *text) { uint8_t byte_address; uint8_t bit_number; @@ -484,7 +485,7 @@ cpu8051_IntMemBitInfo(uint8_t bit_address, char *text) cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); - len = cpu8051_SFRMemInfo(byte_address, text); + len = cpu8051_sfr_mem_info(byte_address, text); sprintf(&text[len], ".%X", bit_address); } @@ -497,9 +498,9 @@ cpu8051_get_instruction_size(unsigned char opcode) /* Display instruction mnemonic. */ void -cpu8051_disasm_mnemonic(unsigned char OpCode, char *buf) +cpu8051_disasm_mnemonic(unsigned char opcode, char *buf) { - sprintf(buf, "%s", InstTextTbl[InstTypesTbl[OpCode]]); + sprintf(buf, "%s", InstTextTbl[InstTypesTbl[opcode]]); } /* Disasm instruction arguments starting at address into a text string */ @@ -507,26 +508,26 @@ void cpu8051_disasm_args(unsigned int address, char *buf) { int len = 0; - char TextTmp[20]; - unsigned char OpCode; + char str[20]; + unsigned char opcode; int ArgTblOfs; int i; - OpCode = memory_read8(PGM_MEM_ID, address); - ArgTblOfs = OpCode << 2; + opcode = memory_read8(PGM_MEM_ID, address); + ArgTblOfs = opcode << 2; address++; /* - * MOV direct, direct (OpCode 85h) is peculiar, the operands + * MOV direct, direct (opcode 85h) is peculiar, the operands * are inverted */ - if (OpCode == 0x85) { - cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, address + 1), - TextTmp); - len += sprintf(&buf[len], "%s,", TextTmp); - cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, address), - TextTmp); - len += sprintf(&buf[len], "%s", TextTmp); + if (opcode == 0x85) { + cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address + 1), + str); + len += sprintf(&buf[len], "%s,", str); + cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address), + str); + len += sprintf(&buf[len], "%s", str); address += 2; return; } @@ -535,7 +536,7 @@ cpu8051_disasm_args(unsigned int address, char *buf) switch (InstArgTbl[ArgTblOfs + i]) { case ADDR11: { len += sprintf(&buf[len], - "%.4XH", ((OpCode << 3) & 0xF00) + + "%.4XH", ((opcode << 3) & 0xF00) + (memory_read8(PGM_MEM_ID, address))); address++; break; @@ -549,17 +550,17 @@ cpu8051_disasm_args(unsigned int address, char *buf) break; } case DIRECT: { - cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, address), - TextTmp); - len += sprintf(&buf[len], "%s", TextTmp); + cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address), + str); + len += sprintf(&buf[len], "%s", str); address++; break; } case BITADDR: { - cpu8051_IntMemBitInfo( + cpu8051_int_mem_bit_info( (memory_read8(PGM_MEM_ID, address) & 0xF8), - TextTmp); - len += sprintf(&buf[len], "%s.%X" , TextTmp, + str); + len += sprintf(&buf[len], "%s.%X" , str, (memory_read8(PGM_MEM_ID, address) & 7)); address++; break; @@ -587,10 +588,10 @@ cpu8051_disasm_args(unsigned int address, char *buf) break; } case CBITADDR: { - cpu8051_IntMemBitInfo((memory_read8(PGM_MEM_ID, - address) & 0xF8), - TextTmp); - len += sprintf(&buf[len], "/%s.%X", TextTmp, + cpu8051_int_mem_bit_info((memory_read8(PGM_MEM_ID, + address) & 0xF8), + str); + len += sprintf(&buf[len], "/%s.%X", str, (memory_read8(PGM_MEM_ID, address) & 7)); address++; break; @@ -605,132 +606,132 @@ cpu8051_disasm_args(unsigned int address, char *buf) } } -/* Disasm one instruction at Address into a Text string */ +/* Disasm one instruction at address into a Text string */ int -cpu8051_Disasm(unsigned int Address, char *Text) +cpu8051_disasm(unsigned int address, char *text) { int len = 0; - char TextTmp[20]; - unsigned char OpCode; + char str[20]; + unsigned char opcode; int ArgTblOfs; - int InstSize; + int inst_size; int i; /* Display address. */ - len += sprintf(Text, " %.4X ", Address); + len += sprintf(text, " %.4X ", address); - OpCode = memory_read8(PGM_MEM_ID, Address); - InstSize = InstSizesTbl[OpCode]; + opcode = memory_read8(PGM_MEM_ID, address); + inst_size = InstSizesTbl[opcode]; /* Display hex bytes. */ - for (i = 0; i < InstSize; i++) - len += sprintf(&Text[len], " %.2X", - memory_read8(PGM_MEM_ID, Address + i)); + for (i = 0; i < inst_size; i++) + len += sprintf(&text[len], " %.2X", + memory_read8(PGM_MEM_ID, address + i)); - Address++; + address++; /* Padd remaining area with spaces. */ for (; len < 17;) - len += sprintf(&Text[len], " "); + len += sprintf(&text[len], " "); /* Display instruction mnemonic. */ - len += sprintf(&Text[len], "%s ", - InstTextTbl[InstTypesTbl[OpCode]]); - ArgTblOfs = OpCode << 2; + len += sprintf(&text[len], "%s ", + InstTextTbl[InstTypesTbl[opcode]]); + ArgTblOfs = opcode << 2; /* Padd remaining area with spaces. */ for (; len < 25;) - len += sprintf(&Text[len], " "); + len += sprintf(&text[len], " "); /* Display instruction arguments. */ /* - * MOV direct, direct (OpCode 85h) is peculiar, the operands + * MOV direct, direct (opcode 85h) is peculiar, the operands * are inverted */ - if (OpCode == 0x85) { - cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, Address + 1), - TextTmp); - len += sprintf(&Text[len], "%s,", TextTmp); - cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, Address), - TextTmp); - len += sprintf(&Text[len], "%s", TextTmp); - Address += 2; - return InstSize; + if (opcode == 0x85) { + cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address + 1), + str); + len += sprintf(&text[len], "%s,", str); + cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address), + str); + len += sprintf(&text[len], "%s", str); + address += 2; + return inst_size; } for (i = 1; i <= InstArgTbl[ArgTblOfs]; i++) { switch (InstArgTbl[ArgTblOfs + i]) { case ADDR11: { - len += sprintf(&Text[len], - "%.4XH", ((OpCode << 3) & 0xF00) + - (memory_read8(PGM_MEM_ID, Address))); - Address++; + len += sprintf(&text[len], + "%.4XH", ((opcode << 3) & 0xF00) + + (memory_read8(PGM_MEM_ID, address))); + address++; break; } case ADDR16: { len += sprintf( - &Text[len], "%.4XH", - ((memory_read8(PGM_MEM_ID, Address) << 8) + - memory_read8(PGM_MEM_ID, Address + 1))); - Address += 2; + &text[len], "%.4XH", + ((memory_read8(PGM_MEM_ID, address) << 8) + + memory_read8(PGM_MEM_ID, address + 1))); + address += 2; break; } case DIRECT: { - cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, Address), - TextTmp); - len += sprintf(&Text[len], "%s", TextTmp); - Address++; + cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address), + str); + len += sprintf(&text[len], "%s", str); + address++; break; } case BITADDR: { - cpu8051_IntMemBitInfo( - (memory_read8(PGM_MEM_ID, Address) & 0xF8), - TextTmp); - len += sprintf(&Text[len], "%s.%X" , TextTmp, - (memory_read8(PGM_MEM_ID, Address) & 7)); - Address++; + cpu8051_int_mem_bit_info( + (memory_read8(PGM_MEM_ID, address) & 0xF8), + str); + len += sprintf(&text[len], "%s.%X" , str, + (memory_read8(PGM_MEM_ID, address) & 7)); + address++; break; } case RELADDR: { - Address++; - len += sprintf(&Text[len], "%.4XH", (Address & 0xFF00) + - (((Address & 0xFF) + + address++; + len += sprintf(&text[len], "%.4XH", (address & 0xFF00) + + (((address & 0xFF) + memory_read8(PGM_MEM_ID, - Address - 1)) & 0xFF)); + address - 1)) & 0xFF)); break; } case DATAIMM: { - len += sprintf(&Text[len], "#%.2XH", - memory_read8(PGM_MEM_ID, Address)); - Address++; + len += sprintf(&text[len], "#%.2XH", + memory_read8(PGM_MEM_ID, address)); + address++; break; } case DATA16: { - len += sprintf(&Text[len], "#%.4XH", + len += sprintf(&text[len], "#%.4XH", ((memory_read8(PGM_MEM_ID, - Address) << 8) + - memory_read8(PGM_MEM_ID, Address+1))); - Address += 2; + address) << 8) + + memory_read8(PGM_MEM_ID, address+1))); + address += 2; break; } case CBITADDR: { - cpu8051_IntMemBitInfo((memory_read8(PGM_MEM_ID, - Address) & 0xF8), - TextTmp); - len += sprintf(&Text[len], "/%s.%X", TextTmp, - (memory_read8(PGM_MEM_ID, Address) & 7)); - Address++; + cpu8051_int_mem_bit_info((memory_read8(PGM_MEM_ID, + address) & 0xF8), + str); + len += sprintf(&text[len], "/%s.%X", str, + (memory_read8(PGM_MEM_ID, address) & 7)); + address++; break; } default: { - len += sprintf(&Text[len], "%s", + len += sprintf(&text[len], "%s", ArgsTextTbl[InstArgTbl[ArgTblOfs + i]]); } } if (i < InstArgTbl[ArgTblOfs]) - len += sprintf(&Text[len], ","); + len += sprintf(&text[len], ","); } - return InstSize; + return inst_size; } diff --git a/src/common/cpu8051.h b/src/common/cpu8051.h index 7d16803..f926f65 100644 --- a/src/common/cpu8051.h +++ b/src/common/cpu8051.h @@ -45,52 +45,49 @@ struct cpu8051_t { _SCOPE_ struct cpu8051_t cpu8051; int -IsBreakpoint(unsigned int Address); - -int -IsStoppoint(unsigned int address); +breakpoint_is_defined(unsigned int address); void -ShowBreakpoints(void); +breakpoints_show(void); void -SetBreakpoint(unsigned int Address); +breakpoint_set(unsigned int address); void -ClearBreakpoint(unsigned int Address); +breakpoint_clr(unsigned int address); void -ClearAllBreakpoints(void); +breakpoints_clr_all(void); void -ToggleBreakpoint(unsigned int Address); +breakpoint_toggle(unsigned int address); void cpu8051_init(void); int -cpu8051_Exec(void); +cpu8051_exec(void); int cpu8051_run(int instr_count, int (*interface_stop)(void)); void -cpu8051_Reset(void); +cpu8051_reset(void); void -cpu8051_WriteD(unsigned int Address, unsigned char Value); +cpu8051_WriteD(unsigned int address, unsigned char value); void -cpu8051_WriteI(unsigned int Address, unsigned char Value); +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); +cpu8051_ReadD(unsigned int address); unsigned char -cpu8051_ReadI(unsigned int Address); +cpu8051_ReadI(unsigned int address); unsigned char cpu8051_ReadB(uint8_t bit_address); @@ -99,12 +96,12 @@ int cpu8051_get_instruction_size(unsigned char opcode); void -cpu8051_disasm_mnemonic(unsigned char OpCode, char *buf); +cpu8051_disasm_mnemonic(unsigned char opcode, char *buf); void cpu8051_disasm_args(unsigned int address, char *buf); int -cpu8051_Disasm(unsigned int Address, char *Text); +cpu8051_disasm(unsigned int address, char *text); #endif /* CPU8051_H */ diff --git a/src/common/hexfile.c b/src/common/hexfile.c index 19ba44f..8967cf8 100644 --- a/src/common/hexfile.c +++ b/src/common/hexfile.c @@ -28,6 +28,8 @@ /* Maximum of 75 digits with 32-bytes data records. */ #define HEXFILE_LINE_BUFFER_LEN 128 +static int asciihex2int_error; + /* Convert integer to ASCII hex string. */ void int2asciihex(int val, char *str, int width) @@ -47,15 +49,21 @@ int asciihex2int(char *str) { int val; + int rc; + + rc = sscanf(str, "%X", &val); - sscanf(str, "%X", &val); + if (rc == 0) { + log_err("ASCII to hex conversion failure"); + asciihex2int_error = true; + } return val; } /* Convert an ascii string to an hexadecimal number. */ -unsigned int -Ascii2Hex(char *istring, int length) +static unsigned int +asciihex2int_len(char *istring, int length) { unsigned int result = 0; int i, ascii_code; @@ -69,7 +77,7 @@ Ascii2Hex(char *istring, int length) ascii_code &= 0xDF; if ((ascii_code >= 0x30 && ascii_code <= 0x39) || - (ascii_code >= 0x41 && ascii_code <= 0x46)) { + (ascii_code >= 0x41 && ascii_code <= 0x46)) { ascii_code -= 0x30; if (ascii_code > 9) ascii_code -= 7; @@ -77,8 +85,8 @@ Ascii2Hex(char *istring, int length) result <<= 4; result += ascii_code; } else { - log_fail("Error converting ASCII string <%s> to hex" - " (len=%d)", istring, length); + log_err("ASCII to hex conversion failure"); + asciihex2int_error = true; } } return result; @@ -90,13 +98,14 @@ Ascii2Hex(char *istring, int length) * false: failure */ int -LoadHexFile(const char *filename) +hexfile_load(const char *filename) { - int i, j, RecLength, LoadOffset, RecType, Data, Checksum; + int i, j, rec_len, load_offset, rec_type, data, checksum; FILE *fp; int status; char line[HEXFILE_LINE_BUFFER_LEN]; int valid = false; + int line_num = 1; log_debug("LoadHexFile"); @@ -117,56 +126,60 @@ LoadHexFile(const char *filename) */ while (fgets(line, HEXFILE_LINE_BUFFER_LEN, fp) != NULL) { i = 0; - Checksum = 0; + checksum = 0; if (line[i++] != ':') { log_err("hexfile line not beginning with \":\""); goto close_file; } - RecLength = Ascii2Hex(&line[i], 2); + rec_len = asciihex2int_len(&line[i], 2); i += 2; - Checksum += RecLength; + checksum += rec_len; - LoadOffset = Ascii2Hex(&line[i], 4); - Checksum += LoadOffset / 256; - Checksum += LoadOffset % 256; + load_offset = asciihex2int_len(&line[i], 4); + checksum += load_offset / 256; + checksum += load_offset % 256; i += 4; - RecType = Ascii2Hex(&line[i], 2); + rec_type = asciihex2int_len(&line[i], 2); i += 2; - Checksum += RecType; + checksum += rec_type; - if (RecType == 0) { - for (j = 0; j < RecLength; j++) { - Data = Ascii2Hex(&line[i], 2); + if (rec_type == 0) { + for (j = 0; j < rec_len; j++) { + data = asciihex2int_len(&line[i], 2); memory_write8(PGM_MEM_ID, - (unsigned int)(LoadOffset + j), - (unsigned char)Data); + (unsigned int) (load_offset + j), + (unsigned char) data); i += 2; - Checksum += Data; + checksum += data; } } /* Read and add checksum value */ - Checksum += Ascii2Hex(&line[i], 2); - Checksum &= 0x000000FF; + checksum += asciihex2int_len(&line[i], 2); + checksum &= 0x000000FF; - /* Make sure line checksum is valid */ - if (Checksum) { + if (asciihex2int_error) { + log_err("hexfile parse error at line %d", line_num); + goto close_file; + } else if (checksum) { log_err("hexfile checksum mismatch"); goto close_file; } - if (RecType == 0) { + if (rec_type == 0) { log_debug("hex record: data"); - } else if (RecType == 1) { + } else if (rec_type == 1) { log_debug("hex record: End Of File"); valid = true; goto close_file; } else { - log_warn("hex record: Unsupported ($%02X)", RecType); + log_warn("hex record: Unsupported ($%02X)", rec_type); } + + line_num++; } close_file: @@ -174,9 +187,8 @@ close_file: if (status != EXIT_SUCCESS) log_fail("Error closing hex file"); - if (valid == false) { + if (!valid) log_err("Error parsing hex file"); - } return valid; } diff --git a/src/common/hexfile.h b/src/common/hexfile.h index 329573e..f9a258b 100644 --- a/src/common/hexfile.h +++ b/src/common/hexfile.h @@ -16,10 +16,7 @@ int2asciihex(int val, char *str, int width); int asciihex2int(char *str); -unsigned int -Ascii2Hex(char *istring, int length); - int -LoadHexFile(const char *filename); +hexfile_load(const char *filename); #endif /* HEXFILE_H */ diff --git a/src/common/memory.c b/src/common/memory.c index f231705..4b600b4 100644 --- a/src/common/memory.c +++ b/src/common/memory.c @@ -73,9 +73,9 @@ memory_check_address(enum mem_id_t id, unsigned long address, int display_error) log_err("Address out of range ($%X >= $%X", address, mem_infos[id].max_size - 1); return false; - } - else + } else { return true; + } } u_int8_t * @@ -98,8 +98,9 @@ memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value) " Address (%lu) greater than maximum memory size", id, address); return; - } else + } else { mem_infos[id].buf[address] = value; + } } void @@ -124,8 +125,9 @@ memory_read8(enum mem_id_t id, unsigned long address) " Address (%lu) greater than maximum memory size", id, address); return 0; - } else + } else { return mem_infos[id].buf[address]; + } } u_int8_t @@ -211,7 +213,7 @@ void memory_dump(unsigned int address, int size, int memory_id) { int rc; - int Offset, Column; + int offset, col; if (size == 0) { log_err("invalid size: 0"); @@ -220,35 +222,35 @@ memory_dump(unsigned int address, int size, int memory_id) /* Validate start address. */ rc = memory_check_address(memory_id, address, DISPLAY_ERROR_YES); - if (rc != false) { + if (!rc) { /* Validate end address. */ rc = memory_check_address(memory_id, address + (size - 1), DISPLAY_ERROR_NO); - if (rc == false) + if (!rc) log_err("Trying to read beyond memory limit"); } - if (rc == false) + if (!rc) return; - for (Offset = 0; Offset < size; Offset += 16) { + for (offset = 0; offset < size; offset += 16) { unsigned char data[16]; - printf("%.4X ", address + Offset); + printf("%.4X ", address + offset); - for (Column = 0; Column < 16; Column++) { - data[Column] = memory_read8(memory_id, address + - Offset + Column); - printf(" %.2X", (int) data[Column]); + for (col = 0; col < 16; col++) { + data[col] = memory_read8(memory_id, address + + offset + col); + printf(" %.2X", (int) data[col]); } printf(" "); /* Display any ASCII characters */ - for (Column = 0; Column < 16; Column++) { - if ((int) data[Column] >= 32 && - (int) data[Column] <= 126) { - printf("%c", data[Column]); - } else + for (col = 0; col < 16; col++) { + if ((int) data[col] >= 32 && + (int) data[col] <= 126) + printf("%c", data[col]); + else printf("."); } printf("\n"); diff --git a/src/common/memory.h b/src/common/memory.h index dbfd043..5ba5204 100644 --- a/src/common/memory.h +++ b/src/common/memory.h @@ -38,7 +38,8 @@ void memory_init(void); int -memory_check_address(enum mem_id_t id, unsigned long address, int display_error); +memory_check_address(enum mem_id_t id, unsigned long address, + int display_error); u_int8_t * memory_getbuf(enum mem_id_t id, unsigned long address); diff --git a/src/common/opcode2c.pl b/src/common/opcode2c.pl index 6d41948..d79dc6d 100755 --- a/src/common/opcode2c.pl +++ b/src/common/opcode2c.pl @@ -23,15 +23,7 @@ sub write_header print $fd " * Copyright (C) 1999 Jonathan St-André\n"; print $fd " * Copyright (C) 1999 Hugo Villeneuve \n"; print $fd " *\n"; - print $fd " * This program is free software; you can redistribute it and/or modify\n"; - print $fd " * it under the terms of the GNU General Public License as published by\n"; - print $fd " * the Free Software Foundation; either version 2 of the License, or\n"; - print $fd " * (at your option) any later version.\n"; - print $fd " *\n"; - print $fd " * This program is distributed in the hope that it will be useful,\n"; - print $fd " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"; - print $fd " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"; - print $fd " * GNU General Public License for more details.\n"; + print $fd " * This file is released under the GPLv2\n"; print $fd " */\n\n"; } diff --git a/src/common/sfr.c b/src/common/sfr.c index 2e81e99..0e609f9 100644 --- a/src/common/sfr.c +++ b/src/common/sfr.c @@ -50,7 +50,8 @@ regwin_read_timer(int timer_low_addr) static void regwin_write_timer(int timer_low_addr, int val) { - memory_sfr_write8(timer_low_addr + 2, (u_int8_t) ((val & 0x0000FFFF) >> 8)); + memory_sfr_write8(timer_low_addr + 2, + (u_int8_t) ((val & 0x0000FFFF) >> 8)); memory_sfr_write8(timer_low_addr, (u_int8_t) val); } @@ -94,7 +95,8 @@ regwin_read_rx(int offset) static void regwin_write_rx(int offset, int val) { - memory_write8(INT_MEM_ID, regwin_read_bank_offset() + offset, (u_int8_t) val); + memory_write8(INT_MEM_ID, regwin_read_bank_offset() + offset, + (u_int8_t) val); } /* This array defines how to read value for each register. */ @@ -262,27 +264,29 @@ static struct regwin_infos_t regwin_infos[SFR_REGS] = { static unsigned int regwin_read_generic(int addr, int width) { - if (width == 2) + if (width == 2) { return memory_sfr_read8(addr); - else if (width == 4) { + } else if (width == 4) { /* Address is low address. */ return (memory_sfr_read8(addr + 1) << 8) | memory_sfr_read8(addr); - } else + } else { return 0xFFFFFFFF; + } } static void regwin_write_generic(int addr, int val, int width) { - if (width == 2) + if (width == 2) { memory_sfr_write8(addr, (u_int8_t) val); - else if (width == 4) { + } else if (width == 4) { /* Address is low address. */ - memory_sfr_write8(addr + 1, (u_int8_t) ((val & 0x0000FFFF) >> 8)); + memory_sfr_write8(addr + 1, + (u_int8_t) ((val & 0x0000FFFF) >> 8)); memory_sfr_write8(addr, (u_int8_t) val); } -}; +} int regwin_read(int row) diff --git a/src/common/timers.c b/src/common/timers.c index c5776a1..b8afdfa 100644 --- a/src/common/timers.c +++ b/src/common/timers.c @@ -66,7 +66,8 @@ timer_increment_check_overflow(uint8_t counter_address, uint8_t tf_mask) } static void -timer_with_prescaler(uint8_t tl, uint8_t th, uint8_t tf_mask, int prescaler_width) +timer_with_prescaler(uint8_t tl, uint8_t th, uint8_t tf_mask, + int prescaler_width) { unsigned int prescaler; @@ -82,7 +83,7 @@ timer_with_prescaler(uint8_t tl, uint8_t th, uint8_t tf_mask, int prescaler_widt static void process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, - uint8_t GATE, uint32_t TimerCounter) + uint8_t gate, uint32_t timer_counter) { unsigned int tmp; @@ -104,8 +105,9 @@ process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, /* If overflow -> reload and set TF0 */ cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) | tf_mask); cpu8051_WriteD(tl, cpu8051_ReadD(th)); - } else + } else { cpu8051_WriteD(tl, tmp); + } break; case 3: /* @@ -117,7 +119,7 @@ process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, if (tl == _TL1_) break; - if (TR && !GATE && !TimerCounter) + if (TR && !gate && !timer_counter) timer_increment_check_overflow(tl, tf_mask); /* TH0 uses TR1 et TF1. */ @@ -134,26 +136,28 @@ process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, void timers_check(void) { - unsigned int TR; - unsigned int MODE; - unsigned int GATE; - unsigned int TimerCounter; + unsigned int tr; + unsigned int mode; + unsigned int gate; + unsigned int timer_counter; /* Timer 0 */ - TR = cpu8051_ReadD(_TCON_) & 0x10; - MODE = cpu8051_ReadD(_TMOD_) & 0x03; - GATE = cpu8051_ReadD(_TMOD_) & 0x08; - TimerCounter = cpu8051_ReadD(_TMOD_) & 0x04; + tr = cpu8051_ReadD(_TCON_) & 0x10; + mode = cpu8051_ReadD(_TMOD_) & 0x03; + gate = cpu8051_ReadD(_TMOD_) & 0x08; + timer_counter = cpu8051_ReadD(_TMOD_) & 0x04; - if ((TR && !GATE && !TimerCounter) || (MODE == 3)) - process_timer(_TL0_, _TH0_, 0x20, TR, MODE, GATE, TimerCounter); + 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; - TimerCounter = cpu8051_ReadD(_TMOD_) & 0x40; - - if (TR && !GATE && !TimerCounter) - process_timer(_TL1_, _TH1_, 0x80, TR, MODE, GATE, TimerCounter); + tr = cpu8051_ReadD(_TCON_) & 0x40; + mode = (cpu8051_ReadD(_TMOD_) & 0x30) >> 4 ; + gate = cpu8051_ReadD(_TMOD_) & 0x80; + timer_counter = cpu8051_ReadD(_TMOD_) & 0x40; + + if (tr && !gate && !timer_counter) + process_timer(_TL1_, _TH1_, 0x80, tr, mode, gate, + timer_counter); } diff --git a/src/gtk/app-config.c b/src/gtk/app-config.c index 209d75c..eccfc4d 100644 --- a/src/gtk/app-config.c +++ b/src/gtk/app-config.c @@ -53,19 +53,20 @@ app_config_init(void) } static int -app_config_key_file_get_int(GKeyFile *kf, const char *grp, const char *key, int *value) +app_config_key_file_get_int(GKeyFile *kf, const char *grp, const char *key, + int *value) { - char *str = g_key_file_get_value(kf, grp, key, NULL); + char *str = g_key_file_get_value(kf, grp, key, NULL); - log_debug("key: %s", key); + log_debug("key: %s", key); - if (G_LIKELY(str)) { - *value = atoi(str); - log_debug(" value = %d", *value); - g_free(str); - } + if (G_LIKELY(str)) { + *value = atoi(str); + log_debug(" value = %d", *value); + g_free(str); + } - return str != NULL; + return str != NULL; } static void @@ -159,10 +160,9 @@ app_config_save(void) dir_path = app_config_get_dir_path(); - if (g_mkdir_with_parents(dir_path, 0700) != -1) - { + if (g_mkdir_with_parents(dir_path, 0700) != -1) { char *file_path; - GString* buf = g_string_sized_new(1024); + GString *buf = g_string_sized_new(1024); g_string_append(buf, "\n[emulation]\n"); diff --git a/src/gtk/app-config.h b/src/gtk/app-config.h index b05d872..6002437 100644 --- a/src/gtk/app-config.h +++ b/src/gtk/app-config.h @@ -23,8 +23,7 @@ enum layout_t { UI_LAYOUT2, }; -struct app_config_t -{ +struct app_config_t { /* Emulation options */ int clear_ram_on_file_load; diff --git a/src/gtk/filemenu.c b/src/gtk/filemenu.c index 11cf87c..3c36fec 100644 --- a/src/gtk/filemenu.c +++ b/src/gtk/filemenu.c @@ -44,8 +44,8 @@ remember_current_folder(GtkFileChooser *chooser) } } -void -FileOpenEvent(GtkObject *object, gpointer data) +static void +file_open_event(GtkObject *object, gpointer data) { GtkWidget *file_dialog; char *dir; @@ -55,7 +55,7 @@ FileOpenEvent(GtkObject *object, gpointer data) (void) object; (void) data; - log_info("FileOpenEvent()"); + log_info("file_open_event()"); /* Create a new file selection widget. */ file_dialog = gtk_file_chooser_dialog_new( @@ -97,7 +97,7 @@ FileOpenEvent(GtkObject *object, gpointer data) } static void -FileQuitEvent(gchar *string) +file_quit_event(gchar *string) { /* Remove compiler warning about unused variables. */ (void) string; @@ -106,7 +106,7 @@ FileQuitEvent(gchar *string) } void -FileAddMenu(GtkWidget *menu_bar) +file_add_menu(GtkWidget *menu_bar) { GtkWidget *item; GtkWidget *menu; @@ -117,14 +117,14 @@ FileAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label(FILENAME_DESCRIPTION); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - g_signal_connect(item, "activate", G_CALLBACK(FileOpenEvent), NULL); + g_signal_connect(item, "activate", G_CALLBACK(file_open_event), NULL); - AddMenuSeparator(menu); + add_menu_separator(menu); item = gtk_menu_item_new_with_label("Exit"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* We can attach the Quit menu item to our exit function */ - g_signal_connect(item, "activate", G_CALLBACK(FileQuitEvent), + g_signal_connect(item, "activate", G_CALLBACK(file_quit_event), (gpointer) "file.quit"); /* Adding submenu title. */ diff --git a/src/gtk/filemenu.h b/src/gtk/filemenu.h index 26d819e..d24875f 100644 --- a/src/gtk/filemenu.h +++ b/src/gtk/filemenu.h @@ -13,12 +13,6 @@ #include void -FileOpenEvent(GtkObject *object, gpointer data); - -void -FileResetEvent(GtkObject *object, gpointer data); - -void -FileAddMenu(GtkWidget *menu_bar); +file_add_menu(GtkWidget *menu_bar); #endif /* FILEMENU_H */ diff --git a/src/gtk/helpmenu.c b/src/gtk/helpmenu.c index 0bc3c4d..9b9ac2e 100644 --- a/src/gtk/helpmenu.c +++ b/src/gtk/helpmenu.c @@ -28,7 +28,7 @@ #include "helpmenu.h" static void -HelpAboutEvent(GtkWidget *widget, gpointer data) +help_about_event(GtkWidget *widget, gpointer data) { /* Remove compiler warning about unused variables. */ (void) widget; @@ -74,7 +74,7 @@ HelpAboutEvent(GtkWidget *widget, gpointer data) } void -HelpAddMenu(GtkWidget *menu_bar) +help_add_menu(GtkWidget *menu_bar) { GtkWidget *item; GtkWidget *menu; @@ -85,7 +85,7 @@ HelpAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label("About " PACKAGE); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - g_signal_connect(item, "activate", G_CALLBACK(HelpAboutEvent), NULL); + g_signal_connect(item, "activate", G_CALLBACK(help_about_event), NULL); /* Adding submenu title. */ item = gtk_menu_item_new_with_label("Help"); diff --git a/src/gtk/helpmenu.h b/src/gtk/helpmenu.h index 0175e3e..2205c6a 100644 --- a/src/gtk/helpmenu.h +++ b/src/gtk/helpmenu.h @@ -13,6 +13,6 @@ #include void -HelpAddMenu(GtkWidget *menu_bar); +help_add_menu(GtkWidget *menu_bar); #endif /* HELPMENU_H */ diff --git a/src/gtk/main.c b/src/gtk/main.c index 67fbee7..94b7ebe 100644 --- a/src/gtk/main.c +++ b/src/gtk/main.c @@ -53,9 +53,9 @@ extern struct app_config_t *cfg; extern struct options_t options; void -emugtk_UpdateDisplay(void) +emugtk_update_display(void) { - log_debug("UpdateDisplay()"); + log_debug("update display"); regwin_refresh(); pgmwin_refresh(); pswwin_refresh(); @@ -73,10 +73,10 @@ static void emugtk_stop_running() { if (running) { - log_info("StopRunning()"); + log_info("stop running"); g_source_remove(running_function_tag); running = 0; - emugtk_UpdateDisplay(); + emugtk_update_display(); } } @@ -101,7 +101,7 @@ static void emugtk_start_running(void) { if (!running) { - log_info("StartRunning()"); + log_info("start running"); running_function_tag = g_idle_add(emugtk_running, 0); running = 1; } @@ -127,15 +127,15 @@ button_add_pix(GtkWidget *box, char **xpm) /* CPU reset and Gtk UI update */ static void -emugtk_Reset(void) +emugtk_reset(void) { - cpu8051_Reset(); - emugtk_UpdateDisplay(); + cpu8051_reset(); + emugtk_update_display(); } /* Signal ResetEvent (ResetButton) */ static void -emugtk_ResetEvent(GtkWidget *widget, GdkEvent *event, gpointer data) +emugtk_reset_event(GtkWidget *widget, GdkEvent *event, gpointer data) { /* Remove compiler warning about unused variables. */ (void) widget; @@ -144,20 +144,20 @@ emugtk_ResetEvent(GtkWidget *widget, GdkEvent *event, gpointer data) log_info("ResetEvent()"); emugtk_stop_running(); - emugtk_Reset(); + emugtk_reset(); } /* CPU Step and Gtk UI update */ static void -emugtk_Step(void) +emugtk_step(void) { - cpu8051_Exec(); - emugtk_UpdateDisplay(); + cpu8051_exec(); + emugtk_update_display(); } /* Signal RunEvent (RunButton) */ static void -emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data) +emugtk_run_event(GtkWidget *widget, GdkEvent *event, gpointer data) { /* Remove compiler warning about unused variables. */ (void) widget; @@ -174,7 +174,7 @@ emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data) /* Signal StopEvent (StopButton) */ static void -emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data) +emugtk_stop_event(GtkWidget *widget, GdkEvent *event, gpointer data) { /* Remove compiler warning about unused variables. */ (void) widget; @@ -187,7 +187,7 @@ emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data) /* Signal StepEvent (StepButton) */ static void -emugtk_StepEvent(GtkWidget *widget, GdkEvent *event, gpointer data) +emugtk_step_event(GtkWidget *widget, GdkEvent *event, gpointer data) { /* Remove compiler warning about unused variables. */ (void) widget; @@ -196,12 +196,12 @@ emugtk_StepEvent(GtkWidget *widget, GdkEvent *event, gpointer data) log_info("StepEvent()"); emugtk_stop_running(); - emugtk_Step(); + emugtk_step(); } /* Creates the Reset, Run, Stop and Step buttons. */ static GtkWidget * -AddButtons(void) +add_buttons(void) { GtkWidget *button_hbox; GtkWidget *button; @@ -212,32 +212,32 @@ AddButtons(void) /* Creating the RESET button. */ button = button_add_pix(button_hbox, reset_xpm); g_signal_connect(button, "clicked", - G_CALLBACK(emugtk_ResetEvent), + G_CALLBACK(emugtk_reset_event), NULL); /* Creating the RUN button. */ button = button_add_pix(button_hbox, run_xpm); g_signal_connect(button, "clicked", - G_CALLBACK(emugtk_RunEvent), + G_CALLBACK(emugtk_run_event), NULL); /* Creating STOP button. */ button = button_add_pix(button_hbox, stop_xpm); g_signal_connect(GTK_OBJECT(button), "clicked", - G_CALLBACK(emugtk_StopEvent), + G_CALLBACK(emugtk_stop_event), NULL); /* Creating STEP button. */ button = button_add_pix(button_hbox, step_xpm); g_signal_connect(GTK_OBJECT(button), "clicked", - G_CALLBACK(emugtk_StepEvent), + G_CALLBACK(emugtk_step_event), NULL); return button_hbox; } static GtkWidget * -AddMenu(void) +add_menu(void) { GtkWidget *menu_bar; @@ -245,13 +245,13 @@ AddMenu(void) menu_bar = gtk_menu_bar_new(); /* Adding the 'File' submenu */ - FileAddMenu(menu_bar); + file_add_menu(menu_bar); /* Adding the 'View' submenu */ - ViewAddMenu(menu_bar); + view_add_menu(menu_bar); /* Adding the 'Help' submenu */ - HelpAddMenu(menu_bar); + help_add_menu(menu_bar); return menu_bar; } @@ -320,7 +320,7 @@ static void emugtk_show_memory_paned(void) { gtk_widget_show_all(mainwin); - emugtk_UpdateDisplay(); + emugtk_update_display(); } void @@ -330,7 +330,7 @@ emugtk_create_int_memory_paned(void) INT_MEM_ID); gtk_paned_pack1(GTK_PANED(vpaned1), scrollwin_int, FALSE, FALSE); - if (emugtk_window_init_complete == true) + if (emugtk_window_init_complete) emugtk_show_memory_paned(); } @@ -353,7 +353,7 @@ emugtk_create_ext_memory_paned(void) gtk_paned_pack2(GTK_PANED(vpaned1), scrollwin_ext, TRUE, FALSE); - if (emugtk_window_init_complete == true) + if (emugtk_window_init_complete) emugtk_show_memory_paned(); } @@ -380,7 +380,7 @@ emugtk_recreate_memory_paned(void) emugtk_create_ext_memory_paned(); } - if (emugtk_window_init_complete == true) + if (emugtk_window_init_complete) emugtk_show_memory_paned(); } @@ -398,8 +398,9 @@ emugtk_create_memory_paned(void) emugtk_recreate_memory_paned(); return vpaned1; - } else + } else { return NULL; + } } /* @@ -491,17 +492,18 @@ emugtk_window_init(void) G_CALLBACK(mainwin_configure_event), NULL); /* Creating the menu bar. */ - menu_bar = AddMenu(); + menu_bar = add_menu(); /* Creating the buttons bar. */ - buttons_bar = AddButtons(); + buttons_bar = add_buttons(); scrollwin = pswwin_init(); gtk_box_pack_start(GTK_BOX(buttons_bar), scrollwin, FALSE, FALSE, 50); for (id = 0; id < GP_TIMERS_COUNT; id++) { scrollwin = timerwin_init(id); - gtk_box_pack_start(GTK_BOX(buttons_bar), scrollwin, FALSE, FALSE, 15); + gtk_box_pack_start(GTK_BOX(buttons_bar), scrollwin, + FALSE, FALSE, 15); } /* hpaned will contain registers and disassembly windows. */ @@ -558,7 +560,7 @@ emugtk_window_init(void) } void -AddMenuSeparator(GtkWidget *menu) +add_menu_separator(GtkWidget *menu) { GtkWidget *item; @@ -573,14 +575,14 @@ emugtk_new_file(char *file) emugtk_stop_running(); - rc = LoadHexFile(file); - if (rc == false) { + rc = hexfile_load(file); + if (!rc) { message_show_error("Error parsing hex file"); } else { if (cfg->clear_ram_on_file_load) - emugtk_Reset(); + emugtk_reset(); - emugtk_UpdateDisplay(); + emugtk_update_display(); } } @@ -599,15 +601,15 @@ main(int argc, char **argv) gtk_init(&argc, &argv); if (options.filename != NULL) - rc_load_hexfile = LoadHexFile(options.filename); + rc_load_hexfile = hexfile_load(options.filename); - cpu8051_Reset(); + cpu8051_reset(); log_info("Init GUI"); emugtk_window_init(); - emugtk_UpdateDisplay(); + emugtk_update_display(); - if (rc_load_hexfile == false) + if (!rc_load_hexfile) message_show_error("Error parsing hex file"); gtk_main(); diff --git a/src/gtk/main.h b/src/gtk/main.h index 607f5e5..7751a3b 100644 --- a/src/gtk/main.h +++ b/src/gtk/main.h @@ -13,13 +13,13 @@ #include void -AddMenuSeparator(GtkWidget *menu); +add_menu_separator(GtkWidget *menu); void emugtk_new_file(char *file); void -emugtk_UpdateDisplay(void); +emugtk_update_display(void); void emugtk_quit_gui(void); diff --git a/src/gtk/memwin.c b/src/gtk/memwin.c index 3a3780d..9f8abd2 100644 --- a/src/gtk/memwin.c +++ b/src/gtk/memwin.c @@ -24,6 +24,7 @@ #include "memwin.h" #include "main.h" #include "options.h" +#include "log.h" #include "app-config.h" extern struct app_config_t *cfg; @@ -32,8 +33,7 @@ extern struct options_t options; static int COL_ASCII; static int N_COLUMNS; -enum -{ +enum { COL_ADDRESS = 0, COL_DATA0, }; @@ -87,20 +87,19 @@ memwin_cell_edited(GtkCellRendererText *cell, gchar *path_string, int new; char *str; - if (!model) { - g_error("Unable to get model from cell renderer"); - } + if (!model) + log_err("Unable to get model from cell renderer"); /* Column number is passed as renderer object data */ - columnptr = g_object_get_data(G_OBJECT(cell), "column"); - column = GPOINTER_TO_UINT(columnptr); + columnptr = g_object_get_data(G_OBJECT(cell), "column"); + column = GPOINTER_TO_UINT(columnptr); /* Memory ID is passed as renderer object data */ memory_id_ptr = g_object_get_data(G_OBJECT(cell), "memory_id"); memory_id = GPOINTER_TO_UINT(memory_id_ptr); /* Get the iterator */ - gtk_tree_model_get_iter_from_string(model, &iter, path_string); + gtk_tree_model_get_iter_from_string(model, &iter, path_string); /* Get base address. */ gtk_tree_model_get(model, &iter, COL_ADDRESS, &str, -1); @@ -129,13 +128,13 @@ memwin_cell_edited(GtkCellRendererText *cell, gchar *path_string, int2asciihex(new, str, 2); /* Store new value in gtk model. */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1); /* * Make sure to update all registers and memory. * For example, BANKed registers depends on internal memory. */ - emugtk_UpdateDisplay(); + emugtk_update_display(); }; static void @@ -168,7 +167,7 @@ memwin_init_columns(GtkWidget *listview, int memory_id) gtk_tree_view_get_model( GTK_TREE_VIEW(listview))); - /* Add column index and memory_id, used when editing the cell. */ + /* Add column index and memory_id, used when editing the cell */ g_object_set_data(G_OBJECT(renderer), "column", GUINT_TO_POINTER(i)); g_object_set_data(G_OBJECT(renderer), "memory_id", @@ -214,11 +213,12 @@ memwin_infos_select(int memory_id) static void compute_data_rows(int memory_id) { - if (memory_id == INT_MEM_ID) { - memwin_infos->data_rows = options.iram_size / cfg->bytes_per_row; - } else if (memory_id == EXT_MEM_ID) { - memwin_infos->data_rows = options.xram_size / cfg->bytes_per_row; - } + if (memory_id == INT_MEM_ID) + memwin_infos->data_rows = options.iram_size / + cfg->bytes_per_row; + else if (memory_id == EXT_MEM_ID) + memwin_infos->data_rows = options.xram_size / + cfg->bytes_per_row; if (memwin_infos->crc) free(memwin_infos->crc); @@ -259,8 +259,10 @@ memwin_init(char *title, int memory_id) store = memwin_init_store(memwin_infos->data_rows); /* Creating the view component */ - memwin_infos->memlist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(memwin_infos->memlist), TRUE); + memwin_infos->memlist = gtk_tree_view_new_with_model( + GTK_TREE_MODEL(store)); + gtk_tree_view_set_headers_visible( + GTK_TREE_VIEW(memwin_infos->memlist), TRUE); gtk_container_add(GTK_CONTAINER(scrollwin), memwin_infos->memlist); memwin_init_columns(memwin_infos->memlist, memory_id); @@ -291,7 +293,7 @@ memwin_row_changed(int memory_id, int row, unsigned int address) crc_new = crc32(0L, Z_NULL, 0); crc_new = crc32(crc_new, buf8, cfg->bytes_per_row); - if ((memwin_infos->crc_init != false) && + if ((memwin_infos->crc_init) && (crc_new == memwin_infos->crc[row])) { row_changed = false; } else { @@ -308,7 +310,7 @@ void memwin_refresh(int memory_id) { int row; - unsigned int Address = 0; + unsigned int address = 0; GtkListStore *store; log_debug("memwin_refresh"); @@ -319,10 +321,10 @@ memwin_refresh(int memory_id) GTK_TREE_VIEW(memwin_infos->memlist))); for (row = 0; row < memwin_infos->data_rows; - row++, Address += cfg->bytes_per_row) { + row++, address += cfg->bytes_per_row) { int valid; GtkTreeIter iter; - char str[4+1]; /* Maximum str len is for address column (4 digits) */ + char str[4+1]; /* Max. str len for address column (4 digits) */ char ascii_str[16+1]; /* Maximum 16 data columns. */ int col; @@ -342,21 +344,22 @@ memwin_refresh(int memory_id) } /* Only update row if it has been modified. */ - if (memwin_row_changed(memory_id, row, Address)) { + if (memwin_row_changed(memory_id, row, address)) { /* Display base address. */ - int2asciihex(Address, str, 4); + int2asciihex(address, str, 4); gtk_list_store_set(store, &iter, COL_ADDRESS, str, -1); for (col = 0; col < cfg->bytes_per_row; col++) { u_int8_t data; - data = memory_read8(memory_id, Address + col); + data = memory_read8(memory_id, address + col); /* Display hex data */ int2asciihex(data, str, 2); - gtk_list_store_set(store, &iter, col + 1, str, -1); + gtk_list_store_set(store, &iter, col + 1, str, + -1); /* Append to ASCII string (if applicable). */ if (!isprint(data)) @@ -365,7 +368,8 @@ memwin_refresh(int memory_id) } /* Display ASCII characters. */ - gtk_list_store_set(store, &iter, COL_ASCII, ascii_str, -1); + gtk_list_store_set(store, &iter, COL_ASCII, ascii_str, + -1); } } diff --git a/src/gtk/messagebox.c b/src/gtk/messagebox.c index 6e047c4..2ba3a50 100644 --- a/src/gtk/messagebox.c +++ b/src/gtk/messagebox.c @@ -28,8 +28,8 @@ message_show_error(char *message) GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, message, NULL); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } void @@ -42,6 +42,6 @@ message_show_information(char *message) GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message, NULL); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } diff --git a/src/gtk/pgmwin.c b/src/gtk/pgmwin.c index f2c6a8c..5439936 100644 --- a/src/gtk/pgmwin.c +++ b/src/gtk/pgmwin.c @@ -24,8 +24,7 @@ static GtkWidget *pgmlist; #define LIST_VIEW_NAME "Program" #define DATA_ROWS 100 -enum -{ +enum { COL_BREAKPT = 0, COL_ADDR, COL_B0, @@ -72,7 +71,8 @@ pgmwin_init_store(void) if (row == 0) gtk_list_store_set(store, &iter, COL_COLOR, "red", -1); else - gtk_list_store_set(store, &iter, COL_COLOR, "black", -1); + gtk_list_store_set(store, &iter, COL_COLOR, "black", + -1); } return store; @@ -137,7 +137,7 @@ pgmwin_sel_changed_event(GtkWidget *widget, GdkEvent *event, gpointer data) log_debug(" row address is: $%04X", val); - ToggleBreakpoint(val); + breakpoint_toggle(val); pgmwin_refresh(); g_free(str_addr); @@ -183,7 +183,7 @@ pgmwin_init(void) gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect(selection, "changed", - G_CALLBACK(pgmwin_sel_changed_event), NULL); + G_CALLBACK(pgmwin_sel_changed_event), NULL); pgmwin_init_columns(); @@ -203,9 +203,9 @@ pgmwin_refresh(void) { int row; GtkListStore *store; - unsigned int Address; + unsigned int address; - Address = cpu8051.pc; + address = cpu8051.pc; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pgmlist))); @@ -215,8 +215,8 @@ pgmwin_refresh(void) char str[128]; int k; int col_id; - int InstSize; - unsigned char OpCode; + int inst_size; + unsigned char opcode; if (row == 0) { /* Get first row in list store */ @@ -233,7 +233,7 @@ pgmwin_refresh(void) return; } - if (Address > 0xFFFF) { + if (address > 0xFFFF) { /* * Not the most elegant solution, but it works to not * display instructions past last address, 0xFFFF. @@ -250,7 +250,7 @@ pgmwin_refresh(void) -1); } else { /* Display breakpoints. */ - if (IsBreakpoint(Address)) + if (breakpoint_is_defined(address)) sprintf(str, "*"); else str[0] = '\0'; @@ -258,35 +258,36 @@ pgmwin_refresh(void) gtk_list_store_set(store, &iter, COL_BREAKPT, str, -1); /* Display base address. */ - int2asciihex(Address, str, 4); + int2asciihex(address, str, 4); gtk_list_store_set(store, &iter, COL_ADDR, str, -1); - OpCode = memory_read8(PGM_MEM_ID, Address); - InstSize = cpu8051_get_instruction_size(OpCode); + opcode = memory_read8(PGM_MEM_ID, address); + inst_size = cpu8051_get_instruction_size(opcode); /* Display instruction hex bytes. */ for (k = 0, col_id = COL_B0; k < 3; k++, col_id++) { - if (k < InstSize) + if (k < inst_size) int2asciihex(memory_read8(PGM_MEM_ID, - Address + k), + address + k), str, 2); else str[0] = '\0'; - gtk_list_store_set(store, &iter, col_id, str, -1); + gtk_list_store_set(store, &iter, col_id, str, + -1); } /* Display instruction menmonic. */ - cpu8051_disasm_mnemonic(OpCode, str); + cpu8051_disasm_mnemonic(opcode, str); gtk_list_store_set(store, &iter, COL_INST, str, -1); /* Display instruction arguments (if applicable). */ str[0] = '\0'; - cpu8051_disasm_args(Address, str); + cpu8051_disasm_args(address, str); gtk_list_store_set(store, &iter, COL_ARGS, str, -1); - Address += InstSize; + address += inst_size; } } } diff --git a/src/gtk/pgmwin.h b/src/gtk/pgmwin.h index d2518b2..51194de 100644 --- a/src/gtk/pgmwin.h +++ b/src/gtk/pgmwin.h @@ -18,7 +18,4 @@ pgmwin_init(void); void pgmwin_refresh(void); -int -pgmwin_IsBreakpoint(unsigned int address); - #endif /* PGMWIN_H */ diff --git a/src/gtk/pswwin.c b/src/gtk/pswwin.c index f1577ef..9dd6816 100644 --- a/src/gtk/pswwin.c +++ b/src/gtk/pswwin.c @@ -29,8 +29,8 @@ static GtkWidget *pswlist; #define DATA_ROWS 1 #define LIST_VIEW_NAME "PSW" -enum -{ + +enum { COL_CY = 0, COL_AC, COL_F0, @@ -88,18 +88,17 @@ pswwin_cell_edited(GtkCellRendererText *cell, gchar *path_string, char str[10]; int bit_index; - if (!model) { - g_error("Unable to get model from cell renderer"); - } + if (!model) + log_err("Unable to get model from cell renderer"); /* Column number is passed as renderer object data */ - columnptr = g_object_get_data(G_OBJECT(cell), "column"); - column = GPOINTER_TO_UINT(columnptr); + columnptr = g_object_get_data(G_OBJECT(cell), "column"); + column = GPOINTER_TO_UINT(columnptr); log_info("column = $%02X", column); /* Get the iterator */ - gtk_tree_model_get_iter_from_string(model, &iter, path_string); + gtk_tree_model_get_iter_from_string(model, &iter, path_string); bit_index = 7 - column; @@ -124,13 +123,13 @@ pswwin_cell_edited(GtkCellRendererText *cell, gchar *path_string, int2asciihex(new, str, 1); /* Store new value in gtk model. */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1); /* * Make sure to update all registers and memory. * For example, BANKed registers depends on internal memory. */ - emugtk_UpdateDisplay(); + emugtk_update_display(); }; static void @@ -151,7 +150,8 @@ pswwin_init_columns(void) g_signal_connect(renderer, "edited", G_CALLBACK(pswwin_cell_edited), - gtk_tree_view_get_model(GTK_TREE_VIEW(pswlist))); + gtk_tree_view_get_model( + GTK_TREE_VIEW(pswlist))); /* Add column index, used when editing the cell. */ g_object_set_data(G_OBJECT(renderer), "column", @@ -164,7 +164,8 @@ pswwin_init_columns(void) g_object_set(column, "alignment", 0.5, NULL); /* Hardcoded width... */ - gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); + gtk_tree_view_column_set_sizing(column, + GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_fixed_width(column, 35); gtk_tree_view_append_column(GTK_TREE_VIEW(pswlist), column); @@ -185,7 +186,8 @@ pswwin_init(void) /* Creating the view component */ pswlist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(pswlist), GTK_TREE_VIEW_GRID_LINES_BOTH); + gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(pswlist), + GTK_TREE_VIEW_GRID_LINES_BOTH); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(pswlist), TRUE); gtk_container_add(GTK_CONTAINER(frame), pswlist); diff --git a/src/gtk/regwin.c b/src/gtk/regwin.c index 0b027a5..2358685 100644 --- a/src/gtk/regwin.c +++ b/src/gtk/regwin.c @@ -30,8 +30,7 @@ static GtkWidget *reglist; #define LIST_VIEW_NAME "Registers" #define DATA_ROWS SFR_REGS -enum -{ +enum { COL_NAME = 0, COL_VAL, N_COLUMNS, @@ -73,12 +72,11 @@ regwin_cell_edited(GtkCellRendererText *cell, gchar *path_string, (void) cell; /* Remove compiler warning about unused variables. */ - if (!model) { - g_error("Unable to get model from cell renderer"); - } + if (!model) + log_err("Unable to get model from cell renderer"); /* Get the iterator */ - gtk_tree_model_get_iter_from_string(model, &iter, path_string); + gtk_tree_model_get_iter_from_string(model, &iter, path_string); /* Get register name. */ gtk_tree_model_get(model, &iter, COL_NAME, &str, -1); @@ -101,13 +99,14 @@ regwin_cell_edited(GtkCellRendererText *cell, gchar *path_string, if (rc == 0) { /* Store new value in gtk model. */ int2asciihex(new, str, regwin_infos->w); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_VAL, str, -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_VAL, str, + -1); /* * Make sure to update all windows. * For example, R0-R7 values depends on internal memory values. */ - emugtk_UpdateDisplay(); + emugtk_update_display(); } }; diff --git a/src/gtk/timerwin.c b/src/gtk/timerwin.c index f65d525..985ffd4 100644 --- a/src/gtk/timerwin.c +++ b/src/gtk/timerwin.c @@ -27,9 +27,10 @@ button_add_stock(GtkWidget *box, gchar *stock_id, int display_label) GtkWidget *button; /* Create the button. */ - if (display_label != false) + if (display_label) { + /* By default, a label is appended to stock buttons. */ button = gtk_button_new_from_stock(stock_id); - else { + } else { GtkWidget *icon; button = gtk_button_new(); @@ -52,7 +53,8 @@ timerwin_update(void) for (id = 0; id < GP_TIMERS_COUNT; id++) { /* Display textin bold, with big font size. */ - sprintf(buf , "%08d cycles", gp_timer_read(id)); + sprintf(buf , "%08d cycles", + gp_timer_read(id)); gtk_label_set_markup(GTK_LABEL(label[id]), buf); } diff --git a/src/gtk/viewmenu.c b/src/gtk/viewmenu.c index efe8c88..e7b068f 100644 --- a/src/gtk/viewmenu.c +++ b/src/gtk/viewmenu.c @@ -25,7 +25,7 @@ void toggle_layout(GtkWidget *widget, gpointer data) { int id; - id = GPOINTER_TO_UINT(data); + id = GPOINTER_TO_UINT(data); if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { log_info(" Switching to layout %d", id); @@ -40,7 +40,7 @@ void toggle_bytes_per_row(GtkWidget *widget, gpointer data) { int bytes_per_row; - bytes_per_row = GPOINTER_TO_UINT(data); + bytes_per_row = GPOINTER_TO_UINT(data); if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { log_info(" Bytes per row = %d", bytes_per_row); @@ -97,9 +97,11 @@ view_add_layout_submenu(GtkWidget *parent) layout2 = gtk_radio_menu_item_new_with_label(group, "Layout2"); if (cfg->layout == UI_LAYOUT1) - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(layout1), TRUE); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(layout1), + TRUE); else - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(layout2), TRUE); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(layout2), + TRUE); g_signal_connect(G_OBJECT(layout1), "activate", G_CALLBACK(toggle_layout), (gpointer) UI_LAYOUT1); @@ -130,9 +132,11 @@ view_add_bytes_per_row_submenu(GtkWidget *parent) item2 = gtk_radio_menu_item_new_with_label(group, "16"); if (cfg->bytes_per_row == 8) - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item1), TRUE); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item1), + TRUE); else - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item2), TRUE); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item2), + TRUE); g_signal_connect(G_OBJECT(item1), "activate", G_CALLBACK(toggle_bytes_per_row), (gpointer) 8); @@ -146,7 +150,7 @@ view_add_bytes_per_row_submenu(GtkWidget *parent) } void -ViewAddMenu(GtkWidget *menu_bar) +view_add_menu(GtkWidget *menu_bar) { GtkWidget *item; GtkWidget *menu; @@ -170,12 +174,12 @@ ViewAddMenu(GtkWidget *menu_bar) g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(toggle_ext_memory), NULL); - AddMenuSeparator(menu); + add_menu_separator(menu); /* Add layout submenu */ view_add_layout_submenu(menu); - AddMenuSeparator(menu); + add_menu_separator(menu); /* Add bytes per row submenu */ view_add_bytes_per_row_submenu(menu); diff --git a/src/gtk/viewmenu.h b/src/gtk/viewmenu.h index f92d940..80aada8 100644 --- a/src/gtk/viewmenu.h +++ b/src/gtk/viewmenu.h @@ -13,6 +13,6 @@ #include void -ViewAddMenu(GtkWidget *menu_bar); +view_add_menu(GtkWidget *menu_bar); #endif /* VIEWMENU_H */