From e46903e90b9fa1d7c2988fcdf04ccab8297e128a Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Wed, 29 May 2024 20:26:45 +0100 Subject: [PATCH] Use bool for bitfield values --- examples/benchmark/peanut-benchmark.c | 2 +- examples/debug/peanut-debug.c | 4 +- examples/mini_fb/peanut_minifb.c | 2 +- examples/sdl2/peanut_sdl.c | 4 +- peanut_gb.h | 57 ++++++++++++++------------- test/test_external_rom.c | 2 +- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/examples/benchmark/peanut-benchmark.c b/examples/benchmark/peanut-benchmark.c index 0981569..3c2b44c 100644 --- a/examples/benchmark/peanut-benchmark.c +++ b/examples/benchmark/peanut-benchmark.c @@ -185,7 +185,7 @@ int main(int argc, char **argv) #if ENABLE_LCD gb_init_lcd(&gb, &lcd_draw_line); - // gb.direct.interlace = 1; + // gb.direct.interlace = true; #endif start_time = clock(); diff --git a/examples/debug/peanut-debug.c b/examples/debug/peanut-debug.c index a9d54ca..15716cd 100644 --- a/examples/debug/peanut-debug.c +++ b/examples/debug/peanut-debug.c @@ -379,8 +379,8 @@ int main(int argc, char **argv) /* Execute CPU cycles until the screen has to be redrawn. */ //gb_run_frame(&gb); - gb.gb_frame = 0; - while(gb.gb_frame == 0) + gb.gb_frame = false; + while(!gb.gb_frame) { const char *lcd_mode_str[4] = { "HBLANK", "VBLANK", "OAM", "TRANSFER" diff --git a/examples/mini_fb/peanut_minifb.c b/examples/mini_fb/peanut_minifb.c index 7f7d8c6..fdd015b 100644 --- a/examples/mini_fb/peanut_minifb.c +++ b/examples/mini_fb/peanut_minifb.c @@ -159,7 +159,7 @@ int main(int argc, char **argv) #if ENABLE_LCD gb_init_lcd(&gb, &lcd_draw_line); - // gb.direct.interlace = 1; + // gb.direct.interlace = true; #endif if(!mfb_open("Peanut-minifb", LCD_WIDTH, LCD_HEIGHT)) diff --git a/examples/sdl2/peanut_sdl.c b/examples/sdl2/peanut_sdl.c index b3126f7..3d22efd 100644 --- a/examples/sdl2/peanut_sdl.c +++ b/examples/sdl2/peanut_sdl.c @@ -1155,11 +1155,11 @@ int main(int argc, char **argv) #if ENABLE_LCD case SDLK_i: - gb.direct.interlace = ~gb.direct.interlace; + gb.direct.interlace = !gb.direct.interlace; break; case SDLK_o: - gb.direct.frame_skip = ~gb.direct.frame_skip; + gb.direct.frame_skip = !gb.direct.frame_skip; break; case SDLK_b: diff --git a/peanut_gb.h b/peanut_gb.h index 663d3f3..401aa1f 100644 --- a/peanut_gb.h +++ b/peanut_gb.h @@ -42,6 +42,7 @@ #endif #include /* Required for qsort and abort */ +#include /* Required for bool types */ #include /* Required for int types */ #include /* Required for memset */ #include /* Required for tm struct */ @@ -591,10 +592,10 @@ struct gb_s struct { - uint8_t gb_halt : 1; - uint8_t gb_ime : 1; - uint8_t gb_frame : 1; /* New frame drawn. */ - uint8_t lcd_blank : 1; + bool gb_halt : 1; + bool gb_ime : 1; + bool gb_frame : 1; /* New frame drawn. */ + bool lcd_blank : 1; }; /* Cartridge information: @@ -659,8 +660,8 @@ struct gb_s uint8_t WY; /* Only support 30fps frame skip. */ - uint8_t frame_skip_count : 1; - uint8_t interlace_count : 1; + bool frame_skip_count : 1; + bool interlace_count : 1; } display; /** @@ -675,8 +676,8 @@ struct gb_s /* Set to enable interlacing. Interlacing will start immediately * (at the next line drawing). */ - uint8_t interlace : 1; - uint8_t frame_skip : 1; + bool interlace : 1; + bool frame_skip : 1; union { @@ -1087,7 +1088,7 @@ void __gb_write(struct gb_s *gb, uint_fast16_t addr, uint8_t val) /* Check if LCD is going to be switched on. */ if (!lcd_enabled && (val & LCDC_ENABLE)) { - gb->lcd_blank = 1; + gb->lcd_blank = true; } /* Check if LCD is being switched off. */ else if (lcd_enabled && !(val & LCDC_ENABLE)) @@ -1416,9 +1417,9 @@ void __gb_draw_line(struct gb_s *gb) * line. */ if(gb->direct.interlace) { - if((gb->display.interlace_count == 0 + if((!gb->display.interlace_count && (gb->hram_io[IO_LY] & 1) == 0) - || (gb->display.interlace_count == 1 + || (gb->display.interlace_count && (gb->hram_io[IO_LY] & 1) == 1)) { /* Compensate for missing window draw if required. */ @@ -1757,13 +1758,13 @@ void __gb_step_cpu(struct gb_s *gb) while(gb->gb_halt || (gb->gb_ime && gb->hram_io[IO_IF] & gb->hram_io[IO_IE] & ANY_INTR)) { - gb->gb_halt = 0; + gb->gb_halt = false; if(!gb->gb_ime) break; /* Disable interrupts */ - gb->gb_ime = 0; + gb->gb_ime = false; /* Push Program Counter */ __gb_write(gb, --gb->cpu_reg.sp.reg, gb->cpu_reg.pc.bytes.p); @@ -1890,7 +1891,7 @@ void __gb_step_cpu(struct gb_s *gb) break; case 0x10: /* STOP */ - //gb->gb_halt = 1; + //gb->gb_halt = true; break; case 0x11: /* LD DE, imm */ @@ -2407,7 +2408,7 @@ void __gb_step_cpu(struct gb_s *gb) int_fast16_t halt_cycles = INT_FAST16_MAX; /* TODO: Emulate HALT bug? */ - gb->gb_halt = 1; + gb->gb_halt = true; if (gb->hram_io[IO_IE] == 0) { @@ -3014,7 +3015,7 @@ void __gb_step_cpu(struct gb_s *gb) { gb->cpu_reg.pc.bytes.c = __gb_read(gb, gb->cpu_reg.sp.reg++); gb->cpu_reg.pc.bytes.p = __gb_read(gb, gb->cpu_reg.sp.reg++); - gb->gb_ime = 1; + gb->gb_ime = true; } break; @@ -3151,7 +3152,7 @@ void __gb_step_cpu(struct gb_s *gb) break; case 0xF3: /* DI */ - gb->gb_ime = 0; + gb->gb_ime = false; break; case 0xF5: /* PUSH AF */ @@ -3198,7 +3199,7 @@ void __gb_step_cpu(struct gb_s *gb) } case 0xFB: /* EI */ - gb->gb_ime = 1; + gb->gb_ime = true; break; case 0xFE: /* CP imm */ @@ -3380,9 +3381,9 @@ void __gb_step_cpu(struct gb_s *gb) { gb->hram_io[IO_STAT] = (gb->hram_io[IO_STAT] & ~STAT_MODE) | IO_STAT_MODE_VBLANK; - gb->gb_frame = 1; + gb->gb_frame = true; gb->hram_io[IO_IF] |= VBLANK_INTR; - gb->lcd_blank = 0; + gb->lcd_blank = false; if(gb->hram_io[IO_STAT] & STAT_MODE_1_INTR) gb->hram_io[IO_IF] |= LCDC_INTR; @@ -3463,7 +3464,7 @@ void __gb_step_cpu(struct gb_s *gb) void gb_run_frame(struct gb_s *gb) { - gb->gb_frame = 0; + gb->gb_frame = false; while(!gb->gb_frame) __gb_step_cpu(gb); @@ -3516,8 +3517,8 @@ uint8_t gb_colour_hash(struct gb_s *gb) */ void gb_reset(struct gb_s *gb) { - gb->gb_halt = 0; - gb->gb_ime = 1; + gb->gb_halt = false; + gb->gb_ime = true; /* Initialise MBC values. */ gb->selected_rom_bank = 1; @@ -3670,7 +3671,7 @@ enum gb_init_error_e gb_init(struct gb_s *gb, * always has 512 half-bytes of RAM. Hence, gb->num_ram_banks must be * ignored for MBC2. */ - gb->lcd_blank = 0; + gb->lcd_blank = false; gb->display.lcd_draw_line = NULL; gb_reset(gb); @@ -3710,10 +3711,10 @@ void gb_init_lcd(struct gb_s *gb, { gb->display.lcd_draw_line = lcd_draw_line; - gb->direct.interlace = 0; - gb->display.interlace_count = 0; - gb->direct.frame_skip = 0; - gb->display.frame_skip_count = 0; + gb->direct.interlace = false; + gb->display.interlace_count = false; + gb->direct.frame_skip = false; + gb->display.frame_skip_count = false; gb->display.window_clear = 0; gb->display.WY = 0; diff --git a/test/test_external_rom.c b/test/test_external_rom.c index e9e6f52..a5a1693 100644 --- a/test/test_external_rom.c +++ b/test/test_external_rom.c @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) gb_init_serial(&gb, gb_serial_tx, NULL); #if ENABLE_LCD gb_init_lcd(&gb, &lcd_draw_line); - // gb.direct.interlace = 1; + // gb.direct.interlace = true; #endif do