Skip to content

Commit

Permalink
Use bool for bitfield values
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 committed May 30, 2024
1 parent a2f0395 commit e46903e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/benchmark/peanut-benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions examples/debug/peanut-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/mini_fb/peanut_minifb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/sdl2/peanut_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
57 changes: 29 additions & 28 deletions peanut_gb.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#endif

#include <stdlib.h> /* Required for qsort and abort */
#include <stdbool.h> /* Required for bool types */
#include <stdint.h> /* Required for int types */
#include <string.h> /* Required for memset */
#include <time.h> /* Required for tm struct */
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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
{
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/test_external_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e46903e

Please sign in to comment.