Skip to content

Commit

Permalink
Coding standards: if's should always have {
Browse files Browse the repository at this point in the history
  • Loading branch information
indigodarkwolf committed Jun 5, 2024
1 parent 7e76d6c commit 9429842
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 78 deletions.
8 changes: 5 additions & 3 deletions src/compat/getopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down
70 changes: 42 additions & 28 deletions src/cpu/instructions_6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand All @@ -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++;
}
}
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
13 changes: 8 additions & 5 deletions src/cpu/instructions_65c02.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

// *******************************************************************************************
Expand Down Expand Up @@ -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++;
}
}
}

Expand Down Expand Up @@ -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++;
}
}
}

Expand Down
46 changes: 25 additions & 21 deletions src/cpu/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/javascript_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 2 additions & 1 deletion src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(len));
if (bytes_read < len)
if (bytes_read < len) {
break;
}

// Wrap into the next bank
start = 0xa000;
Expand Down
6 changes: 4 additions & 2 deletions src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 9429842

Please sign in to comment.