From 94298420f095708686b6e896f0115726cfa6d403 Mon Sep 17 00:00:00 2001 From: Stephen Horn Date: Tue, 4 Jun 2024 22:53:29 -0500 Subject: [PATCH] Coding standards: if's should always have { --- src/compat/getopt.cpp | 8 +++-- src/cpu/instructions_6502.h | 70 +++++++++++++++++++++--------------- src/cpu/instructions_65c02.h | 13 ++++--- src/cpu/support.h | 46 +++++++++++++----------- src/display.cpp | 15 +++++--- src/javascript_interface.cpp | 5 +-- src/loadsave.cpp | 3 +- src/memory.cpp | 6 ++-- src/overlay/overlay.cpp | 21 +++++++---- src/vera/vera_video.cpp | 10 +++--- 10 files changed, 119 insertions(+), 78 deletions(-) diff --git a/src/compat/getopt.cpp b/src/compat/getopt.cpp index 10eb91e..b01cf29 100644 --- a/src/compat/getopt.cpp +++ b/src/compat/getopt.cpp @@ -308,8 +308,9 @@ parse_long_options(char *const *nargv, const char *options, const struct option for (i = 0; long_options[i].name; i++) { /* find matching long option */ - if (strncmp(current_argv, long_options[i].name, current_argv_len)) + if (strncmp(current_argv, long_options[i].name, current_argv_len)) { continue; + } if (strlen(long_options[i].name) == current_argv_len) { /* exact match */ @@ -324,10 +325,11 @@ parse_long_options(char *const *nargv, const char *options, const struct option if (short_too && current_argv_len == 1) continue; - if (match == -1) /* partial match */ + if (match == -1) { /* partial match */ match = i; - else if (!IDENTICAL_INTERPRETATION(i, match)) + } else if (!IDENTICAL_INTERPRETATION(i, match)) { ambiguous = 1; + } } if (ambiguous) { /* ambiguous abbreviation */ diff --git a/src/cpu/instructions_6502.h b/src/cpu/instructions_6502.h index cb83cc8..5169c44 100644 --- a/src/cpu/instructions_6502.h +++ b/src/cpu/instructions_6502.h @@ -93,10 +93,11 @@ bcc() if ((state6502.status & FLAG_CARRY) == 0) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -106,10 +107,11 @@ bcs() if ((state6502.status & FLAG_CARRY) == FLAG_CARRY) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -119,10 +121,11 @@ beq() if ((state6502.status & FLAG_ZERO) == FLAG_ZERO) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -142,10 +145,11 @@ bmi() if ((state6502.status & FLAG_SIGN) == FLAG_SIGN) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -155,10 +159,11 @@ bne() if ((state6502.status & FLAG_ZERO) == 0) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -168,10 +173,11 @@ bpl() if ((state6502.status & FLAG_SIGN) == 0) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -194,10 +200,11 @@ bvc() if ((state6502.status & FLAG_OVERFLOW) == 0) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -207,10 +214,11 @@ bvs() if ((state6502.status & FLAG_OVERFLOW) == FLAG_OVERFLOW) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; // check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -245,14 +253,16 @@ cmp() value = getvalue(); result = (uint16_t)state6502.a - value; - if (state6502.a >= (uint8_t)(value & 0x00FF)) + if (state6502.a >= (uint8_t)(value & 0x00FF)) { setcarry(); - else + } else { clearcarry(); - if (state6502.a == (uint8_t)(value & 0x00FF)) + } + if (state6502.a == (uint8_t)(value & 0x00FF)) { setzero(); - else + } else { clearzero(); + } signcalc(result); } @@ -262,14 +272,16 @@ cpx() value = getvalue(); result = (uint16_t)state6502.x - value; - if (state6502.x >= (uint8_t)(value & 0x00FF)) + if (state6502.x >= (uint8_t)(value & 0x00FF)) { setcarry(); - else + } else { clearcarry(); - if (state6502.x == (uint8_t)(value & 0x00FF)) + } + if (state6502.x == (uint8_t)(value & 0x00FF)) { setzero(); - else + } else { clearzero(); + } signcalc(result); } @@ -279,14 +291,16 @@ cpy() value = getvalue(); result = (uint16_t)state6502.y - value; - if (state6502.y >= (uint8_t)(value & 0x00FF)) + if (state6502.y >= (uint8_t)(value & 0x00FF)) { setcarry(); - else + } else { clearcarry(); - if (state6502.y == (uint8_t)(value & 0x00FF)) + } + if (state6502.y == (uint8_t)(value & 0x00FF)) { setzero(); - else + } else { clearzero(); + } signcalc(result); } diff --git a/src/cpu/instructions_65c02.h b/src/cpu/instructions_65c02.h index cb124dd..647e4dd 100644 --- a/src/cpu/instructions_65c02.h +++ b/src/cpu/instructions_65c02.h @@ -70,8 +70,9 @@ bra() { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502++; //check if jump crossed a page boundary + } } // ******************************************************************************************* @@ -171,10 +172,11 @@ bbr(uint16_t bitmask) if ((getvalue() & bitmask) == 0) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; //check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } @@ -225,10 +227,11 @@ bbs(uint16_t bitmask) if ((getvalue() & bitmask) != 0) { oldpc = state6502.pc; state6502.pc += reladdr; - if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) + if ((oldpc & 0xFF00) != (state6502.pc & 0xFF00)) { clockticks6502 += 2; //check if jump crossed a page boundary - else + } else { clockticks6502++; + } } } diff --git a/src/cpu/support.h b/src/cpu/support.h index 98d314b..84bc174 100644 --- a/src/cpu/support.h +++ b/src/cpu/support.h @@ -24,36 +24,40 @@ # define clearsign() state6502.status &= (~FLAG_SIGN) // flag calculation macros -# define zerocalc(n) \ - { \ - if ((n)&0x00FF) \ - clearzero(); \ - else \ - setzero(); \ +# define zerocalc(n) \ + { \ + if ((n)&0x00FF) { \ + clearzero(); \ + } else { \ + setzero(); \ + } \ } -# define signcalc(n) \ - { \ - if ((n)&0x0080) \ - setsign(); \ - else \ - clearsign(); \ +# define signcalc(n) \ + { \ + if ((n)&0x0080) { \ + setsign(); \ + } else { \ + clearsign(); \ + } \ } -# define carrycalc(n) \ +# define carrycalc(n) \ { \ - if ((n)&0xFF00) \ + if ((n)&0xFF00) { \ setcarry(); \ - else \ + } else { \ clearcarry(); \ + } \ } -# define overflowcalc(n, m, o) \ - { /* n = result, m = accumulator, o = memory */ \ - if (((n) ^ (uint16_t)(m)) & ((n) ^ (o)) & 0x0080) \ - setoverflow(); \ - else \ - clearoverflow(); \ +# define overflowcalc(n, m, o) \ + { /* n = result, m = accumulator, o = memory */ \ + if (((n) ^ (uint16_t)(m)) & ((n) ^ (o)) & 0x0080) { \ + setoverflow(); \ + } else { \ + clearoverflow(); \ + } \ } // a few general functions used by various other functions diff --git a/src/display.cpp b/src/display.cpp index a71cb69..714236f 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -551,20 +551,25 @@ void display_shutdown() Fullscreen = false; SDL_SetWindowFullscreen(Display_window, 0); - if (Initd_imgui_opengl) + if (Initd_imgui_opengl) { ImGui_ImplOpenGL2_Shutdown(); + } - if (Initd_imgui_sdl2) + if (Initd_imgui_sdl2) { ImGui_ImplSDL2_Shutdown(); + } - if (Initd_imgui) + if (Initd_imgui) { ImGui::DestroyContext(); + } - if (Initd_display_context) + if (Initd_display_context) { SDL_GL_DeleteContext(Display_context); + } - if (Initd_sdl_gl) + if (Initd_sdl_gl) { SDL_DestroyWindow(Display_window); + } Initd_sdl_image = false; Initd_sdl_gl = false; diff --git a/src/javascript_interface.cpp b/src/javascript_interface.cpp index ebf2cd1..6d87814 100644 --- a/src/javascript_interface.cpp +++ b/src/javascript_interface.cpp @@ -25,8 +25,9 @@ void j2c_paste(char *buffer) void j2c_start_audio(bool start) { - if (start) + if (start) { audio_init(NULL, 8); - else + } else { audio_close(); + } } diff --git a/src/loadsave.cpp b/src/loadsave.cpp index 1e8aaed..282ea77 100644 --- a/src/loadsave.cpp +++ b/src/loadsave.cpp @@ -201,8 +201,9 @@ void LOAD() while (1) { size_t len = 0xc000 - start; bytes_read = (uint16_t)x16read(f, RAM + (((memory_get_ram_bank() % (uint16_t)Options.num_ram_banks) << 13) & 0xffffff) + start, sizeof(uint8_t), static_cast(len)); - if (bytes_read < len) + if (bytes_read < len) { break; + } // Wrap into the next bank start = 0xa000; diff --git a/src/memory.cpp b/src/memory.cpp index 18fd51f..166964d 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -428,8 +428,9 @@ static void debug_write(uint16_t address, uint8_t bank, uint8_t value) case MEMMAP_NULL: break; case MEMMAP_DIRECT: RAM[address] = value; - if (address == 1) + if (address == 1) { ROM_BANK = value; + } break; case MEMMAP_RAMBANK: debug_ram_write(address, bank, value); break; case MEMMAP_ROMBANK: debug_rom_write(address, bank, value); break; @@ -459,8 +460,9 @@ static void real_write(uint16_t address, uint8_t value) RAM_written[address >> 6] |= (uint64_t)1 << (address & 0x3f); ++RAM_write_counts[address]; RAM[address] = value; - if (address == 1) + if (address == 1) { ROM_BANK = value; + } break; case MEMMAP_RAMBANK: real_ram_write(address, value); break; case MEMMAP_ROMBANK: real_rom_write(address, value); break; diff --git a/src/overlay/overlay.cpp b/src/overlay/overlay.cpp index de47daf..358bf82 100644 --- a/src/overlay/overlay.cpp +++ b/src/overlay/overlay.cpp @@ -1052,8 +1052,9 @@ static void draw_debugger_vera_sprite() if (box[3] < box[2]) box[2] = 0; spr->off_screen = (box[0] >= screen_width && box[1] >= screen_width) || (box[2] >= screen_height && box[3] >= screen_height); - if (!((hide_disabled && (spr->prop.sprite_zdepth == 0)) || (hide_offscreen && spr->off_screen))) + if (!((hide_disabled && (spr->prop.sprite_zdepth == 0)) || (hide_offscreen && spr->off_screen))) { sprite_table_entries.push_back(i); + } uint32_t *dstpix = &sprite_pixels[i * 64 * 64]; int src = 0; @@ -1334,12 +1335,15 @@ static void draw_debugger_vera_sprite() if (ImGui::InputText("flg", flags_txt, 4)) { uint8_t b1_new = b1 & ~mask_8; uint8_t b6_new = b6 & ~mask_h & ~mask_v; - if (strchr(flags_txt, '8')) + if (strchr(flags_txt, '8')) { b1_new |= mask_8; - if (strchr(flags_txt, 'H') || strchr(flags_txt, 'h')) + } + if (strchr(flags_txt, 'H') || strchr(flags_txt, 'h')) { b6_new |= mask_h; - if (strchr(flags_txt, 'V') || strchr(flags_txt, 'v')) + } + if (strchr(flags_txt, 'V') || strchr(flags_txt, 'v')) { b6_new |= mask_v; + } vera_video_space_write(dst + 1, b1_new); vera_video_space_write(dst + 6, b6_new); } @@ -1565,12 +1569,15 @@ class vram_visualizer if (ImGui::BeginCombo("Source", source_txts[active.mem_source])) { for (int i = 0; i < 3; i++) { const bool selected = active.mem_source == i; - if (ImGui::Selectable(source_txts[i], selected)) + if (ImGui::Selectable(source_txts[i], selected)) { active.mem_source = i; - if (selected) + } + if (selected) { ImGui::SetItemDefaultFocus(); - if (i == 0) + } + if (i == 0) { ImGui::Separator(); + } } ImGui::EndCombo(); } diff --git a/src/vera/vera_video.cpp b/src/vera/vera_video.cpp index 2f4d5fc..6962ff6 100644 --- a/src/vera/vera_video.cpp +++ b/src/vera/vera_video.cpp @@ -1133,15 +1133,17 @@ static uint32_t get_and_inc_address(uint8_t sel, bool write) if (sel == 1 && fx_16bit_hop) { if (incr == 4) { - if (fx_16bit_hop_align == (address & 0x3)) + if (fx_16bit_hop_align == (address & 0x3)) { incr = 1; - else + } else { incr = 3; + } } else if (incr == 320) { - if (fx_16bit_hop_align == (address & 0x3)) + if (fx_16bit_hop_align == (address & 0x3)) { incr = 1; - else + } else { incr = 319; + } } }