From 163a5ea20c061fe66452017ef8f1b613af3f352f Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 29 Jan 2020 14:19:11 +0200 Subject: [PATCH 001/125] Add DMG color palettes (Cocoa) --- Cocoa/Document.m | 28 ++++++++++++++++++++ Cocoa/GBPreferencesWindow.h | 1 + Cocoa/GBPreferencesWindow.m | 21 +++++++++++++++ Cocoa/Preferences.xib | 43 ++++++++++++++++++++++++++----- Core/display.c | 14 +++++++--- Core/gb.c | 51 ++++++++++++++++++++++--------------- Core/gb.h | 15 ++++++++++- 7 files changed, 143 insertions(+), 30 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 85dd728..0c40776 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -184,6 +184,27 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } } +- (void) updatePalette +{ + switch ([[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorPalette"]) { + case 1: + GB_set_palette(&gb, &GB_PALETTE_DMG); + break; + + case 2: + GB_set_palette(&gb, &GB_PALETTE_MGB); + break; + + case 3: + GB_set_palette(&gb, &GB_PALETTE_GBL); + break; + + default: + GB_set_palette(&gb, &GB_PALETTE_GREY); + break; + } +} + - (void) initCommon { GB_init(&gb, [self internalModel]); @@ -193,6 +214,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) GB_set_input_callback(&gb, (GB_input_callback_t) consoleInput); GB_set_async_input_callback(&gb, (GB_input_callback_t) asyncConsoleInput); GB_set_color_correction_mode(&gb, (GB_color_correction_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorCorrection"]); + [self updatePalette]; GB_set_rgb_encode_callback(&gb, rgbEncode); GB_set_camera_get_pixel_callback(&gb, cameraGetPixel); GB_set_camera_update_request_callback(&gb, cameraRequestUpdate); @@ -452,6 +474,12 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) name:@"GBColorCorrectionChanged" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(updatePalette) + name:@"GBColorPaletteChanged" + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateRewindLength) name:@"GBRewindLengthChanged" diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h index 90eee54..b34aafa 100644 --- a/Cocoa/GBPreferencesWindow.h +++ b/Cocoa/GBPreferencesWindow.h @@ -7,6 +7,7 @@ @property (strong) IBOutlet NSButton *aspectRatioCheckbox; @property (strong) IBOutlet NSPopUpButton *highpassFilterPopupButton; @property (strong) IBOutlet NSPopUpButton *colorCorrectionPopupButton; +@property (nonatomic, strong) IBOutlet NSPopUpButton *colorPalettePopupButton; @property (strong) IBOutlet NSPopUpButton *rewindPopupButton; @property (strong) IBOutlet NSButton *configureJoypadButton; @property (strong) IBOutlet NSButton *skipButton; diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m index ecf0311..8d3e73d 100644 --- a/Cocoa/GBPreferencesWindow.m +++ b/Cocoa/GBPreferencesWindow.m @@ -14,6 +14,7 @@ NSPopUpButton *_graphicsFilterPopupButton; NSPopUpButton *_highpassFilterPopupButton; NSPopUpButton *_colorCorrectionPopupButton; + NSPopUpButton *_colorPalettePopupButton; NSPopUpButton *_rewindPopupButton; NSButton *_aspectRatioCheckbox; NSEventModifierFlags previousModifiers; @@ -84,6 +85,18 @@ return _colorCorrectionPopupButton; } +- (void)setColorPalettePopupButton:(NSPopUpButton *)colorPalettePopupButton +{ + _colorPalettePopupButton = colorPalettePopupButton; + NSInteger mode = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBColorPalette"]; + [_colorPalettePopupButton selectItemAtIndex:mode]; +} + +- (NSPopUpButton *)colorPalettePopupButton +{ + return _colorPalettePopupButton; +} + - (void)setRewindPopupButton:(NSPopUpButton *)rewindPopupButton { _rewindPopupButton = rewindPopupButton; @@ -199,6 +212,14 @@ } +- (IBAction)colorPaletteChanged:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem]) + forKey:@"GBColorPalette"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"GBColorPaletteChanged" object:nil]; + +} + - (IBAction)rewindLengthChanged:(id)sender { [[NSUserDefaults standardUserDefaults] setObject:@([sender selectedTag]) diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib index 8278ee1..2c05a64 100644 --- a/Cocoa/Preferences.xib +++ b/Cocoa/Preferences.xib @@ -63,6 +63,7 @@ + @@ -78,11 +79,11 @@ - + - + @@ -91,7 +92,7 @@ - + @@ -127,7 +128,7 @@ - + @@ -136,7 +137,7 @@ - + @@ -156,6 +157,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/Core/display.c b/Core/display.c index 5c1935c..f0e2ff2 100644 --- a/Core/display.c +++ b/Core/display.c @@ -142,9 +142,17 @@ static void display_vblank(GB_gameboy_t *gb) } } else { - uint32_t color = (gb->io_registers[GB_IO_LCDC] & 0x80) && gb->stopped && GB_is_cgb(gb) ? - gb->rgb_encode_callback(gb, 0, 0, 0) : - gb->rgb_encode_callback(gb, 0xFF, 0xFF, 0xFF); + uint32_t color = 0; + if (GB_is_cgb(gb)) { + color = (gb->io_registers[GB_IO_LCDC] & 0x80) && gb->stopped ? + gb->rgb_encode_callback(gb, 0, 0, 0) : + gb->rgb_encode_callback(gb, 0xFF, 0xFF, 0xFF); + } + else { + color = (gb->io_registers[GB_IO_LCDC] & 0x80) && gb->stopped ? + gb->background_palettes_rgb[3] : + gb->background_palettes_rgb[4]; + } for (unsigned i = 0; i < WIDTH * LINES; i++) { gb ->screen[i] = color; } diff --git a/Core/gb.c b/Core/gb.c index f29d400..d019fc4 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -573,21 +573,41 @@ void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) #endif } +const GB_palette_t GB_PALETTE_GREY = {{{0x00, 0x00, 0x00}, {0x55, 0x55, 0x55}, {0xaa, 0xaa, 0xaa}, {0xff ,0xff, 0xff}, {0xff ,0xff, 0xff}}}; +const GB_palette_t GB_PALETTE_DMG = {{{0x08, 0x18, 0x10}, {0x39, 0x61, 0x39}, {0x84, 0xa5, 0x63}, {0xc6, 0xde, 0x8c}, {0xd2 ,0xe6 ,0xa6}}}; +const GB_palette_t GB_PALETTE_MGB = {{{0x07, 0x10, 0x0e}, {0x3a, 0x4c, 0x3a}, {0x81, 0x8d, 0x66}, {0xc2, 0xce, 0x93}, {0xcf, 0xda, 0xac}}}; +const GB_palette_t GB_PALETTE_GBL = {{{0x0a, 0x1c, 0x15}, {0x35, 0x78, 0x62}, {0x56, 0xb4, 0x95}, {0x7f, 0xe2, 0xc3}, {0x91, 0xea, 0xd0}}}; + +static void update_dmg_palette(GB_gameboy_t *gb) +{ + const GB_palette_t *palette = gb->dmg_palette ?: &GB_PALETTE_GREY; + if (gb->rgb_encode_callback && !GB_is_cgb(gb)) { + gb->sprite_palettes_rgb[4] = gb->sprite_palettes_rgb[0] = gb->background_palettes_rgb[0] = + gb->rgb_encode_callback(gb, palette->colors[3].r, palette->colors[3].g, palette->colors[3].b); + gb->sprite_palettes_rgb[5] = gb->sprite_palettes_rgb[1] = gb->background_palettes_rgb[1] = + gb->rgb_encode_callback(gb, palette->colors[2].r, palette->colors[2].g, palette->colors[2].b); + gb->sprite_palettes_rgb[6] = gb->sprite_palettes_rgb[2] = gb->background_palettes_rgb[2] = + gb->rgb_encode_callback(gb, palette->colors[1].r, palette->colors[1].g, palette->colors[1].b); + gb->sprite_palettes_rgb[7] = gb->sprite_palettes_rgb[3] = gb->background_palettes_rgb[3] = + gb->rgb_encode_callback(gb, palette->colors[0].r, palette->colors[0].g, palette->colors[0].b); + + // LCD off color + gb->background_palettes_rgb[4] = + gb->rgb_encode_callback(gb, palette->colors[4].r, palette->colors[4].g, palette->colors[4].b); + } +} + +void GB_set_palette(GB_gameboy_t *gb, const GB_palette_t *palette) +{ + gb->dmg_palette = palette; + update_dmg_palette(gb); +} void GB_set_rgb_encode_callback(GB_gameboy_t *gb, GB_rgb_encode_callback_t callback) { - if (!gb->rgb_encode_callback && !GB_is_cgb(gb)) { - gb->sprite_palettes_rgb[4] = gb->sprite_palettes_rgb[0] = gb->background_palettes_rgb[0] = - callback(gb, 0xFF, 0xFF, 0xFF); - gb->sprite_palettes_rgb[5] = gb->sprite_palettes_rgb[1] = gb->background_palettes_rgb[1] = - callback(gb, 0xAA, 0xAA, 0xAA); - gb->sprite_palettes_rgb[6] = gb->sprite_palettes_rgb[2] = gb->background_palettes_rgb[2] = - callback(gb, 0x55, 0x55, 0x55); - gb->sprite_palettes_rgb[7] = gb->sprite_palettes_rgb[3] = gb->background_palettes_rgb[3] = - callback(gb, 0, 0, 0); - } gb->rgb_encode_callback = callback; + update_dmg_palette(gb); for (unsigned i = 0; i < 32; i++) { GB_palette_changed(gb, true, i * 2); @@ -882,16 +902,7 @@ void GB_reset(GB_gameboy_t *gb) gb->vram_size = 0x2000; memset(gb->vram, 0, gb->vram_size); - if (gb->rgb_encode_callback) { - gb->sprite_palettes_rgb[4] = gb->sprite_palettes_rgb[0] = gb->background_palettes_rgb[0] = - gb->rgb_encode_callback(gb, 0xFF, 0xFF, 0xFF); - gb->sprite_palettes_rgb[5] = gb->sprite_palettes_rgb[1] = gb->background_palettes_rgb[1] = - gb->rgb_encode_callback(gb, 0xAA, 0xAA, 0xAA); - gb->sprite_palettes_rgb[6] = gb->sprite_palettes_rgb[2] = gb->background_palettes_rgb[2] = - gb->rgb_encode_callback(gb, 0x55, 0x55, 0x55); - gb->sprite_palettes_rgb[7] = gb->sprite_palettes_rgb[3] = gb->background_palettes_rgb[3] = - gb->rgb_encode_callback(gb, 0, 0, 0); - } + update_dmg_palette(gb); } reset_ram(gb); diff --git a/Core/gb.h b/Core/gb.h index c27b6c6..7831cb7 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -50,6 +50,17 @@ #error Unable to detect endianess #endif +typedef struct { + struct { + uint8_t r,g,b; + } colors[5]; +} GB_palette_t; + +extern const GB_palette_t GB_PALETTE_GREY; +extern const GB_palette_t GB_PALETTE_DMG; +extern const GB_palette_t GB_PALETTE_MGB; +extern const GB_palette_t GB_PALETTE_GBL; + typedef union { struct { uint8_t seconds; @@ -61,7 +72,6 @@ typedef union { uint8_t data[5]; } GB_rtc_time_t; - typedef enum { // GB_MODEL_DMG_0 = 0x000, // GB_MODEL_DMG_A = 0x001, @@ -513,6 +523,7 @@ struct GB_gameboy_internal_s { uint32_t *screen; uint32_t background_palettes_rgb[0x20]; uint32_t sprite_palettes_rgb[0x20]; + const GB_palette_t *dmg_palette; GB_color_correction_mode_t color_correction_mode; bool keys[4][GB_KEY_MAX]; @@ -696,6 +707,8 @@ void GB_set_infrared_callback(GB_gameboy_t *gb, GB_infrared_callback_t callback) void GB_set_rumble_callback(GB_gameboy_t *gb, GB_rumble_callback_t callback); void GB_set_update_input_hint_callback(GB_gameboy_t *gb, GB_update_input_hint_callback_t callback); +void GB_set_palette(GB_gameboy_t *gb, const GB_palette_t *palette); + /* These APIs are used when using internal clock */ void GB_set_serial_transfer_bit_start_callback(GB_gameboy_t *gb, GB_serial_transfer_bit_start_callback_t callback); void GB_set_serial_transfer_bit_end_callback(GB_gameboy_t *gb, GB_serial_transfer_bit_end_callback_t callback); From 046b09052cd54562de710c1577df05e18713800a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 29 Jan 2020 15:36:19 +0200 Subject: [PATCH 002/125] Add DMG color palettes (SDL), add scrolling to SDL menus --- SDL/gui.c | 81 +++++++++++++++++++++++++++++++++++++++++------------- SDL/gui.h | 3 ++ SDL/main.c | 22 +++++++++++++++ 3 files changed, 87 insertions(+), 19 deletions(-) diff --git a/SDL/gui.c b/SDL/gui.c index db72c4d..d476175 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -175,8 +175,10 @@ static void draw_char(uint32_t *buffer, unsigned width, unsigned height, unsigne } } +static unsigned scroll = 0; static void draw_unbordered_text(uint32_t *buffer, unsigned width, unsigned height, unsigned x, unsigned y, const char *string, uint32_t color) { + y -= scroll; unsigned orig_x = x; while (*string) { if (*string == '\n') { @@ -297,6 +299,7 @@ static void return_to_root_menu(unsigned index) { current_menu = root_menu; current_selection = 0; + scroll = 0; } static void cycle_model(unsigned index) @@ -407,6 +410,7 @@ static void enter_emulation_menu(unsigned index) { current_menu = emulation_menu; current_selection = 0; + scroll = 0; } const char *current_scaling_mode(unsigned index) @@ -421,6 +425,12 @@ const char *current_color_correction_mode(unsigned index) [configuration.color_correction_mode]; } +const char *current_palette(unsigned index) +{ + return (const char *[]){"Greyscale", "Lime (Game Boy)", "Olive (Pocket)", "Teal (Light)"} + [configuration.dmg_palette]; +} + void cycle_scaling(unsigned index) { configuration.scaling_mode++; @@ -463,6 +473,26 @@ static void cycle_color_correction_backwards(unsigned index) } } +static void cycle_palette(unsigned index) +{ + if (configuration.dmg_palette == 3) { + configuration.dmg_palette = 0; + } + else { + configuration.dmg_palette++; + } +} + +static void cycle_palette_backwards(unsigned index) +{ + if (configuration.dmg_palette == 0) { + configuration.dmg_palette = 3; + } + else { + configuration.dmg_palette--; + } +} + struct shader_name { const char *file_name; const char *display_name; @@ -556,6 +586,7 @@ static const struct menu_item graphics_menu[] = { {"Scaling Mode:", cycle_scaling, current_scaling_mode, cycle_scaling_backwards}, {"Scaling Filter:", cycle_filter, current_filter_name, cycle_filter_backwards}, {"Color Correction:", cycle_color_correction, current_color_correction_mode, cycle_color_correction_backwards}, + {"Mono Palette:", cycle_palette, current_palette, cycle_palette_backwards}, {"Blend Frames:", toggle_blend_frames, blend_frames_string, toggle_blend_frames}, {"Back", return_to_root_menu}, {NULL,} @@ -565,6 +596,7 @@ static void enter_graphics_menu(unsigned index) { current_menu = graphics_menu; current_selection = 0; + scroll = 0; } const char *highpass_filter_string(unsigned index) @@ -601,6 +633,7 @@ static void enter_audio_menu(unsigned index) { current_menu = audio_menu; current_selection = 0; + scroll = 0; } static void modify_key(unsigned index) @@ -608,7 +641,6 @@ static void modify_key(unsigned index) gui_state = WAITING_FOR_KEY; } -static void enter_controls_menu_2(unsigned index); static const char *key_name(unsigned index); static const struct menu_item controls_menu[] = { @@ -620,12 +652,6 @@ static const struct menu_item controls_menu[] = { {"B:", modify_key, key_name,}, {"Select:", modify_key, key_name,}, {"Start:", modify_key, key_name,}, - {"Next Page", enter_controls_menu_2}, - {"Back", return_to_root_menu}, - {NULL,} -}; - -static const struct menu_item controls_menu_2[] = { {"Turbo:", modify_key, key_name,}, {"Rewind:", modify_key, key_name,}, {"Slow-Motion:", modify_key, key_name,}, @@ -635,11 +661,11 @@ static const struct menu_item controls_menu_2[] = { static const char *key_name(unsigned index) { - if (current_menu == controls_menu_2) { - if (index == 0) { + if (index >= 8) { + if (index == 8) { return SDL_GetScancodeName(configuration.keys[8]); } - return SDL_GetScancodeName(configuration.keys_2[index - 1]); + return SDL_GetScancodeName(configuration.keys_2[index - 9]); } return SDL_GetScancodeName(configuration.keys[index]); } @@ -648,12 +674,7 @@ static void enter_controls_menu(unsigned index) { current_menu = controls_menu; current_selection = 0; -} - -static void enter_controls_menu_2(unsigned index) -{ - current_menu = controls_menu_2; - current_selection = 0; + scroll = 0; } static unsigned joypad_index = 0; @@ -744,6 +765,7 @@ static void enter_joypad_menu(unsigned index) { current_menu = joypad_menu; current_selection = 0; + scroll = 0; } joypad_button_t get_joypad_button(uint8_t physical_button) @@ -826,6 +848,7 @@ void run_gui(bool is_running) bool should_render = true; current_menu = root_menu = is_running? paused_menu : nonpaused_menu; current_selection = 0; + scroll = 0; do { /* Convert Joypad and mouse events (We only generate down events) */ if (gui_state != WAITING_FOR_KEY && gui_state != WAITING_FOR_JBUTTON) { @@ -850,6 +873,7 @@ void run_gui(bool is_running) y = y * 8 / 7; y -= 144 / 16; } + y += scroll; if (x < 0 || x >= 160 || y < 24) { continue; @@ -1058,6 +1082,7 @@ void run_gui(bool is_running) gui_state = SHOWING_DROP_MESSAGE; } current_selection = 0; + scroll = 0; current_menu = root_menu; should_render = true; } @@ -1106,12 +1131,12 @@ void run_gui(bool is_running) should_render = true; } else if (gui_state == WAITING_FOR_KEY) { - if (current_menu == controls_menu_2) { - if (current_selection == 0) { + if (current_selection >= 8) { + if (current_selection == 8) { configuration.keys[8] = event.key.keysym.scancode; } else { - configuration.keys_2[current_selection - 1] = event.key.keysym.scancode; + configuration.keys_2[current_selection - 9] = event.key.keysym.scancode; } } else { @@ -1125,6 +1150,7 @@ void run_gui(bool is_running) if (should_render) { should_render = false; + rerender: if (width == 160 && height == 144) { memcpy(pixels, converted_background->pixels, sizeof(pixels)); } @@ -1144,6 +1170,16 @@ void run_gui(bool is_running) draw_text_centered(pixels, width, height, 8 + y_offset, "SameBoy", gui_palette_native[3], gui_palette_native[0], false); unsigned i = 0, y = 24; for (const struct menu_item *item = current_menu; item->string; item++, i++) { + if (i == current_selection) { + if (y < scroll) { + scroll = y - 4; + goto rerender; + } + } + if (i == current_selection && i == 0 && scroll != 0) { + scroll = 0; + goto rerender; + } if (item->value_getter && !item->backwards_handler) { char line[25]; snprintf(line, sizeof(line), "%s%*s", item->string, 24 - (int)strlen(item->string), item->value_getter(i)); @@ -1162,6 +1198,13 @@ void run_gui(bool is_running) y += 12; } } + if (i == current_selection) { + if (y > scroll + 144) { + scroll = y - 144; + goto rerender; + } + } + } break; case SHOWING_HELP: diff --git a/SDL/gui.h b/SDL/gui.h index b22c74f..ccfdfb9 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -100,6 +100,9 @@ typedef struct { SGB_2, SGB_MAX } sgb_revision; + + /* v0.13 */ + uint8_t dmg_palette; } configuration_t; extern configuration_t configuration; diff --git a/SDL/main.c b/SDL/main.c index 1646d5c..e83bfd8 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -92,6 +92,26 @@ static const char *end_capturing_logs(bool show_popup, bool should_exit) return captured_log; } +static void update_palette(void) +{ + switch (configuration.dmg_palette) { + case 1: + GB_set_palette(&gb, &GB_PALETTE_DMG); + break; + + case 2: + GB_set_palette(&gb, &GB_PALETTE_MGB); + break; + + case 3: + GB_set_palette(&gb, &GB_PALETTE_GBL); + break; + + default: + GB_set_palette(&gb, &GB_PALETTE_GREY); + } +} + static void open_menu(void) { bool audio_playing = SDL_GetAudioDeviceStatus(device_id) == SDL_AUDIO_PLAYING; @@ -105,6 +125,7 @@ static void open_menu(void) SDL_PauseAudioDevice(device_id, 0); } GB_set_color_correction_mode(&gb, configuration.color_correction_mode); + update_palette(); GB_set_highpass_filter_mode(&gb, configuration.highpass_mode); } @@ -454,6 +475,7 @@ restart: GB_set_rgb_encode_callback(&gb, rgb_encode); GB_set_sample_rate(&gb, have_aspec.freq); GB_set_color_correction_mode(&gb, configuration.color_correction_mode); + update_palette(); GB_set_highpass_filter_mode(&gb, configuration.highpass_mode); GB_set_rewind_length(&gb, configuration.rewind_length); GB_set_update_input_hint_callback(&gb, handle_events); From 99d2c0258c4da19b6b7a135bd9d0472388c79c33 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 29 Jan 2020 15:51:53 +0200 Subject: [PATCH 003/125] Add monochrome LCD shader --- Cocoa/GBPreferencesWindow.m | 1 + Cocoa/Preferences.xib | 15 ++++++++------- SDL/gui.c | 1 + Shaders/MonoLCD.fsh | 38 +++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 Shaders/MonoLCD.fsh diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m index 8d3e73d..5c5d375 100644 --- a/Cocoa/GBPreferencesWindow.m +++ b/Cocoa/GBPreferencesWindow.m @@ -32,6 +32,7 @@ @"NearestNeighbor", @"Bilinear", @"SmoothBilinear", + @"MonoLCD", @"LCD", @"CRT", @"Scale2x", diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib index 2c05a64..1062dae 100644 --- a/Cocoa/Preferences.xib +++ b/Cocoa/Preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -17,7 +17,7 @@ - + @@ -104,7 +104,8 @@ - + + @@ -428,7 +429,7 @@ - + @@ -472,11 +473,11 @@ - - + - + - + - + - + - + - - - - + + + + @@ -129,16 +130,16 @@ - + - + - + @@ -148,9 +149,9 @@ - - - + + + @@ -159,16 +160,16 @@ - + - + - + @@ -188,10 +189,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -233,7 +263,7 @@ - + @@ -251,12 +281,12 @@ - + - + @@ -275,7 +305,7 @@ - + @@ -303,7 +333,7 @@ - + @@ -333,7 +363,7 @@ - + @@ -371,16 +401,16 @@ - + - + - - + + @@ -391,7 +421,7 @@ - + @@ -429,7 +459,7 @@ - + diff --git a/Core/apu.h b/Core/apu.h index 011412e..933f14e 100644 --- a/Core/apu.h +++ b/Core/apu.h @@ -162,6 +162,7 @@ void GB_apu_div_event(GB_gameboy_t *gb); void GB_apu_init(GB_gameboy_t *gb); void GB_apu_run(GB_gameboy_t *gb); void GB_apu_update_cycles_per_sample(GB_gameboy_t *gb); +void GB_borrow_sgb_border(GB_gameboy_t *gb); #endif #endif /* apu_h */ diff --git a/Core/display.c b/Core/display.c index 7f3d23e..b7ddee1 100644 --- a/Core/display.c +++ b/Core/display.c @@ -99,6 +99,8 @@ static void fifo_overlay_object_row(GB_fifo_t *fifo, uint8_t lower, uint8_t uppe #define LINE_LENGTH (456) #define LINES (144) #define WIDTH (160) +#define BORDERED_WIDTH 256 +#define BORDERED_HEIGHT 224 #define FRAME_LENGTH (LCDC_PERIOD) #define VIRTUAL_LINES (FRAME_LENGTH / LINE_LENGTH) // = 154 @@ -134,7 +136,7 @@ static void display_vblank(GB_gameboy_t *gb) } } - if (!gb->disable_rendering && ((!(gb->io_registers[GB_IO_LCDC] & 0x80) || gb->stopped) || gb->frame_skip_state == GB_FRAMESKIP_LCD_TURNED_ON)) { + if ((!gb->disable_rendering || gb->sgb) && ((!(gb->io_registers[GB_IO_LCDC] & 0x80) || gb->stopped) || gb->frame_skip_state == GB_FRAMESKIP_LCD_TURNED_ON)) { /* LCD is off, set screen to white or black (if LCD is on in stop mode) */ if (gb->sgb) { for (unsigned i = 0; i < WIDTH * LINES; i++) { @@ -153,13 +155,70 @@ static void display_vblank(GB_gameboy_t *gb) gb->background_palettes_rgb[3] : gb->background_palettes_rgb[4]; } - for (unsigned i = 0; i < WIDTH * LINES; i++) { - gb ->screen[i] = color; + if (gb->border_mode == GB_BORDER_ALWAYS) { + for (unsigned y = 0; y < LINES; y++) { + for (unsigned x = 0; x < WIDTH; x++) { + gb ->screen[x + y * BORDERED_WIDTH + (BORDERED_WIDTH - WIDTH) / 2 + (BORDERED_HEIGHT - LINES) / 2 * BORDERED_WIDTH] = color; + } + } + } + else { + for (unsigned i = 0; i < WIDTH * LINES; i++) { + gb ->screen[i] = color; + } + } + } + } + + if (gb->border_mode == GB_BORDER_ALWAYS && !GB_is_sgb(gb)) { + GB_borrow_sgb_border(gb); + uint32_t border_colors[16 * 4]; + + if (!gb->has_sgb_border && GB_is_cgb(gb) && gb->model != GB_MODEL_AGB) { + static uint16_t colors[] = { + 0x2095, 0x5129, 0x1EAF, 0x1EBA, 0x4648, + 0x30DA, 0x69AD, 0x2B57, 0x2B5D, 0x632C, + 0x1050, 0x3C84, 0x0E07, 0x0E18, 0x2964, + }; + unsigned index = gb->rom[0x14e] % 5; + gb->borrowed_border.palette[0] = colors[index]; + gb->borrowed_border.palette[10] = colors[5 + index]; + gb->borrowed_border.palette[14] = colors[10 + index]; + + } + + for (unsigned i = 0; i < 16 * 4; i++) { + border_colors[i] = GB_convert_rgb15(gb, gb->borrowed_border.palette[i], true); + } + + for (unsigned tile_y = 0; tile_y < 28; tile_y++) { + for (unsigned tile_x = 0; tile_x < 32; tile_x++) { + if (tile_x >= 6 && tile_x < 26 && tile_y >= 5 && tile_y < 23) { + continue; + } + uint16_t tile = gb->borrowed_border.map[tile_x + tile_y * 32]; + uint8_t flip_x = (tile & 0x4000)? 0x7 : 0; + uint8_t flip_y = (tile & 0x8000)? 0x7 : 0; + uint8_t palette = (tile >> 10) & 3; + for (unsigned y = 0; y < 8; y++) { + for (unsigned x = 0; x < 8; x++) { + uint8_t color = gb->borrowed_border.tiles[(tile & 0xFF) * 64 + (x ^ flip_x) + (y ^ flip_y) * 8] & 0xF; + uint32_t *output = gb->screen + tile_x * 8 + x + (tile_y * 8 + y) * 256; + if (color == 0) { + *output = border_colors[0]; + } + else { + *output = border_colors[color + palette * 16]; + } + } + } } } } - gb->vblank_callback(gb); + if (gb->vblank_callback) { + gb->vblank_callback(gb); + } GB_timing_sync(gb); } @@ -184,19 +243,19 @@ static inline uint8_t scale_channel_with_curve_sgb(uint8_t x) } -uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color) +uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border) { uint8_t r = (color) & 0x1F; uint8_t g = (color >> 5) & 0x1F; uint8_t b = (color >> 10) & 0x1F; - if (gb->color_correction_mode == GB_COLOR_CORRECTION_DISABLED) { + if (gb->color_correction_mode == GB_COLOR_CORRECTION_DISABLED || (for_border && !gb->has_sgb_border)) { r = scale_channel(r); g = scale_channel(g); b = scale_channel(b); } else { - if (GB_is_sgb(gb)) { + if (GB_is_sgb(gb) || for_border) { return gb->rgb_encode_callback(gb, scale_channel_with_curve_sgb(r), scale_channel_with_curve_sgb(g), @@ -253,7 +312,7 @@ void GB_palette_changed(GB_gameboy_t *gb, bool background_palette, uint8_t index uint8_t *palette_data = background_palette? gb->background_palettes_data : gb->sprite_palettes_data; uint16_t color = palette_data[index & ~1] | (palette_data[index | 1] << 8); - (background_palette? gb->background_palettes_rgb : gb->sprite_palettes_rgb)[index / 2] = GB_convert_rgb15(gb, color); + (background_palette? gb->background_palettes_rgb : gb->sprite_palettes_rgb)[index / 2] = GB_convert_rgb15(gb, color, false); } void GB_set_color_correction_mode(GB_gameboy_t *gb, GB_color_correction_mode_t mode) @@ -393,7 +452,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } /* Drop pixels for scrollings */ - if (gb->position_in_line >= 160 || gb->disable_rendering) { + if (gb->position_in_line >= 160 || (gb->disable_rendering && !gb->sgb)) { gb->position_in_line++; return; } @@ -412,6 +471,16 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } uint8_t icd_pixel = 0; + uint32_t *dest = NULL; + if (!gb->sgb) { + if (gb->border_mode != GB_BORDER_ALWAYS) { + dest = gb->screen + gb->position_in_line + gb->current_line * WIDTH; + } + else { + dest = gb->screen + gb->position_in_line + gb->current_line * BORDERED_WIDTH + (BORDERED_WIDTH - WIDTH) / 2 + (BORDERED_HEIGHT - LINES) / 2 * BORDERED_WIDTH; + } + } + { uint8_t pixel = bg_enabled? fifo_item->pixel : 0; if (pixel && bg_priority) { @@ -431,7 +500,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } } else { - gb->screen[gb->position_in_line + gb->current_line * WIDTH] = gb->background_palettes_rgb[fifo_item->palette * 4 + pixel]; + *dest = gb->background_palettes_rgb[fifo_item->palette * 4 + pixel]; } } @@ -453,7 +522,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } } else { - gb->screen[gb->position_in_line + gb->current_line * WIDTH] = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel]; + *dest = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel]; } } diff --git a/Core/display.h b/Core/display.h index 9d1d1b4..69e7905 100644 --- a/Core/display.h +++ b/Core/display.h @@ -49,6 +49,6 @@ typedef enum { void GB_draw_tileset(GB_gameboy_t *gb, uint32_t *dest, GB_palette_type_t palette_type, uint8_t palette_index); void GB_draw_tilemap(GB_gameboy_t *gb, uint32_t *dest, GB_palette_type_t palette_type, uint8_t palette_index, GB_map_type_t map_type, GB_tileset_type_t tileset_type); uint8_t GB_get_oam_info(GB_gameboy_t *gb, GB_oam_info_t *dest, uint8_t *sprite_height); -uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color); +uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border); void GB_set_color_correction_mode(GB_gameboy_t *gb, GB_color_correction_mode_t mode); #endif /* display_h */ diff --git a/Core/gb.c b/Core/gb.c index 4a9525c..b0eaf68 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -99,6 +99,42 @@ static char *default_async_input_callback(GB_gameboy_t *gb) } #endif +static void load_default_border(GB_gameboy_t *gb) +{ + if (gb->has_sgb_border) return; + + #define LOAD_BORDER() do { \ + memcpy(gb->borrowed_border.map, tilemap, sizeof(tilemap));\ + memcpy(gb->borrowed_border.palette, palette, sizeof(palette));\ + \ + /* Expand tileset */\ + for (unsigned tile = 0; tile < sizeof(tiles) / 32; tile++) {\ + for (unsigned y = 0; y < 8; y++) {\ + for (unsigned x = 0; x < 8; x++) {\ + gb->borrowed_border.tiles[tile * 8 * 8 + y * 8 + x] =\ + (tiles[tile * 32 + y * 2 + 0] & (1 << (7 ^ x)) ? 1 : 0) |\ + (tiles[tile * 32 + y * 2 + 1] & (1 << (7 ^ x)) ? 2 : 0) |\ + (tiles[tile * 32 + y * 2 + 16] & (1 << (7 ^ x)) ? 4 : 0) |\ + (tiles[tile * 32 + y * 2 + 17] & (1 << (7 ^ x)) ? 8 : 0);\ + }\ + }\ + }\ + } while(false); + + if (gb->model == GB_MODEL_AGB) { + #include "graphics/agb_border.inc" + LOAD_BORDER(); + } + else if (GB_is_cgb(gb)) { + #include "graphics/cgb_border.inc" + LOAD_BORDER(); + } + else { + #include "graphics/dmg_border.inc" + LOAD_BORDER(); + } +} + void GB_init(GB_gameboy_t *gb, GB_model_t model) { memset(gb, 0, sizeof(*gb)); @@ -125,6 +161,7 @@ void GB_init(GB_gameboy_t *gb, GB_model_t model) } GB_reset(gb); + load_default_border(gb); } GB_model_t GB_get_model(GB_gameboy_t *gb) @@ -184,6 +221,46 @@ void GB_load_boot_rom_from_buffer(GB_gameboy_t *gb, const unsigned char *buffer, memcpy(gb->boot_rom, buffer, size); } +void GB_borrow_sgb_border(GB_gameboy_t *gb) +{ + if (GB_is_sgb(gb)) return; + if (gb->border_mode != GB_BORDER_ALWAYS) return; + if (gb->tried_loading_sgb_border) return; + gb->tried_loading_sgb_border = true; + if (gb->rom[0x146] != 3) return; // Not an SGB game, nothing to borrow + if (!gb->boot_rom_load_callback) return; // Can't borrow a border without this callback + GB_gameboy_t sgb; + GB_init(&sgb, GB_MODEL_SGB); + sgb.cartridge_type = gb->cartridge_type; + sgb.rom = gb->rom; + sgb.rom_size = gb->rom_size; + sgb.turbo = true; + sgb.turbo_dont_skip = true; + // sgb.disable_rendering = true; + + /* Load the boot ROM using the existing gb object */ + typeof(gb->boot_rom) boot_rom_backup; + memcpy(boot_rom_backup, gb->boot_rom, sizeof(gb->boot_rom)); + gb->boot_rom_load_callback(gb, GB_BOOT_ROM_SGB); + memcpy(sgb.boot_rom, gb->boot_rom, sizeof(gb->boot_rom)); + memcpy(gb->boot_rom, boot_rom_backup, sizeof(gb->boot_rom)); + sgb.sgb->intro_animation = -1; + + for (unsigned i = 600; i--;) { + GB_run_frame(&sgb); + if (sgb.sgb->border_animation) { + gb->has_sgb_border = true; + memcpy(&gb->borrowed_border, &sgb.sgb->pending_border, sizeof(gb->borrowed_border)); + gb->borrowed_border.palette[0] = sgb.sgb->effective_palettes[0]; + break; + } + } + + sgb.rom = NULL; + sgb.rom_size = 0; + GB_free(&sgb); +} + int GB_load_rom(GB_gameboy_t *gb, const char *path) { FILE *f = fopen(path, "rb"); @@ -199,6 +276,9 @@ int GB_load_rom(GB_gameboy_t *gb, const char *path) gb->rom_size |= gb->rom_size >> 1; gb->rom_size++; } + if (gb->rom_size == 0) { + gb->rom_size = 0x8000; + } fseek(f, 0, SEEK_SET); if (gb->rom) { free(gb->rom); @@ -208,7 +288,6 @@ int GB_load_rom(GB_gameboy_t *gb, const char *path) fread(gb->rom, 1, gb->rom_size, f); fclose(f); GB_configure_cart(gb); - return 0; } @@ -219,6 +298,9 @@ void GB_load_rom_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t siz gb->rom_size |= gb->rom_size >> 1; gb->rom_size++; } + if (gb->rom_size == 0) { + gb->rom_size = 0x8000; + } if (gb->rom) { free(gb->rom); } @@ -994,6 +1076,7 @@ void GB_switch_model_and_reset(GB_gameboy_t *gb, GB_model_t model) } GB_rewind_free(gb); GB_reset(gb); + load_default_border(gb); } void *GB_get_direct_access(GB_gameboy_t *gb, GB_direct_access_t access, size_t *size, uint16_t *bank) @@ -1079,14 +1162,36 @@ uint32_t GB_get_clock_rate(GB_gameboy_t *gb) return CPU_FREQUENCY * gb->clock_multiplier; } +void GB_set_border_mode(GB_gameboy_t *gb, GB_border_mode_t border_mode) +{ + if (gb->border_mode > GB_BORDER_ALWAYS) return; + gb->border_mode = border_mode; +} + unsigned GB_get_screen_width(GB_gameboy_t *gb) { - return GB_is_hle_sgb(gb)? 256 : 160; + switch (gb->border_mode) { + default: + case GB_BORDER_SGB: + return GB_is_hle_sgb(gb)? 256 : 160; + case GB_BORDER_NEVER: + return 160; + case GB_BORDER_ALWAYS: + return 256; + } } unsigned GB_get_screen_height(GB_gameboy_t *gb) { - return GB_is_hle_sgb(gb)? 224 : 144; + switch (gb->border_mode) { + default: + case GB_BORDER_SGB: + return GB_is_hle_sgb(gb)? 224 : 144; + case GB_BORDER_NEVER: + return 144; + case GB_BORDER_ALWAYS: + return 224; + } } unsigned GB_get_player_count(GB_gameboy_t *gb) diff --git a/Core/gb.h b/Core/gb.h index 487269f..e803f3c 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -112,6 +112,12 @@ enum { GB_ZERO_FLAG = 128, }; +typedef enum { + GB_BORDER_SGB, + GB_BORDER_NEVER, + GB_BORDER_ALWAYS, +} GB_border_mode_t; + #define GB_MAX_IR_QUEUE 256 enum { @@ -538,6 +544,10 @@ struct GB_gameboy_internal_s { const GB_palette_t *dmg_palette; GB_color_correction_mode_t color_correction_mode; bool keys[4][GB_KEY_MAX]; + GB_border_mode_t border_mode; + GB_sgb_border_t borrowed_border; + bool tried_loading_sgb_border; + bool has_sgb_border; /* Timing */ uint64_t last_sync; @@ -707,7 +717,8 @@ void GB_log(GB_gameboy_t *gb, const char *fmt, ...) __printflike(2, 3); void GB_attributed_log(GB_gameboy_t *gb, GB_log_attributes attributes, const char *fmt, ...) __printflike(3, 4); void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output); - +void GB_set_border_mode(GB_gameboy_t *gb, GB_border_mode_t border_mode); + void GB_set_infrared_input(GB_gameboy_t *gb, bool state); void GB_queue_infrared_input(GB_gameboy_t *gb, bool state, long cycles_after_previous_change); /* In 8MHz units*/ diff --git a/Core/graphics/agb_border.inc b/Core/graphics/agb_border.inc new file mode 100644 index 0000000..dd4ebbe --- /dev/null +++ b/Core/graphics/agb_border.inc @@ -0,0 +1,522 @@ +static const uint16_t palette[] = { + 0x410A, 0x0421, 0x35AD, 0x4A52, 0x7FFF, 0x2D49, 0x0C42, 0x1484, + 0x18A5, 0x20C6, 0x6718, 0x5D6E, 0x0000, 0x0000, 0x0000, 0x0000, +}; + +static const uint16_t tilemap[] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0001, 0x0002, 0x0003, 0x0003, 0x0003, 0x0004, 0x0004, + 0x0004, 0x0004, 0x0004, 0x0004, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0004, 0x0004, 0x0004, 0x0004, + 0x0004, 0x0004, 0x0003, 0x0003, 0x0003, 0x4002, 0x4001, 0x0000, + 0x0000, 0x0006, 0x0007, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, + 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, + 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, + 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x4007, 0x4006, 0x0000, + 0x0000, 0x0009, 0x0008, 0x0008, 0x0008, 0x000A, 0x000B, 0x000B, + 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, + 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, 0x000B, + 0x000B, 0x000B, 0x400A, 0x0008, 0x0008, 0x0008, 0xC009, 0x0000, + 0x0000, 0x000C, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x400C, 0x0000, + 0x0000, 0x000E, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC00E, 0x0000, + 0x0000, 0x000F, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x400F, 0x0000, + 0x0000, 0x0010, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC010, 0x0000, + 0x0000, 0x0010, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC010, 0x0000, + 0x0000, 0x0011, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC011, 0x0000, + 0x0000, 0x0011, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC011, 0x0000, + 0x0000, 0x0012, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x4012, 0x0000, + 0x0000, 0x0013, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC013, 0x0000, + 0x0014, 0x0015, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x4015, 0x4014, + 0x0016, 0x0017, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC017, 0xC016, + 0x0016, 0x0017, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC017, 0xC016, + 0x0018, 0x0019, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x4019, 0x4018, + 0x001A, 0x001B, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0xC01B, 0xC01A, + 0x001C, 0x001D, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x401D, 0x401C, + 0x001E, 0x0008, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x0008, 0xC01E, + 0x001E, 0x0008, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x0008, 0xC01E, + 0x001E, 0x0008, 0x0008, 0x0008, 0x0008, 0x000D, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC00D, 0x0008, 0x0008, 0x0008, 0x0008, 0xC01E, + 0x001F, 0x801D, 0x0008, 0x0008, 0x0008, 0x0020, 0x0021, 0x0022, + 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, + 0x002B, 0x002C, 0x002D, 0x002D, 0x002D, 0x002D, 0x002D, 0x002D, + 0x002E, 0x0021, 0x4020, 0x0008, 0x0008, 0x0008, 0xC01D, 0x401F, + 0x002F, 0x0030, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0031, + 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, + 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, + 0x0042, 0x0043, 0x0008, 0x0008, 0x0008, 0x0008, 0x4030, 0x402F, + 0x0044, 0x0045, 0x0046, 0x0047, 0x0008, 0x0008, 0x0048, 0x0049, + 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, + 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, + 0x005A, 0x005B, 0x0008, 0x0008, 0x4047, 0x4046, 0x4045, 0x4044, + 0x0000, 0x0000, 0x005C, 0x005D, 0x005E, 0x005F, 0x0060, 0x0061, + 0x0061, 0x0062, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, + 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x4062, 0x0061, + 0x0061, 0x4060, 0x405F, 0x405E, 0x405D, 0x405C, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, +}; + +const uint8_t tiles[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1F, 0x01, + 0x7F, 0x1F, 0xFF, 0x7E, 0xFF, 0xE1, 0xFF, 0x9F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x1E, + 0x1F, 0x60, 0x7F, 0x80, 0xFF, 0x00, 0xBF, 0x40, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x03, 0x01, 0x07, 0x03, 0x07, 0x03, 0x07, 0x06, + 0x07, 0x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F, 0x6F, 0x7F, 0x6F, + 0x6F, 0x10, 0x6F, 0x10, 0x6F, 0x10, 0x6F, 0x10, + 0x6F, 0x10, 0x6F, 0x10, 0x6F, 0x10, 0x6F, 0x10, + 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0xFF, 0xDF, + 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, + 0x6F, 0x10, 0x6F, 0x10, 0x6F, 0x10, 0xDF, 0x20, + 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, + 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, + 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, + 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, + 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xDF, + 0xFF, 0xDF, 0xFF, 0xDF, 0xFF, 0xBF, 0xFF, 0xBF, + 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, 0xDF, 0x20, + 0xDF, 0x20, 0xDF, 0x20, 0xBF, 0x40, 0xBF, 0x40, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, + 0xFF, 0xBF, 0xFF, 0xBF, 0xFF, 0xBF, 0xFF, 0xBF, + 0xFF, 0xBF, 0xFF, 0xBF, 0xFF, 0xBF, 0xFF, 0xBF, + 0xBF, 0x40, 0xBF, 0x40, 0xBF, 0x40, 0xBF, 0x40, + 0xBF, 0x40, 0xBF, 0x40, 0xBF, 0x40, 0xBF, 0x40, + 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0xFF, 0xBF, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, + 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, + 0xBF, 0x40, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, + 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, + 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, + 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, + 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, + 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, + 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, + 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, + 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, + 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, 0x06, 0x01, + 0x03, 0x04, 0x03, 0x04, 0x03, 0x04, 0x03, 0x04, + 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFE, 0x01, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xF8, 0xFF, 0xE7, 0xF8, 0xDF, 0xE3, + 0x00, 0xFF, 0xFF, 0x00, 0x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 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xFF, + 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, + 0x03, 0x04, 0x03, 0x04, 0x03, 0x04, 0x03, 0x04, + 0x03, 0x04, 0x01, 0x02, 0x01, 0x02, 0x00, 0x01, + 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, + 0xFF, 0x7F, 0xFF, 0xBF, 0xFF, 0xBF, 0xFF, 0xDF, + 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, + 0x7F, 0x80, 0xBF, 0x40, 0xBF, 0x40, 0xDF, 0x20, + 0xB0, 0xD8, 0xA0, 0xD3, 0x67, 0x84, 0x47, 0xA4, + 0x61, 0x81, 0xA0, 0xD0, 0xB4, 0xCA, 0x7E, 0x81, + 0xD7, 0x08, 0xCC, 0x13, 0x98, 0x20, 0x98, 0x00, + 0x9E, 0x20, 0xCF, 0x00, 0xCD, 0x02, 0x80, 0x01, + 0x32, 0x2D, 0x13, 0x6D, 0x34, 0x48, 0xFC, 0x02, + 0x7C, 0x00, 0x78, 0x05, 0x30, 0x49, 0x20, 0x50, + 0xCD, 0x00, 0xAC, 0x40, 0x49, 0x82, 0x01, 0x02, + 0x07, 0x80, 0xC2, 0x05, 0x86, 0x41, 0x9F, 0x40, + 0x15, 0x2E, 0x09, 0x06, 0x09, 0x16, 0x0B, 0xD4, + 0xC6, 0x49, 0x8E, 0x40, 0xCF, 0xC8, 0x06, 0x01, + 0xCE, 0x20, 0xE6, 0x10, 0xE6, 0x00, 0x24, 0xD0, + 0x39, 0x80, 0x38, 0x01, 0x31, 0x00, 0xF8, 0x00, + 0x0C, 0x8B, 0x85, 0x8A, 0x03, 0x84, 0x27, 0x20, + 0x22, 0x35, 0x12, 0x34, 0x20, 0x12, 0x10, 0x20, + 0x73, 0x00, 0x72, 0x08, 0x7C, 0x80, 0xDC, 0x01, + 0xC8, 0x11, 0xC9, 0x06, 0xCD, 0x22, 0xEF, 0x10, + 0x83, 0x44, 0x86, 0x01, 0x03, 0x85, 0x26, 0x21, + 0x46, 0x69, 0x46, 0x68, 0x8E, 0xCA, 0x86, 0x88, + 0x39, 0x40, 0x78, 0x84, 0x7C, 0x80, 0xD8, 0x01, + 0x90, 0x29, 0xD1, 0x28, 0x73, 0x00, 0xB3, 0x40, + 0x00, 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x40, + 0x03, 0x02, 0x01, 0x02, 0x41, 0x7C, 0x7F, 0x00, + 0xFE, 0x00, 0xFF, 0x00, 0xC0, 0x00, 0x80, 0x40, + 0xFC, 0x00, 0xFC, 0x00, 0x80, 0x02, 0xC0, 0x00, + 0xC0, 0x00, 0x80, 0x4C, 0xCC, 0x43, 0x8E, 0x52, + 0x80, 0x4C, 0x80, 0x00, 0x12, 0x1E, 0x9E, 0x00, + 0x7F, 0x00, 0x33, 0x0C, 0x32, 0x01, 0x23, 0x50, + 0x33, 0x4C, 0x7F, 0x00, 0x61, 0x80, 0xF1, 0x00, + 0x7C, 0x02, 0x30, 0x48, 0x31, 0x40, 0x61, 0x50, + 0x87, 0xE4, 0xE3, 0x84, 0x23, 0x44, 0x43, 0x44, + 0x85, 0x42, 0x87, 0x40, 0x8F, 0x50, 0x8C, 0x12, + 0x78, 0x00, 0x18, 0x20, 0xB8, 0x00, 0x98, 0x24, + 0x03, 0x04, 0x03, 0xE0, 0xF1, 0x12, 0xF0, 0x09, + 0xF9, 0x09, 0xF9, 0x08, 0xE1, 0x12, 0xF1, 0x12, + 0xF8, 0x00, 0x1E, 0xE0, 0x0C, 0x02, 0x07, 0x08, + 0x07, 0x00, 0x06, 0x00, 0x1C, 0x02, 0x0C, 0x00, + 0x9F, 0x91, 0x86, 0x88, 0xC4, 0x4C, 0x80, 0x4C, + 0xE1, 0x20, 0xC1, 0x22, 0x23, 0xD4, 0x22, 0xD5, + 0x60, 0x00, 0xFB, 0x00, 0x37, 0x00, 0x73, 0x0C, + 0x1F, 0x00, 0x3C, 0x00, 0xC8, 0x14, 0xC9, 0x14, + 0x16, 0x2F, 0x76, 0x4F, 0x2D, 0xDE, 0xDD, 0xBE, + 0xBA, 0x7D, 0x7A, 0xFD, 0x7A, 0xFD, 0xF4, 0xF8, + 0xCF, 0x00, 0x8F, 0x00, 0x5E, 0x80, 0xBE, 0x00, + 0x7D, 0x00, 0xFC, 0x00, 0xFC, 0x01, 0xF9, 0x02, + 0xFF, 0x00, 0xBF, 0x78, 0x86, 0x09, 0x86, 0x89, + 0x06, 0x25, 0x02, 0x25, 0x42, 0x45, 0x60, 0x11, + 0x00, 0x00, 0x09, 0x00, 0x70, 0x81, 0x70, 0x09, + 0xDC, 0x21, 0xD8, 0x01, 0x98, 0x25, 0xCC, 0x13, + 0xFF, 0x00, 0xF3, 0xF8, 0x02, 0x03, 0x01, 0x30, + 0x39, 0x09, 0x30, 0x09, 0x31, 0x09, 0x20, 0x19, + 0x00, 0x00, 0x01, 0x04, 0xFC, 0x00, 0xCF, 0x30, + 0xE6, 0x00, 0xE6, 0x01, 0xE6, 0x00, 0xF6, 0x08, + 0xFF, 0x00, 0xFA, 0xC7, 0x18, 0x21, 0x09, 0x10, + 0x88, 0x99, 0x93, 0x1A, 0x83, 0x11, 0xC2, 0x41, + 0x00, 0x00, 0x00, 0x20, 0xC6, 0x21, 0xFF, 0x00, + 0x67, 0x00, 0xE4, 0x08, 0x6F, 0x10, 0x3C, 0x00, + 0xFD, 0x02, 0xB5, 0x3A, 0xC7, 0x44, 0x03, 0x84, + 0x83, 0x24, 0x21, 0xB0, 0x21, 0x12, 0x21, 0x02, + 0x02, 0x00, 0x02, 0x40, 0x3C, 0x00, 0xF8, 0x00, + 0xD8, 0x24, 0x4C, 0x92, 0xEC, 0x00, 0xCC, 0x12, + 0xFF, 0x00, 0xFF, 0xF3, 0x1C, 0x14, 0x0C, 0x04, + 0x00, 0x0C, 0x04, 0x24, 0x00, 0x24, 0x10, 0x30, + 0x00, 0x00, 0x10, 0x04, 0xE3, 0x00, 0xFB, 0x00, + 0xF3, 0x08, 0xDB, 0x20, 0xDB, 0x04, 0xCF, 0x00, + 0xFF, 0x00, 0xEC, 0x3E, 0xC1, 0x01, 0x01, 0x8E, + 0x8F, 0x10, 0x0F, 0x90, 0x0F, 0x90, 0x0D, 0x09, + 0x00, 0x00, 0x20, 0x01, 0x7E, 0x00, 0xF1, 0x0E, + 0xE0, 0x10, 0x60, 0x10, 0x60, 0x10, 0x79, 0x82, + 0xFF, 0x00, 0x7F, 0xFC, 0x03, 0x82, 0x01, 0x9E, + 0x13, 0x80, 0x03, 0x80, 0x03, 0x9C, 0x0F, 0x90, + 0x00, 0x00, 0x02, 0x00, 0x7C, 0x80, 0x60, 0x9C, + 0x60, 0x9C, 0x7C, 0x80, 0x60, 0x9C, 0x70, 0x80, + 0xFF, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, + 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xEF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xD8, 0x20, 0x1D, 0xA0, 0x03, 0x00, + 0x07, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xC7, 0xE1, 0xE6, 0x05, 0x42, 0xA5, 0xBF, 0xC0, + 0x9F, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x18, 0x24, 0x38, 0x01, 0xB8, 0x05, 0xC0, 0x00, + 0xE0, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x21, 0x11, 0x31, 0x49, 0x33, 0x4A, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xDE, 0x00, 0x87, 0x48, 0x84, 0x48, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xCC, 0x02, 0x8E, 0x4A, 0xCC, 0x42, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x71, 0x08, 0x39, 0x00, 0x31, 0x02, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x3D, 0x40, 0x03, 0x02, 0x03, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0x02, 0xFC, 0x00, 0xFE, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x12, 0x82, 0x80, 0x80, 0x01, 0x83, 0xFF, 0x00, + 0xFE, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x61, 0x1C, 0x7F, 0x00, 0x7C, 0x82, 0x00, 0x00, + 0x01, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x22, 0x52, 0x30, 0xC0, 0x58, 0xA4, 0x8F, 0x72, + 0x73, 0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FF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x3F, 0x3F, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x3C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFE, 0xFF, 0xFF, 0x3F, 0x3F, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFE, 0x01, 0x3F, 0xC0, 0x01, 0x3E, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0x3F, 0xFF, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, + 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3F, 0xC0, 0xC0, 0x3F, 0xFF, 0x00, 0x3F, 0xC0, + 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xC0, 0xFF, 0xFF, + 0xFF, 0xFF, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0x00, 0x3F, 0xC0, 0xC0, 0x3F, 0xFF, 0x00, + 0x3F, 0xC0, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0xFC, + 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x00, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0x03, 0xFC, 0xFC, 0x03, + 0xFF, 0x00, 0x03, 0xFC, 0x00, 0x03, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, + 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x03, 0xFC, + 0xFC, 0x03, 0xFF, 0x00, 0x03, 0xFC, 0x00, 0x03, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, +}; diff --git a/Core/graphics/cgb_border.inc b/Core/graphics/cgb_border.inc new file mode 100644 index 0000000..755312a --- /dev/null +++ b/Core/graphics/cgb_border.inc @@ -0,0 +1,446 @@ +static const uint16_t palette[] = { + 0x7C1A, 0x0000, 0x0011, 0x3DEF, 0x6318, 0x7FFF, 0x1EBA, 0x19AF, + 0x1EAF, 0x4648, 0x7FC0, 0x2507, 0x1484, 0x5129, 0x5010, 0x2095, +}; + +static const uint16_t tilemap[] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0001, 0x0002, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, + 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, + 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, + 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x4002, 0x4001, 0x0000, + 0x0000, 0x0004, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x4004, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0007, 0x0008, 0x0008, + 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, + 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, + 0x0008, 0x0008, 0x4007, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x000A, 0x000B, 0x400A, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x800A, 0x000C, 0xC00A, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x0006, 0x0005, 0x0005, 0x0005, 0x0009, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC009, 0x0005, 0x0005, 0x0005, 0xC006, 0x0000, + 0x0000, 0x000D, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x000E, + 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, + 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, + 0x001F, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x400D, 0x0000, + 0x0000, 0x0020, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0021, + 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, + 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, + 0x0032, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x4020, 0x0000, + 0x0000, 0x0033, 0x0034, 0x0035, 0x0036, 0x0005, 0x0005, 0x0037, + 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, + 0x0040, 0x0005, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, + 0x0047, 0x0005, 0x0005, 0x4036, 0x4035, 0x4034, 0x4033, 0x0000, + 0x0000, 0x0000, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, + 0x004E, 0x004E, 0x004F, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, + 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x404F, 0x004E, 0x004E, + 0x404D, 0x004C, 0x404B, 0x404A, 0x4049, 0x4048, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +const uint8_t tiles[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, + 0x01, 0x11, 0x06, 0x26, 0x04, 0x24, 0x08, 0x48, + 0x00, 0x00, 0x01, 0x01, 0x07, 0x07, 0x0F, 0x0F, + 0x1E, 0x1F, 0x39, 0x3F, 0x3B, 0x3F, 0x77, 0x7F, + 0x00, 0x7F, 0x00, 0x80, 0x00, 0x00, 0x7F, 0x7F, + 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0xFF, + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x08, 0x48, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x77, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, + 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, + 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, + 0xBD, 0xBD, 0x7E, 0x66, 0x7E, 0xFF, 0x7E, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, 0xFF, + 0x7E, 0xFF, 0xFF, 0xE7, 0x7E, 0x7E, 0x7E, 0x7E, + 0x7E, 0xFF, 0x3C, 0xFF, 0x81, 0xFF, 0xC3, 0xFF, + 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x7E, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x81, + 0x81, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x08, 0x48, 0x08, 0x48, 0x08, 0x48, 0x08, 0x48, + 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, 0x6F, 0x7F, + 0x37, 0x7F, 0x37, 0x7F, 0x37, 0x7F, 0x37, 0x7F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFE, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x9F, 0x3F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x70, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0xDF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x78, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x87, 0xC7, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3C, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0xE3, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9F, 0x9F, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0xE1, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0xD8, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x27, 0x8F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x70, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x8F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x70, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x9F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC2, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBD, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x3F, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xE0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x84, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x7F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x08, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xFF, + 0x08, 0x48, 0x08, 0x48, 0x08, 0x48, 0x08, 0x48, + 0x08, 0x48, 0x04, 0x24, 0x04, 0x24, 0x02, 0x12, + 0x37, 0x7F, 0x37, 0x7F, 0x37, 0x7F, 0x37, 0x7F, + 0x37, 0x7F, 0x1B, 0x3F, 0x1B, 0x3F, 0x0D, 0x1F, + 0x0F, 0x08, 0x0E, 0x00, 0x1E, 0x12, 0x1E, 0x12, + 0x1F, 0x10, 0x0F, 0x08, 0x02, 0x02, 0x00, 0x00, + 0xF7, 0xF8, 0xFF, 0xF0, 0xED, 0xE3, 0xED, 0xE1, + 0xEF, 0xE0, 0xF7, 0xF0, 0xFD, 0xFC, 0xFF, 0xFF, + 0xF0, 0x10, 0x40, 0x00, 0x41, 0x41, 0x00, 0x00, + 0x83, 0x82, 0xE3, 0x20, 0xC7, 0x04, 0xC7, 0x00, + 0xEF, 0x1F, 0xFF, 0x1F, 0xBE, 0xFF, 0xFF, 0xFE, + 0x7D, 0x7E, 0xDF, 0x3C, 0xFB, 0x18, 0xFF, 0x18, + 0x60, 0x00, 0x70, 0x00, 0xF8, 0x08, 0xB0, 0x00, + 0xD8, 0x40, 0x3C, 0x24, 0x5C, 0x44, 0xFC, 0x00, + 0xFF, 0x8F, 0xFF, 0x0F, 0xF7, 0x07, 0xFF, 0x07, + 0xBF, 0x47, 0xDB, 0x47, 0xBB, 0x03, 0xFF, 0x03, + 0x3C, 0x04, 0x78, 0x00, 0x78, 0x00, 0xEC, 0x80, + 0xFE, 0x92, 0xE7, 0x83, 0xE5, 0x80, 0x4F, 0x08, + 0xFB, 0x83, 0xFF, 0x83, 0xFF, 0x83, 0x7F, 0x83, + 0x6D, 0x93, 0x7C, 0x10, 0x7F, 0x10, 0xF7, 0x10, + 0x3C, 0x00, 0x7C, 0x40, 0x78, 0x00, 0xC8, 0x80, + 0xFC, 0x24, 0xBC, 0x24, 0xFD, 0x65, 0x3D, 0x25, + 0xFF, 0xC3, 0xBF, 0x83, 0xFF, 0x83, 0x7F, 0x03, + 0xDB, 0x23, 0xDB, 0x23, 0x9A, 0x67, 0xDA, 0x47, + 0xFF, 0x80, 0xFF, 0x80, 0xE0, 0x80, 0x40, 0x00, + 0xFF, 0x01, 0xFF, 0x01, 0xDF, 0x1F, 0xE0, 0x20, + 0x7F, 0x80, 0x7F, 0x00, 0x7F, 0x1F, 0xFF, 0x1F, + 0xFE, 0x00, 0xFE, 0x00, 0xE0, 0x01, 0xDF, 0x3F, + 0xBF, 0xA0, 0xB9, 0xA0, 0x10, 0x00, 0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, 0x12, + 0x3E, 0x22, 0xFC, 0x00, 0xF8, 0x08, 0xF0, 0x10, + 0x03, 0xFF, 0x01, 0xFF, 0xE1, 0xFF, 0xE1, 0xFF, + 0xC1, 0xFF, 0x03, 0xFF, 0x07, 0xFF, 0x0F, 0xFF, + 0x01, 0x11, 0x00, 0x08, 0x00, 0x04, 0x00, 0x02, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x1F, 0x07, 0x0F, 0x03, 0x07, 0x01, 0x03, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x30, 0x30, + 0x0C, 0x0C, 0x03, 0xC3, 0x00, 0x30, 0x00, 0x0C, + 0xFF, 0xFF, 0x7F, 0xFF, 0xBF, 0xFF, 0xCF, 0xFF, + 0xF3, 0xFF, 0x3C, 0xFF, 0x0F, 0x3F, 0x03, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xC0, 0xC0, 0x3C, 0x3C, 0x03, 0x03, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x3F, 0xFF, 0xC3, 0xFF, 0xFC, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xFF, + 0x15, 0x15, 0x3F, 0x20, 0x2F, 0x20, 0x06, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xEA, 0xE6, 0xDF, 0xC0, 0xDF, 0xE0, 0xF9, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xE6, 0x20, 0x9E, 0x12, 0x0C, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xDF, 0x30, 0xED, 0x31, 0xFF, 0x63, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x0E, 0x02, 0x1E, 0x12, 0x0D, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFD, 0x03, 0xED, 0xE1, 0xFE, 0xF1, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x4F, 0x08, 0xE6, 0x20, 0xE7, 0x21, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF7, 0x18, 0xDF, 0x18, 0xDE, 0x18, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xB9, 0xA1, 0x11, 0x01, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5E, 0x46, 0xFE, 0xC6, 0xFF, 0xC6, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x3F, 0xFF, 0x01, 0xFF, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xC0, 0x01, 0xFE, 0x00, 0xFE, 0x00, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x7E, 0x4E, 0x3F, 0x00, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xB1, 0x8E, 0xF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, 0x00, 0x81, 0x81, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0xFD, 0xF4, 0xFF, 0xFC, 0xFF, 0x7E, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x7D, 0x7D, 0x02, 0x02, 0x02, 0x02, 0xFC, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xFE, 0x01, 0xFF, 0x01, 0xFF, 0x03, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x1C, 0xFF, 0x00, 0xFF, 0x41, 0x7F, 0x18, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF7, 0x08, 0xFF, 0x00, 0xFF, 0x80, 0xE7, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x5E, 0xC2, 0x9C, 0x80, 0x1C, 0x04, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE1, 0x3F, 0xE3, 0x7F, 0xE3, 0xFF, 0xF7, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xF0, 0x80, 0x78, 0x08, 0x78, 0x48, 0x10, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0xFF, 0x87, 0xFF, 0x87, 0xFF, 0xEF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xC0, 0x00, 0x3C, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3F, 0xFF, 0x03, 0x3F, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1C, 0x1C, 0x03, 0x03, 0x00, 0xE0, 0x00, 0x1C, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xE3, 0xFF, 0xFC, 0xFF, 0x1F, 0xFF, 0x03, 0x1F, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFC, 0xFC, 0x03, 0x03, 0x00, 0x00, + 0x00, 0xFC, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, + 0x03, 0xFF, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x3F, 0x3F, + 0x00, 0x00, 0x00, 0xC0, 0x00, 0x3F, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xC0, 0xFF, + 0xFF, 0xFF, 0x3F, 0xFF, 0x00, 0x3F, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, + 0x3F, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x3F, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, + 0xC0, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0x00, 0x3F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF +}; diff --git a/Core/graphics/dmg_border.inc b/Core/graphics/dmg_border.inc new file mode 100644 index 0000000..7db0673 --- /dev/null +++ b/Core/graphics/dmg_border.inc @@ -0,0 +1,558 @@ +static const uint16_t palette[] = { + 0x0000, 0x0011, 0x18C6, 0x001A, 0x318C, 0x39CE, 0x5294, 0x5AD6, + 0x739C, 0x45A8, 0x4520, 0x18A5, 0x4A32, 0x2033, 0x20EC, 0x0000, +}; + +static const uint16_t tilemap[] = { + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, + 0x0001, 0x0003, 0x0004, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x4004, 0x4003, 0x0001, + 0x0001, 0x0006, 0x0007, 0x0007, 0x0007, 0x0008, 0x0009, 0x000A, + 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, + 0x0013, 0x0014, 0x0015, 0x000E, 0x0016, 0x0017, 0x0018, 0x0019, + 0x001A, 0x001B, 0x001C, 0x0007, 0x0007, 0x0007, 0x4006, 0x0001, + 0x0001, 0x001D, 0x001E, 0x001E, 0x001E, 0x001F, 0x0020, 0x0021, + 0x0022, 0x0023, 0x0024, 0x0025, 0x4024, 0x0026, 0x0025, 0x0025, + 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, + 0x002F, 0x0030, 0x0031, 0x001E, 0x001E, 0x001E, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0034, 0x0035, 0x4034, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x8034, 0x0036, 0xC034, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0xC01D, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0x0037, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0032, 0x0038, 0x0001, + 0x0001, 0x001D, 0x0032, 0x0032, 0x0032, 0x0033, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0xC033, 0x0032, 0x0032, 0x0039, 0x003A, 0x0001, + 0x0001, 0x003B, 0x003C, 0x0032, 0x0032, 0xC03C, 0x003D, 0x003D, + 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, + 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, 0x003D, + 0x003D, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0001, 0x0001, + 0x0001, 0x0042, 0x0043, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, + 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, + 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, 0x0044, + 0x0044, 0x0044, 0x0045, 0x0046, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, + 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, + 0x005C, 0x005D, 0x005E, 0x005F, 0x0060, 0x0061, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, + 0x0068, 0x0069, 0x006A, 0x006B, 0x0001, 0x006C, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, +}; + +const uint8_t tiles[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0xFF, 0x01, 0xFE, 0x06, 0xF9, 0x08, 0xF7, + 0x11, 0xEF, 0x22, 0xDB, 0x20, 0xDB, 0x40, 0xB7, + 0xFF, 0x00, 0xFF, 0x00, 0xFE, 0x00, 0xF8, 0x00, + 0xF1, 0x00, 0xE6, 0x04, 0xE4, 0x00, 0xC8, 0x00, + 0x7F, 0x80, 0x80, 0x7F, 0x00, 0xFF, 0x7F, 0xFF, + 0x80, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0x80, 0x00, 0x00, 0x00, 0x7F, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0xB7, 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, + 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, + 0xC8, 0x00, 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, + 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x03, 0xFF, 0x02, 0xFF, + 0x02, 0xFF, 0x02, 0xFF, 0x02, 0xFF, 0x02, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, + 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0xC1, 0xDD, 0x00, 0xC9, + 0x14, 0xFF, 0x14, 0xFF, 0x14, 0xFF, 0x00, 0xC9, + 0x00, 0x00, 0x00, 0x00, 0xE3, 0x00, 0x36, 0x22, + 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x36, 0x22, + 0x00, 0xFF, 0x00, 0xFF, 0xC7, 0xDF, 0x01, 0xCF, + 0x11, 0xFF, 0x11, 0xFF, 0x11, 0xFF, 0x01, 0xCF, + 0x00, 0x00, 0x00, 0x00, 0xE7, 0x00, 0x31, 0x20, + 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x31, 0x20, + 0x00, 0xFF, 0x00, 0xFF, 0xC2, 0xFF, 0x03, 0xFF, + 0x02, 0xFE, 0x02, 0xFE, 0x02, 0xFF, 0x02, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0xC2, 0x00, 0x03, 0x00, + 0x03, 0x01, 0x03, 0x00, 0x02, 0x00, 0x02, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x08, 0xFF, 0x18, 0xFF, + 0x08, 0x4E, 0x08, 0x4E, 0x09, 0x1F, 0x08, 0x1C, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x18, 0x00, + 0xB9, 0x10, 0xB9, 0xA1, 0xE9, 0xA0, 0xEB, 0x41, + 0x00, 0xFF, 0x00, 0xFF, 0x4F, 0xFF, 0x02, 0x1F, + 0x02, 0x4F, 0x02, 0x4F, 0xF2, 0xFF, 0x02, 0xE7, + 0x00, 0x00, 0x00, 0x00, 0x4F, 0x00, 0xE2, 0xA0, + 0xB2, 0xA0, 0xB2, 0x10, 0xF2, 0x00, 0x1A, 0x10, + 0x00, 0xFF, 0x00, 0xFF, 0xBC, 0xFD, 0x22, 0xFB, + 0x22, 0xFB, 0x3C, 0xFD, 0x24, 0xFF, 0x26, 0xF9, + 0x00, 0x00, 0x00, 0x00, 0xBE, 0x00, 0x26, 0x00, + 0x26, 0x00, 0x3E, 0x00, 0x24, 0x00, 0x26, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x50, 0xFF, 0x49, 0xEF, + 0x49, 0xF0, 0x46, 0xFF, 0x49, 0xF0, 0x49, 0xEF, + 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x59, 0x00, + 0x4F, 0x06, 0x46, 0x00, 0x4F, 0x06, 0x59, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x88, 0xFF, 0x00, 0x72, + 0x00, 0xF2, 0x05, 0xFF, 0x00, 0xF8, 0x00, 0x78, + 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x8D, 0x08, + 0x0D, 0x05, 0x05, 0x00, 0x07, 0x05, 0x87, 0x02, + 0x00, 0xFF, 0x00, 0xFF, 0x8A, 0xFF, 0x02, 0x27, + 0x02, 0x27, 0x52, 0xFF, 0x02, 0x8F, 0x02, 0x8F, + 0x00, 0x00, 0x00, 0x00, 0x8A, 0x00, 0xDA, 0x88, + 0xDA, 0x50, 0x52, 0x00, 0x72, 0x50, 0x72, 0x20, + 0x00, 0xFF, 0x00, 0xFF, 0xFA, 0xFF, 0x22, 0xFF, + 0x22, 0xFF, 0x23, 0xFF, 0x22, 0xFF, 0x22, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0xFA, 0x00, 0x22, 0x00, + 0x22, 0x00, 0x23, 0x00, 0x22, 0x00, 0x22, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x20, 0xFF, 0x20, 0xFF, + 0x20, 0xFF, 0xE0, 0xFF, 0x20, 0xFF, 0x20, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, + 0x20, 0x00, 0xE0, 0x00, 0x20, 0x00, 0x20, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x33, 0x37, 0x00, 0x77, + 0x80, 0xFF, 0x20, 0x27, 0x08, 0xFF, 0x00, 0x77, + 0x00, 0x00, 0x00, 0x00, 0xFB, 0x40, 0x88, 0x88, + 0x80, 0x00, 0xF8, 0x50, 0x08, 0x00, 0x88, 0x88, + 0x00, 0xFF, 0x00, 0xFF, 0xEF, 0xFF, 0x88, 0xFF, + 0x88, 0xFF, 0x8F, 0xFF, 0x88, 0xFF, 0x88, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0xEF, 0x00, 0x88, 0x00, + 0x88, 0x00, 0x8F, 0x00, 0x88, 0x00, 0x88, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0xF9, 0xFD, 0x80, 0xF9, + 0x84, 0xFF, 0xF4, 0xFF, 0x84, 0xFF, 0x80, 0xF9, + 0x00, 0x00, 0x00, 0x00, 0xFB, 0x00, 0x86, 0x02, + 0x84, 0x00, 0xF4, 0x00, 0x84, 0x00, 0x86, 0x02, + 0x00, 0xFF, 0x00, 0xFF, 0xC0, 0xDF, 0x00, 0xCF, + 0x10, 0xFF, 0x10, 0xFF, 0x10, 0xFF, 0x00, 0xCF, + 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x30, 0x20, + 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x30, 0x20, + 0x00, 0xFF, 0x00, 0xFF, 0x30, 0x36, 0x00, 0x74, + 0x82, 0xFF, 0x22, 0x27, 0x0A, 0xFF, 0x00, 0x74, + 0x00, 0x00, 0x00, 0x00, 0xF9, 0x40, 0x8B, 0x89, + 0x82, 0x00, 0xFA, 0x50, 0x0A, 0x00, 0x8B, 0x89, + 0x00, 0xFF, 0x00, 0xFF, 0xE2, 0xEF, 0x02, 0xE7, + 0x0A, 0xFF, 0x0A, 0xFF, 0x0A, 0xFF, 0x00, 0xE4, + 0x00, 0x00, 0x00, 0x00, 0xF2, 0x00, 0x1A, 0x10, + 0x0A, 0x00, 0x0A, 0x00, 0x0A, 0x00, 0x1B, 0x12, + 0x00, 0xFF, 0x00, 0xFF, 0x14, 0xFF, 0x16, 0xFF, + 0x14, 0xFC, 0x15, 0xFE, 0x14, 0xFF, 0x04, 0xCF, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x16, 0x00, + 0x17, 0x01, 0x15, 0x00, 0x14, 0x00, 0x34, 0x10, + 0x00, 0xFF, 0x00, 0xFF, 0x2F, 0xFF, 0x28, 0xFF, + 0x28, 0xFF, 0xA8, 0x7F, 0x28, 0x3F, 0x68, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x28, 0x00, + 0x28, 0x00, 0xA8, 0x00, 0xE8, 0x80, 0x68, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0x3F, + 0x40, 0xFF, 0x40, 0xFF, 0x40, 0xFF, 0x00, 0x3F, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xC0, 0x80, + 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0xC0, 0x80, + 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, + 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, + 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, + 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0xFF, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0xC1, 0xDD, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xC1, 0xDF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x02, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x4A, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x0A, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x22, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x82, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x20, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x60, 0x67, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xF8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x8F, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xA2, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xF9, 0xFD, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xC0, 0xDF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x60, 0x66, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xF9, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xE0, 0xEE, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xF1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xC4, 0xDF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0xE4, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x2F, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, + 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x00, 0x7F, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x80, 0xFF, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, + 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x3C, 0xFF, + 0x7E, 0xFF, 0xE7, 0xE7, 0xFF, 0x7E, 0xFF, 0x7E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x7E, + 0x81, 0xC3, 0x00, 0x99, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0x7E, 0xFF, 0x3C, 0xFF, 0x00, 0x7E, 0x81, + 0x3C, 0xC3, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0xC3, 0x81, + 0x7E, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xF7, 0x00, 0xF7, 0x00, 0xF7, 0x00, 0xF7, + 0x00, 0xF7, 0x00, 0xED, 0x00, 0xED, 0x00, 0xED, + 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, + 0x09, 0x00, 0x11, 0x02, 0x11, 0x02, 0x11, 0x02, + 0x00, 0xED, 0x00, 0xDB, 0x00, 0xDB, 0x00, 0xDB, + 0x00, 0xB7, 0x00, 0xB7, 0x00, 0x6F, 0x00, 0x6F, + 0x11, 0x02, 0x23, 0x04, 0x23, 0x04, 0x23, 0x04, + 0x47, 0x08, 0x47, 0x08, 0x8F, 0x10, 0x8F, 0x10, + 0x00, 0xFE, 0x00, 0xFD, 0x00, 0xFB, 0x00, 0xF7, + 0x00, 0xEE, 0x00, 0xDD, 0x00, 0xBB, 0x00, 0x77, + 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x10, 0x01, 0x21, 0x02, 0x43, 0x04, 0x87, 0x08, + 0x00, 0xDF, 0x00, 0xBF, 0x00, 0xBF, 0x00, 0x7F, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x1F, 0x20, 0x3F, 0x40, 0x3F, 0x40, 0x7F, 0x80, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xEF, 0x00, 0xB7, + 0x00, 0xB7, 0x00, 0xDB, 0x00, 0xDD, 0x00, 0xEE, + 0x90, 0x00, 0x90, 0x00, 0x90, 0x00, 0x88, 0x40, + 0x88, 0x40, 0xC4, 0x20, 0xC2, 0x20, 0xE1, 0x10, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x7F, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFC, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFC, 0x00, 0xE3, 0x00, 0x1F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x1C, 0x00, 0xE0, 0x00, + 0x00, 0xFE, 0x00, 0xFD, 0x00, 0xF3, 0x00, 0xEF, + 0x00, 0x1C, 0x00, 0xF3, 0x00, 0xEF, 0x00, 0x1F, + 0x01, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x10, 0x00, + 0xE0, 0x03, 0x03, 0x0C, 0x0F, 0x10, 0x1F, 0xE0, + 0x00, 0xEF, 0x00, 0xDF, 0x00, 0xBF, 0x00, 0x7F, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x0F, 0x10, 0x1F, 0x20, 0x3F, 0x40, 0x7F, 0x80, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0xF7, 0x00, 0xF9, 0x00, 0xFE, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xF0, 0x08, 0xF8, 0x06, 0xFE, 0x01, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0x80, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0x80, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x7F, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0x03, 0x00, 0xFF, 0x00, 0xFC, 0x00, 0x03, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFC, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFC, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0xFC, 0x00, 0xE3, 0x00, 0x1F, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x03, 0x03, 0x1C, 0x1F, 0xE0, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, + 0x00, 0xFF, 0x00, 0xFF, 0x21, 0xDE, 0x00, 0x7F, + 0x0C, 0xF3, 0x19, 0xE0, 0x10, 0xEE, 0x08, 0xF7, + 0xFF, 0x00, 0xFF, 0x00, 0xC0, 0x3F, 0x80, 0xFF, + 0x00, 0xFF, 0x0E, 0xF7, 0x1F, 0xE1, 0x07, 0xF8, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0xBF, + 0x40, 0xBE, 0x80, 0x3F, 0x02, 0xFD, 0x00, 0xFB, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x80, 0x7F, 0xC0, + 0x7F, 0x81, 0xFE, 0x41, 0xFC, 0x03, 0xFC, 0x07, + 0x00, 0xFF, 0x00, 0xFF, 0x08, 0xF7, 0x00, 0xFF, + 0x00, 0xFB, 0x04, 0xFB, 0x24, 0xDB, 0x64, 0x9B, + 0xFF, 0x00, 0xFF, 0x00, 0x87, 0x78, 0x07, 0xF8, + 0x07, 0xFC, 0x07, 0xF8, 0x03, 0xFC, 0x43, 0xBC, + 0x00, 0xFF, 0x00, 0xFF, 0x01, 0xDE, 0x20, 0xDF, + 0x20, 0xDF, 0x00, 0xFF, 0x04, 0xFB, 0x04, 0xFB, + 0xFF, 0x00, 0xFF, 0x00, 0xE0, 0x3F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xF3, 0x31, 0xC0, 0x60, 0x9F, 0x40, 0xBF, + 0xFF, 0x00, 0xFF, 0x00, 0xC0, 0x7F, 0x00, 0xFF, + 0x00, 0xFF, 0x1E, 0xEF, 0x3F, 0xC0, 0x7F, 0x80, + 0x00, 0xFF, 0x00, 0xFF, 0x80, 0x77, 0x04, 0xDB, + 0x00, 0xFB, 0x10, 0xEF, 0x00, 0xFD, 0x80, 0x77, + 0xFF, 0x00, 0xFF, 0x00, 0x78, 0x8F, 0x38, 0xE7, + 0x1C, 0xE7, 0x0C, 0xF3, 0x0E, 0xF3, 0x0E, 0xF9, + 0x00, 0xFF, 0x00, 0xFF, 0x80, 0x7F, 0x00, 0xFF, + 0x40, 0xB7, 0x00, 0xEF, 0x01, 0xDE, 0x02, 0xFC, + 0xFF, 0x00, 0xFF, 0x00, 0x7C, 0x83, 0x78, 0x87, + 0x38, 0xCF, 0x30, 0xDF, 0x21, 0xFE, 0x03, 0xFD, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xDF, 0x60, 0x9F, + 0xC0, 0x3F, 0x80, 0x7F, 0x00, 0x7F, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0x3F, 0xE0, 0x3F, 0xC0, + 0x7F, 0x80, 0xFF, 0x00, 0xFF, 0x80, 0xFF, 0x00, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFB, 0x01, 0xFC, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFE, 0x01, 0xFC, 0x03, 0xFC, 0x07, 0xFE, 0x03, + 0x00, 0xFF, 0x40, 0x3F, 0x30, 0x8F, 0x00, 0xF7, + 0x80, 0x7F, 0x30, 0xCF, 0x01, 0xFE, 0x87, 0x78, + 0x01, 0xFE, 0x80, 0xFF, 0xE0, 0x5F, 0xF8, 0x0F, + 0x78, 0x87, 0x00, 0xFF, 0x00, 0xFF, 0x03, 0xFC, + 0x00, 0xFF, 0x08, 0xF7, 0x80, 0x6F, 0x80, 0x7F, + 0x80, 0x5F, 0x87, 0x78, 0x04, 0x7B, 0x08, 0x73, + 0xF8, 0x07, 0xF0, 0x0F, 0x70, 0x9F, 0x60, 0x9F, + 0x60, 0xBF, 0xC3, 0x3C, 0x87, 0xF8, 0x87, 0xFC, + 0xA0, 0x1F, 0x80, 0x7D, 0xE2, 0x1D, 0x02, 0xFD, + 0x02, 0xFD, 0xF0, 0x0F, 0x10, 0xEE, 0x11, 0xEE, + 0x43, 0xFC, 0xE3, 0x1E, 0x03, 0xFC, 0x01, 0xFE, + 0x01, 0xFE, 0xE1, 0x1E, 0xE1, 0x1F, 0xE1, 0x1E, + 0x44, 0xBB, 0x48, 0xB3, 0x48, 0xB7, 0x08, 0xF7, + 0x0A, 0xF5, 0x02, 0xF5, 0x80, 0x77, 0x90, 0x67, + 0x84, 0x7B, 0x84, 0x7F, 0x84, 0x7B, 0x84, 0x7B, + 0x8C, 0x73, 0x8C, 0x7B, 0x0E, 0xF9, 0x0E, 0xF9, + 0x86, 0x59, 0x06, 0xF9, 0x48, 0xB3, 0x08, 0xF7, + 0x10, 0xE7, 0x14, 0xEB, 0x24, 0xCB, 0x20, 0xDF, + 0x60, 0xBF, 0x44, 0xBB, 0x04, 0xFF, 0x0C, 0xF3, + 0x0C, 0xFB, 0x18, 0xE7, 0x18, 0xF7, 0x38, 0xC7, + 0x08, 0xD7, 0x48, 0x97, 0x48, 0xB7, 0x41, 0xBE, + 0x41, 0xBE, 0x01, 0xBE, 0x10, 0xAF, 0x90, 0x2F, + 0x30, 0xEF, 0x30, 0xEF, 0x30, 0xCF, 0x30, 0xCF, + 0x70, 0x8F, 0x70, 0xCF, 0x60, 0xDF, 0x60, 0xDF, + 0x04, 0xFB, 0x04, 0xFB, 0xFC, 0x03, 0x00, 0xFF, + 0x00, 0xFF, 0xF8, 0x02, 0x05, 0xFA, 0x05, 0xFA, + 0x03, 0xFC, 0x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, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x82, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x78, 0x87, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x0F, 0xF0, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x70, 0x8E, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x01, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xC3, 0x18, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x24, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x8F, 0x70, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xF8, 0x03, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x04, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0x7F, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x80, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x3E, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0xC1, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xE0, 0x1F, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, +}; diff --git a/Core/sgb_animation_logo.inc b/Core/graphics/sgb_animation_logo.inc similarity index 100% rename from Core/sgb_animation_logo.inc rename to Core/graphics/sgb_animation_logo.inc diff --git a/Core/sgb_border.inc b/Core/graphics/sgb_border.inc similarity index 100% rename from Core/sgb_border.inc rename to Core/graphics/sgb_border.inc diff --git a/Core/sgb.c b/Core/sgb.c index 7ebeae0..d712e27 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -474,7 +474,7 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value) static uint32_t convert_rgb15(GB_gameboy_t *gb, uint16_t color) { - return GB_convert_rgb15(gb, color); + return GB_convert_rgb15(gb, color, false); } static uint32_t convert_rgb15_with_fade(GB_gameboy_t *gb, uint16_t color, uint8_t fade) @@ -489,14 +489,17 @@ static uint32_t convert_rgb15_with_fade(GB_gameboy_t *gb, uint16_t color, uint8_ color = r | (g << 5) | (b << 10); - return GB_convert_rgb15(gb, color); + return GB_convert_rgb15(gb, color, false); } #include static void render_boot_animation (GB_gameboy_t *gb) { -#include "sgb_animation_logo.inc" - uint32_t *output = &gb->screen[48 + 40 * 256]; +#include "graphics/sgb_animation_logo.inc" + uint32_t *output = gb->screen; + if (gb->border_mode != GB_BORDER_NEVER) { + output += 48 + 40 * 256; + } uint8_t *input = animation_logo; unsigned fade_blue = 0; unsigned fade_red = 0; @@ -544,7 +547,9 @@ static void render_boot_animation (GB_gameboy_t *gb) input++; } } - output += 256 - 160; + if (gb->border_mode != GB_BORDER_NEVER) { + output += 256 - 160; + } } } @@ -556,14 +561,6 @@ void GB_sgb_render(GB_gameboy_t *gb) } if (gb->sgb->intro_animation < INTRO_ANIMATION_LENGTH) gb->sgb->intro_animation++; - - if (!gb->screen || !gb->rgb_encode_callback) return; - - if (gb->sgb->mask_mode != MASK_FREEZE) { - memcpy(gb->sgb->effective_screen_buffer, - gb->sgb->screen_buffer, - sizeof(gb->sgb->effective_screen_buffer)); - } if (gb->sgb->vram_transfer_countdown) { if (--gb->sgb->vram_transfer_countdown == 0) { @@ -626,16 +623,27 @@ void GB_sgb_render(GB_gameboy_t *gb) } } + if (!gb->screen || !gb->rgb_encode_callback || gb->disable_rendering) return; + uint32_t colors[4 * 4]; for (unsigned i = 0; i < 4 * 4; i++) { colors[i] = convert_rgb15(gb, gb->sgb->effective_palettes[i]); } + if (gb->sgb->mask_mode != MASK_FREEZE) { + memcpy(gb->sgb->effective_screen_buffer, + gb->sgb->screen_buffer, + sizeof(gb->sgb->effective_screen_buffer)); + } + if (gb->sgb->intro_animation < INTRO_ANIMATION_LENGTH) { render_boot_animation(gb); } else { - uint32_t *output = &gb->screen[48 + 40 * 256]; + uint32_t *output = gb->screen; + if (gb->border_mode != GB_BORDER_NEVER) { + output += 48 + 40 * 256; + } uint8_t *input = gb->sgb->effective_screen_buffer; switch ((mask_mode_t) gb->sgb->mask_mode) { case MASK_DISABLED: @@ -645,7 +653,9 @@ void GB_sgb_render(GB_gameboy_t *gb) uint8_t palette = gb->sgb->attribute_map[x / 8 + y / 8 * 20] & 3; *(output++) = colors[(*(input++) & 3) + palette * 4]; } - output += 256 - 160; + if (gb->border_mode != GB_BORDER_NEVER) { + output += 256 - 160; + } } break; } @@ -656,7 +666,9 @@ void GB_sgb_render(GB_gameboy_t *gb) for (unsigned x = 0; x < 160; x++) { *(output++) = black; } - output += 256 - 160; + if (gb->border_mode != GB_BORDER_NEVER) { + output += 256 - 160; + } } break; } @@ -666,7 +678,9 @@ void GB_sgb_render(GB_gameboy_t *gb) for (unsigned x = 0; x < 160; x++) { *(output++) = colors[0]; } - output += 256 - 160; + if (gb->border_mode != GB_BORDER_NEVER) { + output += 256 - 160; + } } break; } @@ -703,6 +717,9 @@ void GB_sgb_render(GB_gameboy_t *gb) if (tile_x >= 6 && tile_x < 26 && tile_y >= 5 && tile_y < 23) { gb_area = true; } + else if (gb->border_mode == GB_BORDER_NEVER) { + continue; + } uint16_t tile = gb->sgb->border.map[tile_x + tile_y * 32]; uint8_t flip_x = (tile & 0x4000)? 0x7 : 0; uint8_t flip_y = (tile & 0x8000)? 0x7 : 0; @@ -710,12 +727,19 @@ void GB_sgb_render(GB_gameboy_t *gb) for (unsigned y = 0; y < 8; y++) { for (unsigned x = 0; x < 8; x++) { uint8_t color = gb->sgb->border.tiles[(tile & 0xFF) * 64 + (x ^ flip_x) + (y ^ flip_y) * 8] & 0xF; - if (color == 0) { - if (gb_area) continue; - gb->screen[tile_x * 8 + x + (tile_y * 8 + y) * 0x100] = colors[0]; + uint32_t *output = gb->screen; + if (gb->border_mode == GB_BORDER_NEVER) { + output += (tile_x - 6) * 8 + x + ((tile_y - 5) * 8 + y) * 160; } else { - gb->screen[tile_x * 8 + x + (tile_y * 8 + y) * 0x100] = border_colors[color + palette * 16]; + output += tile_x * 8 + x + (tile_y * 8 + y) * 256; + } + if (color == 0) { + if (gb_area) continue; + *output = colors[0]; + } + else { + *output = border_colors[color + palette * 16]; } } } @@ -726,12 +750,12 @@ void GB_sgb_render(GB_gameboy_t *gb) void GB_sgb_load_default_data(GB_gameboy_t *gb) { -#include "sgb_border.inc" +#include "graphics/sgb_border.inc" memcpy(gb->sgb->border.map, tilemap, sizeof(tilemap)); memcpy(gb->sgb->border.palette, palette, sizeof(palette)); - /* Expend tileset */ + /* Expand tileset */ for (unsigned tile = 0; tile < sizeof(tiles) / 32; tile++) { for (unsigned y = 0; y < 8; y++) { for (unsigned x = 0; x < 8; x++) { diff --git a/Core/sgb.h b/Core/sgb.h index df90253..aae9f75 100644 --- a/Core/sgb.h +++ b/Core/sgb.h @@ -5,6 +5,16 @@ #include typedef struct GB_sgb_s GB_sgb_t; +typedef struct { + uint8_t tiles[0x100 * 8 * 8]; /* High nibble not used*/ + union { + struct { + uint16_t map[32 * 32]; + uint16_t palette[16 * 4]; + }; + uint16_t raw_data[0x440]; + }; +} GB_sgb_border_t; #ifdef GB_INTERNAL struct GB_sgb_s { @@ -29,16 +39,7 @@ struct GB_sgb_s { uint8_t vram_transfer_countdown, transfer_dest; /* Border */ - struct { - uint8_t tiles[0x100 * 8 * 8]; /* High nibble not used*/ - union { - struct { - uint16_t map[32 * 32]; - uint16_t palette[16 * 4]; - }; - uint16_t raw_data[0x440]; - }; - } border, pending_border; + GB_sgb_border_t border, pending_border; uint8_t border_animation; /* Colorization */ diff --git a/SDL/gui.c b/SDL/gui.c index 4e06a75..6646a17 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -429,7 +429,13 @@ const char *current_color_correction_mode(unsigned index) const char *current_palette(unsigned index) { return (const char *[]){"Greyscale", "Lime (Game Boy)", "Olive (Pocket)", "Teal (Light)"} - [configuration.dmg_palette]; + [configuration.dmg_palette]; +} + +const char *current_border_mode(unsigned index) +{ + return (const char *[]){"SGB Only", "Never", "Always"} + [configuration.border_mode]; } void cycle_scaling(unsigned index) @@ -494,6 +500,26 @@ static void cycle_palette_backwards(unsigned index) } } +static void cycle_border_mode(unsigned index) +{ + if (configuration.border_mode == GB_BORDER_ALWAYS) { + configuration.border_mode = GB_BORDER_SGB; + } + else { + configuration.border_mode++; + } +} + +static void cycle_border_mode_backwards(unsigned index) +{ + if (configuration.border_mode == GB_BORDER_SGB) { + configuration.border_mode = GB_BORDER_ALWAYS; + } + else { + configuration.border_mode--; + } +} + struct shader_name { const char *file_name; const char *display_name; @@ -589,6 +615,7 @@ static const struct menu_item graphics_menu[] = { {"Scaling Filter:", cycle_filter, current_filter_name, cycle_filter_backwards}, {"Color Correction:", cycle_color_correction, current_color_correction_mode, cycle_color_correction_backwards}, {"Mono Palette:", cycle_palette, current_palette, cycle_palette_backwards}, + {"Display Border:", cycle_border_mode, current_border_mode, cycle_border_mode_backwards}, {"Blend Frames:", toggle_blend_frames, blend_frames_string, toggle_blend_frames}, {"Back", return_to_root_menu}, {NULL,} diff --git a/SDL/gui.h b/SDL/gui.h index ccfdfb9..41e9bf2 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -103,6 +103,7 @@ typedef struct { /* v0.13 */ uint8_t dmg_palette; + GB_border_mode_t border_mode; } configuration_t; extern configuration_t configuration; diff --git a/SDL/main.c b/SDL/main.c index cb9d00f..06159c9 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -112,12 +112,24 @@ static void update_palette(void) } } +static void screen_size_changed(void) +{ + SDL_DestroyTexture(texture); + texture = SDL_CreateTexture(renderer, SDL_GetWindowPixelFormat(window), SDL_TEXTUREACCESS_STREAMING, + GB_get_screen_width(&gb), GB_get_screen_height(&gb)); + + SDL_SetWindowMinimumSize(window, GB_get_screen_width(&gb), GB_get_screen_height(&gb)); + + update_viewport(); +} + static void open_menu(void) { bool audio_playing = SDL_GetAudioDeviceStatus(device_id) == SDL_AUDIO_PLAYING; if (audio_playing) { SDL_PauseAudioDevice(device_id, 1); } + size_t previous_width = GB_get_screen_width(&gb); run_gui(true); SDL_ShowCursor(SDL_DISABLE); if (audio_playing) { @@ -125,8 +137,12 @@ static void open_menu(void) SDL_PauseAudioDevice(device_id, 0); } GB_set_color_correction_mode(&gb, configuration.color_correction_mode); + GB_set_border_mode(&gb, configuration.border_mode); update_palette(); GB_set_highpass_filter_mode(&gb, configuration.highpass_mode); + if (previous_width != GB_get_screen_width(&gb)) { + screen_size_changed(); + } } static void handle_events(GB_gameboy_t *gb) @@ -495,19 +511,15 @@ restart: GB_set_sample_rate(&gb, have_aspec.freq); GB_set_color_correction_mode(&gb, configuration.color_correction_mode); update_palette(); + if ((unsigned)configuration.border_mode <= GB_BORDER_ALWAYS) { + GB_set_border_mode(&gb, configuration.border_mode); + } GB_set_highpass_filter_mode(&gb, configuration.highpass_mode); GB_set_rewind_length(&gb, configuration.rewind_length); GB_set_update_input_hint_callback(&gb, handle_events); GB_apu_set_sample_callback(&gb, gb_audio_callback); } - - SDL_DestroyTexture(texture); - texture = SDL_CreateTexture(renderer, SDL_GetWindowPixelFormat(window), SDL_TEXTUREACCESS_STREAMING, - GB_get_screen_width(&gb), GB_get_screen_height(&gb)); - - SDL_SetWindowMinimumSize(window, GB_get_screen_width(&gb), GB_get_screen_height(&gb)); - bool error = false; start_capturing_logs(); error = GB_load_rom(&gb, filename); @@ -528,7 +540,7 @@ restart: replace_extension(filename, path_length, symbols_path, ".sym"); GB_debugger_load_symbol_file(&gb, symbols_path); - update_viewport(); + screen_size_changed(); /* Run emulation */ while (true) { From dcb3f6db9e13e5b3510d0eadee326f3cf4ddd27b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 8 Feb 2020 14:38:04 +0200 Subject: [PATCH 010/125] Fix minimum window size in the Cocoa frontend --- Cocoa/Document.m | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 6b9915c..f7349cc 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -239,6 +239,15 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) GB_apu_set_sample_callback(&gb, audioCallback); } +- (void) updateMinSize +{ + self.mainWindow.contentMinSize = NSMakeSize(GB_get_screen_width(&gb), GB_get_screen_height(&gb)); + if (self.mainWindow.contentView.bounds.size.width < GB_get_screen_width(&gb) || + self.mainWindow.contentView.bounds.size.width < GB_get_screen_height(&gb)) { + [self.mainWindow zoom:nil]; + } +} + - (void) vblank { [self.view flip]; @@ -248,6 +257,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) GB_set_border_mode(&gb, (GB_border_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBBorderMode"]); if (GB_get_screen_width(&gb) != previous_width) { [self.view screenSizeChanged]; + [self updateMinSize]; } }); borderModeChanged = false; @@ -405,11 +415,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [self.view screenSizeChanged]; } - self.mainWindow.contentMinSize = NSMakeSize(GB_get_screen_width(&gb), GB_get_screen_height(&gb)); - if (self.mainWindow.contentView.bounds.size.width < GB_get_screen_width(&gb) || - self.mainWindow.contentView.bounds.size.width < GB_get_screen_height(&gb)) { - [self.mainWindow zoom:nil]; - } + [self updateMinSize]; if ([sender tag] != 0) { /* User explictly selected a model, save the preference */ From 804b9bec63a16d8f94068bcc1fb5c1f30e4e9f34 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 10 Feb 2020 00:21:33 +0200 Subject: [PATCH 011/125] Fixed a bug where HDMA begins in the middle of an instruction while cycles are pending to be flushed. Fixes #230 --- Core/sm83_cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 0009a69..c9da208 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -1512,10 +1512,11 @@ void GB_cpu_run(GB_gameboy_t *gb) opcodes[gb->last_opcode_read](gb, gb->last_opcode_read); } + flush_pending_cycles(gb); + if (gb->hdma_starting) { gb->hdma_starting = false; gb->hdma_on = true; gb->hdma_cycles = -8; } - flush_pending_cycles(gb); } From 8b7805b95de34aec0ece1b482ce1e2f3b016f453 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 10 Feb 2020 20:19:37 +0200 Subject: [PATCH 012/125] Hit ^T --- Core/sm83_cpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index c9da208..713bb66 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -1454,19 +1454,19 @@ void GB_cpu_run(GB_gameboy_t *gb) } gb->just_halted = false; - bool effecitve_ime = gb->ime; + bool effective_ime = gb->ime; if (gb->ime_toggle) { gb->ime = !gb->ime; gb->ime_toggle = false; } /* Wake up from HALT mode without calling interrupt code. */ - if (gb->halted && !effecitve_ime && interrupt_queue) { + if (gb->halted && !effective_ime && interrupt_queue) { gb->halted = false; } /* Call interrupt */ - else if (effecitve_ime && interrupt_queue) { + else if (effective_ime && interrupt_queue) { gb->halted = false; uint16_t call_addr = gb->pc; From 0677b1d099fd7ae6bf8eec83fae80df93e33a012 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 11 Feb 2020 00:11:17 +0200 Subject: [PATCH 013/125] Update the automation to not use internel APIs for input --- Tester/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Tester/main.c b/Tester/main.c index 03b9985..e3b662c 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -73,38 +73,38 @@ static void handle_buttons(GB_gameboy_t *gb) frames) % combo_length + (start_is_bad? 20 : 0) ) { case 0: if (!limit_start || frames < 20 * 60) { - gb->keys[0][push_right? 0 : 7] = true; // Start (Or right) down + GB_set_key_state(gb, push_right? GB_KEY_RIGHT: GB_KEY_START, true); } if (pointer_control) { - gb->keys[0][1] = true; // left - gb->keys[0][2] = true; // up + GB_set_key_state(gb, GB_KEY_LEFT, true); + GB_set_key_state(gb, GB_KEY_UP, true); } break; case 10: - gb->keys[0][push_right? 0 : 7] = false; // Start (Or right) up + GB_set_key_state(gb, push_right? GB_KEY_RIGHT: GB_KEY_START, false); if (pointer_control) { - gb->keys[0][1] = false; // left - gb->keys[0][2] = false; // up + GB_set_key_state(gb, GB_KEY_LEFT, false); + GB_set_key_state(gb, GB_KEY_UP, false); } break; case 20: - gb->keys[0][b_is_confirm? 5: 4] = true; // A down (or B) + GB_set_key_state(gb, b_is_confirm? GB_KEY_B: GB_KEY_A, true); break; case 30: - gb->keys[0][b_is_confirm? 5: 4] = false; // A up (or B) + GB_set_key_state(gb, b_is_confirm? GB_KEY_B: GB_KEY_A, false); break; case 40: if (push_a_twice) { - gb->keys[0][b_is_confirm? 5: 4] = true; // A down (or B) + GB_set_key_state(gb, b_is_confirm? GB_KEY_B: GB_KEY_A, true); } else if (gb->boot_rom_finished) { - gb->keys[0][3] = true; // D-Pad Down down + GB_set_key_state(gb, GB_KEY_DOWN, true); } break; case 50: - gb->keys[0][b_is_confirm? 5: 4] = false; // A down (or B) - gb->keys[0][3] = false; // D-Pad Down up + GB_set_key_state(gb, b_is_confirm? GB_KEY_B: GB_KEY_A, false); + GB_set_key_state(gb, GB_KEY_DOWN, false); break; } } From f550360f1ae8bf470dbb51a0eb879377b351322e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 15 Feb 2020 13:21:21 +0200 Subject: [PATCH 014/125] More accurate CGB color correction curve --- Core/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/display.c b/Core/display.c index b7ddee1..842c21f 100644 --- a/Core/display.c +++ b/Core/display.c @@ -229,7 +229,7 @@ static inline uint8_t scale_channel(uint8_t x) static inline uint8_t scale_channel_with_curve(uint8_t x) { - return (uint8_t[]){0,2,4,7,12,18,25,34,42,52,62,73,85,97,109,121,134,146,158,170,182,193,203,213,221,230,237,243,248,251,253,255}[x]; + return (uint8_t[]){0,5,8,11,16,22,28,36,43,51,59,67,77,87,97,107,119,130,141,153,166,177,188,200,209,221,230,238,245,249,252,255}[x]; } static inline uint8_t scale_channel_with_curve_agb(uint8_t x) From 08eb2f3d987cf7a3775c2ecf1b00b74dd4bea7c2 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 15 Feb 2020 15:32:06 +0200 Subject: [PATCH 015/125] Correct emulation of FF6C (Turns out it controls object priority) --- Core/display.c | 2 +- Core/display.h | 7 +++++++ Core/gb.c | 2 ++ Core/gb.h | 7 +++---- Core/memory.c | 20 +++++++++++++++----- Core/save_state.c | 8 ++++++++ Misc/registers.sym | 4 ++-- 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Core/display.c b/Core/display.c index 842c21f..521a386 100644 --- a/Core/display.c +++ b/Core/display.c @@ -939,7 +939,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->vram[line_address + 1], palette, object->flags & 0x80, - gb->cgb_mode? gb->visible_objs[gb->n_visible_objs - 1] : 0, + gb->object_priority == GB_OBJECT_PRIORITY_INDEX? gb->visible_objs[gb->n_visible_objs - 1] : 0, object->flags & 0x20); gb->n_visible_objs--; diff --git a/Core/display.h b/Core/display.h index 69e7905..b9e3149 100644 --- a/Core/display.h +++ b/Core/display.h @@ -11,6 +11,13 @@ void GB_palette_changed(GB_gameboy_t *gb, bool background_palette, uint8_t index void GB_window_related_write(GB_gameboy_t *gb, uint8_t addr, uint8_t value); void GB_STAT_update(GB_gameboy_t *gb); void GB_lcd_off(GB_gameboy_t *gb); + +enum { + GB_OBJECT_PRIORITY_UNDEFINED, // For save state compatibility + GB_OBJECT_PRIORITY_X, + GB_OBJECT_PRIORITY_INDEX, +}; + #endif typedef enum { diff --git a/Core/gb.c b/Core/gb.c index b0eaf68..31fff0d 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -1008,11 +1008,13 @@ void GB_reset(GB_gameboy_t *gb) gb->vram_size = 0x2000 * 2; memset(gb->vram, 0, gb->vram_size); gb->cgb_mode = true; + gb->object_priority = GB_OBJECT_PRIORITY_INDEX; } else { gb->ram_size = 0x2000; gb->vram_size = 0x2000; memset(gb->vram, 0, gb->vram_size); + gb->object_priority = GB_OBJECT_PRIORITY_X; update_dmg_palette(gb); } diff --git a/Core/gb.h b/Core/gb.h index e803f3c..b413fe5 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -185,7 +185,7 @@ enum { // Unfortunately it is not readable or writable after boot has finished, so research of this // register is quite limited. The value written to this register, however, can be controlled // in some cases. - GB_IO_DMG_EMULATION = 0x4c, + GB_IO_MODE = 0x4c, /* General CGB features */ GB_IO_KEY1 = 0x4d, // CGB Mode Only - Prepare Speed Switch @@ -212,9 +212,7 @@ enum { GB_IO_BGPD = 0x69, // CGB Mode Only - Background Palette Data GB_IO_OBPI = 0x6a, // CGB Mode Only - Sprite Palette Index GB_IO_OBPD = 0x6b, // CGB Mode Only - Sprite Palette Data - - // 1 is written for DMG ROMs on a CGB. Does not appear to have an effect. - GB_IO_DMG_EMULATION_INDICATION = 0x6c, // (FEh) Bit 0 (Read/Write) + GB_IO_OBJECT_PRIORITY = 0x6c, // Affects object priority (X based or index based) /* Missing */ @@ -516,6 +514,7 @@ struct GB_gameboy_internal_s { bool cgb_palettes_blocked; uint8_t current_lcd_line; // The LCD can go out of sync since the vsync signal is skipped in some cases. uint32_t cycles_in_stop_mode; + uint8_t object_priority; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/Core/memory.c b/Core/memory.c index 003bb77..8e254bc 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -295,11 +295,11 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) return gb->io_registers[GB_IO_TAC] | 0xF8; case GB_IO_STAT: return gb->io_registers[GB_IO_STAT] | 0x80; - case GB_IO_DMG_EMULATION_INDICATION: - if (!gb->cgb_mode) { + case GB_IO_OBJECT_PRIORITY: + if (!GB_is_cgb(gb)) { return 0xFF; } - return gb->io_registers[GB_IO_DMG_EMULATION_INDICATION] | 0xFE; + return gb->io_registers[GB_IO_OBJECT_PRIORITY] | 0xFE; case GB_IO_PCM_12: if (!GB_is_cgb(gb)) return 0xFF; @@ -656,13 +656,22 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) case GB_IO_OBP1: case GB_IO_WY: case GB_IO_SB: - case GB_IO_DMG_EMULATION_INDICATION: case GB_IO_UNKNOWN2: case GB_IO_UNKNOWN3: case GB_IO_UNKNOWN4: case GB_IO_UNKNOWN5: gb->io_registers[addr & 0xFF] = value; return; + case GB_IO_OBJECT_PRIORITY: + if ((!gb->boot_rom_finished || (gb->io_registers[GB_IO_MODE] & 8)) && GB_is_cgb(gb)) { + gb->io_registers[addr & 0xFF] = value; + gb->object_priority = (value & 1) ? GB_OBJECT_PRIORITY_X : GB_OBJECT_PRIORITY_INDEX; + } + else if (gb->cgb_mode) { + gb->io_registers[addr & 0xFF] = value; + + } + return; case GB_IO_LYC: /* TODO: Probably completely wrong in double speed mode */ @@ -768,9 +777,10 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) gb->boot_rom_finished = true; return; - case GB_IO_DMG_EMULATION: + case GB_IO_MODE: if (GB_is_cgb(gb) && !gb->boot_rom_finished) { gb->cgb_mode = !(value & 0xC); /* The real "contents" of this register aren't quite known yet. */ + gb->io_registers[GB_IO_MODE] = value; } return; diff --git a/Core/save_state.c b/Core/save_state.c index 8ef99ae..931a319 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -266,6 +266,10 @@ int GB_load_state(GB_gameboy_t *gb, const char *path) gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.write_end &= 0xF; + if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { + gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; + } + error: fclose(f); return errno; @@ -371,6 +375,10 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.write_end &= 0xF; + if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { + gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; + } + return 0; } diff --git a/Misc/registers.sym b/Misc/registers.sym index 3bc95bb..ea76ab3 100644 --- a/Misc/registers.sym +++ b/Misc/registers.sym @@ -55,7 +55,7 @@ 00:FF69 IO_BGPD 00:FF6A IO_OBPI 00:FF6B IO_OBPD -00:FF6C IO_DMG_EMULATION_INDICATION +00:FF6C IO_OBJECT_PRIORITY 00:FF70 IO_SVBK 00:FF72 IO_UNKNOWN2 00:FF73 IO_UNKNOWN3 @@ -64,4 +64,4 @@ 00:FF76 IO_PCM_12 00:FF77 IO_PCM_34 00:FF7F IO_UNKNOWN8 -00:FFFF IO_IE \ No newline at end of file +00:FFFF IO_IE From bec09a012cae8f1efe5723afac401084420d59d9 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 15 Feb 2020 19:21:43 +0200 Subject: [PATCH 016/125] More accurate emulation of STOP mode --- Core/display.c | 56 +++++++++++++++++++++++++++++++++---------------- Core/gb.h | 3 +++ Core/sm83_cpu.c | 33 +++++++++++++++++++++-------- Core/timing.c | 7 ++++++- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/Core/display.c b/Core/display.c index 521a386..d5f3c74 100644 --- a/Core/display.c +++ b/Core/display.c @@ -136,23 +136,18 @@ static void display_vblank(GB_gameboy_t *gb) } } - if ((!gb->disable_rendering || gb->sgb) && ((!(gb->io_registers[GB_IO_LCDC] & 0x80) || gb->stopped) || gb->frame_skip_state == GB_FRAMESKIP_LCD_TURNED_ON)) { + bool is_ppu_stopped = !GB_is_cgb(gb) && gb->stopped && gb->io_registers[GB_IO_LCDC] & 0x80; + + if (!gb->disable_rendering && ((!(gb->io_registers[GB_IO_LCDC] & 0x80) || is_ppu_stopped) || gb->frame_skip_state == GB_FRAMESKIP_LCD_TURNED_ON)) { /* LCD is off, set screen to white or black (if LCD is on in stop mode) */ - if (gb->sgb) { - for (unsigned i = 0; i < WIDTH * LINES; i++) { - gb->sgb->screen_buffer[i] = 0x0; - } - } - else { + if (!GB_is_sgb(gb)) { uint32_t color = 0; if (GB_is_cgb(gb)) { - color = (gb->io_registers[GB_IO_LCDC] & 0x80) && gb->stopped ? - gb->rgb_encode_callback(gb, 0, 0, 0) : - gb->rgb_encode_callback(gb, 0xFF, 0xFF, 0xFF); + color = gb->rgb_encode_callback(gb, 0xFF, 0xFF, 0xFF); } else { - color = (gb->io_registers[GB_IO_LCDC] & 0x80) && gb->stopped ? - gb->background_palettes_rgb[3] : + color = is_ppu_stopped ? + gb->background_palettes_rgb[0] : gb->background_palettes_rgb[4]; } if (gb->border_mode == GB_BORDER_ALWAYS) { @@ -412,6 +407,10 @@ static void add_object_from_index(GB_gameboy_t *gb, unsigned index) if (gb->dma_steps_left && (gb->dma_cycles >= 0 || gb->is_dma_restarting)) { return; } + + if (gb->oam_ppu_blocked) { + return; + } /* This reverse sorts the visible objects by location and priority */ GB_object_t *objects = (GB_object_t *) &gb->oam; @@ -499,6 +498,9 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) icd_pixel = pixel; } } + else if (gb->cgb_palettes_ppu_blocked) { + *dest = gb->rgb_encode_callback(gb, 0, 0, 0); + } else { *dest = gb->background_palettes_rgb[fifo_item->palette * 4 + pixel]; } @@ -521,6 +523,9 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) //gb->icd_pixel_callback(gb, pixel); } } + else if (gb->cgb_palettes_ppu_blocked) { + *dest = gb->rgb_encode_callback(gb, 0, 0, 0); + } else { *dest = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel]; } @@ -585,10 +590,16 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_y = y; } gb->current_tile = gb->vram[map + gb->fetcher_x + y / 8 * 32]; + if (gb->vram_ppu_blocked) { + gb->current_tile = 0xFF; + } if (GB_is_cgb(gb)) { /* The CGB actually accesses both the tile index AND the attributes in the same T-cycle. This probably means the CGB has a 16-bit data bus for the VRAM. */ gb->current_tile_attributes = gb->vram[map + gb->fetcher_x + y / 8 * 32 + 0x2000]; + if (gb->vram_ppu_blocked) { + gb->current_tile_attributes = 0xFF; + } } gb->fetcher_x++; gb->fetcher_x &= 0x1f; @@ -615,7 +626,10 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) y_flip = 0x7; } gb->current_tile_data[0] = - gb->vram[tile_address + ((y & 7) ^ y_flip) * 2]; + gb->vram[tile_address + ((y & 7) ^ y_flip) * 2]; + if (gb->vram_ppu_blocked) { + gb->current_tile_data[0] = 0xFF; + } } gb->fetcher_state++; break; @@ -642,7 +656,10 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) y_flip = 0x7; } gb->current_tile_data[1] = - gb->vram[tile_address + ((y & 7) ^ y_flip) * 2 + 1]; + gb->vram[tile_address + ((y & 7) ^ y_flip) * 2 + 1]; + if (gb->vram_ppu_blocked) { + gb->current_tile_data[1] = 0xFF; + } } gb->fetcher_state++; break; @@ -913,7 +930,11 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->cycles_for_line += 6; GB_SLEEP(gb, display, 20, 6); /* TODO: what does the PPU read if DMA is active? */ - GB_object_t *object = &objects[gb->visible_objs[gb->n_visible_objs - 1]]; + const GB_object_t *object = &objects[gb->visible_objs[gb->n_visible_objs - 1]]; + if (gb->oam_ppu_blocked) { + static const GB_object_t blocked = {0xFF, 0xFF, 0xFF, 0xFF}; + object = &blocked; + } bool height_16 = (gb->io_registers[GB_IO_LCDC] & 4) != 0; /* Todo: Which T-cycle actually reads this? */ uint8_t tile_y = (gb->current_line - object->y) & (height_16? 0xF : 7); @@ -933,10 +954,9 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) if (gb->cgb_mode) { palette = object->flags & 0x7; } - fifo_overlay_object_row(&gb->oam_fifo, - gb->vram[line_address], - gb->vram[line_address + 1], + gb->vram_ppu_blocked? 0xFF : gb->vram[line_address], + gb->vram_ppu_blocked? 0xFF : gb->vram[line_address + 1], palette, object->flags & 0x80, gb->object_priority == GB_OBJECT_PRIORITY_INDEX? gb->visible_objs[gb->n_visible_objs - 1] : 0, diff --git a/Core/gb.h b/Core/gb.h index b413fe5..56b0a9a 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -515,6 +515,9 @@ struct GB_gameboy_internal_s { uint8_t current_lcd_line; // The LCD can go out of sync since the vsync signal is skipped in some cases. uint32_t cycles_in_stop_mode; uint8_t object_priority; + bool oam_ppu_blocked; + bool vram_ppu_blocked; + bool cgb_palettes_ppu_blocked; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 713bb66..f30443d 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -236,6 +236,26 @@ static void nop(GB_gameboy_t *gb, uint8_t opcode) { } +static void enter_stop_mode(GB_gameboy_t *gb) +{ + gb->stopped = true; + gb->oam_ppu_blocked = !gb->oam_read_blocked; + gb->vram_ppu_blocked = !gb->vram_read_blocked; + gb->cgb_palettes_ppu_blocked = !gb->cgb_palettes_blocked; +} + +static void leave_stop_mode(GB_gameboy_t *gb) +{ + /* The CPU takes more time to wake up then the other components */ + for (unsigned i = 0x200; i--;) { + GB_advance_cycles(gb, 0x10); + } + gb->stopped = false; + gb->oam_ppu_blocked = false; + gb->vram_ppu_blocked = false; + gb->cgb_palettes_ppu_blocked = false; +} + static void stop(GB_gameboy_t *gb, uint8_t opcode) { if (gb->io_registers[GB_IO_KEY1] & 0x1) { @@ -252,9 +272,8 @@ static void stop(GB_gameboy_t *gb, uint8_t opcode) gb->cgb_double_speed ^= true; gb->io_registers[GB_IO_KEY1] = 0; - for (unsigned i = 0x800; i--;) { - GB_advance_cycles(gb, 0x40); - } + enter_stop_mode(gb); + leave_stop_mode(gb); if (!needs_alignment) { GB_advance_cycles(gb, 0x4); @@ -270,7 +289,7 @@ static void stop(GB_gameboy_t *gb, uint8_t opcode) gb->halted = true; } else { - gb->stopped = true; + enter_stop_mode(gb); } } @@ -1429,11 +1448,7 @@ void GB_cpu_run(GB_gameboy_t *gb) GB_timing_sync(gb); GB_advance_cycles(gb, 4); if ((gb->io_registers[GB_IO_JOYP] & 0xF) != 0xF) { - gb->stopped = false; - /* The CPU takes more time to wake up then the other components */ - for (unsigned i = 0x800; i--;) { - GB_advance_cycles(gb, 0x40); - } + leave_stop_mode(gb); GB_advance_cycles(gb, 8); } return; diff --git a/Core/timing.c b/Core/timing.c index 283558c..1f3f654 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -139,6 +139,11 @@ static void GB_set_internal_div_counter(GB_gameboy_t *gb, uint32_t value) static void GB_timers_run(GB_gameboy_t *gb, uint8_t cycles) { + if (gb->stopped) { + gb->apu.apu_cycles += 4 << !gb->cgb_double_speed; + return; + } + GB_STATE_MACHINE(gb, div, cycles, 1) { GB_STATE(gb, div, 1); GB_STATE(gb, div, 2); @@ -213,8 +218,8 @@ void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles) // Affected by speed boost gb->dma_cycles += cycles; + GB_timers_run(gb, cycles); if (!gb->stopped) { - GB_timers_run(gb, cycles); advance_serial(gb, cycles); // TODO: Verify what happens in STOP mode } From bf32ae66c60d0401ccbb49031e19cd47e5890fff Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 15 Feb 2020 19:23:04 +0200 Subject: [PATCH 017/125] Another attemp to fix Cocoa deadlocking --- Cocoa/Document.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index f7349cc..df15806 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -374,7 +374,9 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) if (GB_debugger_is_stopped(&gb)) { [self interruptDebugInputRead]; } + [audioLock lock]; stopping = true; + [audioLock unlock]; running = false; while (stopping); GB_debugger_set_disabled(&gb, false); From 0290e704451742741c90b466e9ee34eeadd4ebcc Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 17 Feb 2020 23:05:11 +0200 Subject: [PATCH 018/125] Improvements to AGB color correction --- Core/display.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Core/display.c b/Core/display.c index d5f3c74..e0c1a53 100644 --- a/Core/display.c +++ b/Core/display.c @@ -264,15 +264,13 @@ uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border) if (gb->color_correction_mode != GB_COLOR_CORRECTION_CORRECT_CURVES) { uint8_t new_r, new_g, new_b; if (agb) { - new_r = (r * 7 + g * 1) / 8; - new_g = (g * 3 + b * 1) / 4; - new_b = (b * 7 + r * 1) / 8; + new_g = (g * 6 + b * 1) / 7; } else { new_g = (g * 3 + b) / 4; - new_r = r; - new_b = b; } + new_r = r; + new_b = b; if (gb->color_correction_mode == GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS) { uint8_t old_max = MAX(r, MAX(g, b)); uint8_t new_max = MAX(new_r, MAX(new_g, new_b)); From a8f63aea3ce47b72805bc59b5d4f35d112d39bad Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 02:55:07 +0200 Subject: [PATCH 019/125] Emulate DMG LCDC write conflicts correctly. This might vary between individual units. --- Core/sm83_cpu.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index f30443d..5c491f8 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -18,6 +18,7 @@ typedef enum { GB_CONFLICT_STAT_DMG, GB_CONFLICT_PALETTE_DMG, GB_CONFLICT_PALETTE_CGB, + GB_CONFLICT_READ_DMG_LCDC, } GB_conflict_t; /* Todo: How does double speed mode affect these? */ @@ -37,7 +38,7 @@ static const GB_conflict_t cgb_conflict_map[0x80] = { static const GB_conflict_t dmg_conflict_map[0x80] = { [GB_IO_IF] = GB_CONFLICT_WRITE_CPU, [GB_IO_LYC] = GB_CONFLICT_READ_OLD, - [GB_IO_LCDC] = GB_CONFLICT_READ_NEW, + [GB_IO_LCDC] = GB_CONFLICT_READ_DMG_LCDC, [GB_IO_SCY] = GB_CONFLICT_READ_NEW, [GB_IO_STAT] = GB_CONFLICT_STAT_DMG, @@ -192,6 +193,17 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) gb->pending_cycles = 6; return; } + + case GB_CONFLICT_READ_DMG_LCDC: { + /* Seems to be affected by screen? Both my DMG (B, blob) and Game Boy Light behave this way though. */ + uint8_t old_value = GB_read_memory(gb, addr); + GB_advance_cycles(gb, gb->pending_cycles - 2); + GB_write_memory(gb, addr, old_value | (value & 1)); + GB_advance_cycles(gb, 1); + GB_write_memory(gb, addr, value); + gb->pending_cycles = 5; + return; + } } } From 56118d2a6701f422d002a6da123768ef409820a9 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 14:22:25 +0200 Subject: [PATCH 020/125] Move improvements to LCDC conflicts --- Core/display.c | 2 -- Core/sm83_cpu.c | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Core/display.c b/Core/display.c index e0c1a53..c09764a 100644 --- a/Core/display.c +++ b/Core/display.c @@ -441,7 +441,6 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) if (!gb->oam_fifo_paused && fifo_size(&gb->oam_fifo)) { oam_fifo_item = fifo_pop(&gb->oam_fifo); - /* Todo: Verify access timings */ if (oam_fifo_item->pixel && (gb->io_registers[GB_IO_LCDC] & 2)) { draw_oam = true; bg_priority |= oam_fifo_item->bg_priority; @@ -457,7 +456,6 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) /* Mixing */ - /* Todo: Verify access timings */ if ((gb->io_registers[GB_IO_LCDC] & 0x1) == 0) { if (gb->cgb_mode) { bg_priority = false; diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 5c491f8..53bca48 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -18,7 +18,7 @@ typedef enum { GB_CONFLICT_STAT_DMG, GB_CONFLICT_PALETTE_DMG, GB_CONFLICT_PALETTE_CGB, - GB_CONFLICT_READ_DMG_LCDC, + GB_CONFLICT_DMG_LCDC, } GB_conflict_t; /* Todo: How does double speed mode affect these? */ @@ -38,7 +38,7 @@ static const GB_conflict_t cgb_conflict_map[0x80] = { static const GB_conflict_t dmg_conflict_map[0x80] = { [GB_IO_IF] = GB_CONFLICT_WRITE_CPU, [GB_IO_LYC] = GB_CONFLICT_READ_OLD, - [GB_IO_LCDC] = GB_CONFLICT_READ_DMG_LCDC, + [GB_IO_LCDC] = GB_CONFLICT_DMG_LCDC, [GB_IO_SCY] = GB_CONFLICT_READ_NEW, [GB_IO_STAT] = GB_CONFLICT_STAT_DMG, @@ -194,10 +194,13 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) return; } - case GB_CONFLICT_READ_DMG_LCDC: { + case GB_CONFLICT_DMG_LCDC: { /* Seems to be affected by screen? Both my DMG (B, blob) and Game Boy Light behave this way though. */ uint8_t old_value = GB_read_memory(gb, addr); GB_advance_cycles(gb, gb->pending_cycles - 2); + if (/* gb->model != GB_MODEL_MGB && */ gb->position_in_line == 0 && (old_value & 2) && !(value & 2)) { + old_value &= ~2; + } GB_write_memory(gb, addr, old_value | (value & 1)); GB_advance_cycles(gb, 1); GB_write_memory(gb, addr, value); From 91404edd138a6a44b4b2057ffc2300c4bfeab910 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 15:14:33 +0200 Subject: [PATCH 021/125] Disgusting hacks to emulate disabling objects while an object is being fetched --- Core/display.c | 12 ++++++++++++ Core/gb.h | 1 + Core/sm83_cpu.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Core/display.c b/Core/display.c index c09764a..99b8185 100644 --- a/Core/display.c +++ b/Core/display.c @@ -912,6 +912,9 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) advance_fetcher_state_machine(gb); gb->cycles_for_line++; GB_SLEEP(gb, display, 27, 1); + if (!(gb->io_registers[GB_IO_LCDC] & 2) && !GB_is_cgb(gb)) { + goto abort_fetching_object; + } } /* Todo: Measure if penalty occurs before or after waiting for the fetcher. */ @@ -920,11 +923,19 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->cycles_for_line += gb->extra_penalty_for_sprite_at_0; GB_SLEEP(gb, display, 28, gb->extra_penalty_for_sprite_at_0); gb->extra_penalty_for_sprite_at_0 = 0; + if (gb->object_fetch_aborted) { + gb->object_fetch_aborted = false; + goto abort_fetching_object; + } } } gb->cycles_for_line += 6; GB_SLEEP(gb, display, 20, 6); + if (gb->object_fetch_aborted) { + gb->object_fetch_aborted = false; + goto abort_fetching_object; + } /* TODO: what does the PPU read if DMA is active? */ const GB_object_t *object = &objects[gb->visible_objs[gb->n_visible_objs - 1]]; if (gb->oam_ppu_blocked) { @@ -961,6 +972,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->n_visible_objs--; } +abort_fetching_object: /* Handle window */ /* Todo: Timing (Including penalty and access timings) not verified by test ROM */ if (!gb->in_window && window_enabled(gb) && diff --git a/Core/gb.h b/Core/gb.h index 56b0a9a..4e31e00 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -518,6 +518,7 @@ struct GB_gameboy_internal_s { bool oam_ppu_blocked; bool vram_ppu_blocked; bool cgb_palettes_ppu_blocked; + bool object_fetch_aborted; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 53bca48..1dbfc5e 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -195,14 +195,51 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) } case GB_CONFLICT_DMG_LCDC: { - /* Seems to be affected by screen? Both my DMG (B, blob) and Game Boy Light behave this way though. */ + /* Similar to the palette registers, these interact directly with the LCD, so they appear to be affected by it. Both my DMG (B, blob) and Game Boy Light behave this way though. + + Additionally, LCDC.1 is very nasty because on the it is read both by the FIFO when popping pixels, + and the sprite-fetching state machine, and both behave differently when it comes to access conflicts. + Hacks ahead. + */ + + + uint8_t old_value = GB_read_memory(gb, addr); GB_advance_cycles(gb, gb->pending_cycles - 2); + + if (gb->current_lcd_line == 108) { + + } + + /* Handle disabling objects while already fetching an object */ + if ((old_value & 2) && !(value & 2)) { + if (gb->display_state == 27) { + old_value &= ~2; + } + else if (gb->display_state == 20 || gb->display_state == 28) { + gb->cycles_for_line -= gb->display_cycles; + gb->display_cycles = 0; + gb->object_fetch_aborted = true; + } + } + if (/* gb->model != GB_MODEL_MGB && */ gb->position_in_line == 0 && (old_value & 2) && !(value & 2)) { old_value &= ~2; } + GB_write_memory(gb, addr, old_value | (value & 1)); GB_advance_cycles(gb, 1); + /* Handle disabling objects while already fetching an object */ + if ((old_value & 2) && !(value & 2)) { + if (gb->display_state == 27) { + old_value &= ~2; + } + else if (gb->display_state == 20 || gb->display_state == 28) { + gb->cycles_for_line -= gb->display_cycles; + gb->display_cycles = 0; + gb->object_fetch_aborted = true; + } + } GB_write_memory(gb, addr, value); gb->pending_cycles = 5; return; From 7d51ba3d9745917f7b5855bcc53e28dd7b5d2be2 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 16:16:02 +0200 Subject: [PATCH 022/125] More fixes, SGB emulation of the same quirk --- Core/display.c | 19 +++++++++++++------ Core/gb.h | 1 + Core/sm83_cpu.c | 42 ++++++++++++++++++++++++++++++------------ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Core/display.c b/Core/display.c index 99b8185..7523f6d 100644 --- a/Core/display.c +++ b/Core/display.c @@ -735,6 +735,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_STATE(gb, display, 36); GB_STATE(gb, display, 37); GB_STATE(gb, display, 38); + GB_STATE(gb, display, 39); } @@ -904,15 +905,16 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->obj_comparators[gb->n_visible_objs - 1] < (uint8_t)(gb->position_in_line + 8)) { gb->n_visible_objs--; } + + gb->during_object_fetch = true; while (gb->n_visible_objs != 0 && (gb->io_registers[GB_IO_LCDC] & 2 || GB_is_cgb(gb)) && gb->obj_comparators[gb->n_visible_objs - 1] == (uint8_t)(gb->position_in_line + 8)) { - while (gb->fetcher_state < 5) { advance_fetcher_state_machine(gb); gb->cycles_for_line++; GB_SLEEP(gb, display, 27, 1); - if (!(gb->io_registers[GB_IO_LCDC] & 2) && !GB_is_cgb(gb)) { + if (gb->object_fetch_aborted) { goto abort_fetching_object; } } @@ -924,18 +926,20 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_SLEEP(gb, display, 28, gb->extra_penalty_for_sprite_at_0); gb->extra_penalty_for_sprite_at_0 = 0; if (gb->object_fetch_aborted) { - gb->object_fetch_aborted = false; goto abort_fetching_object; } } } - gb->cycles_for_line += 6; - GB_SLEEP(gb, display, 20, 6); + gb->cycles_for_line += 5; + GB_SLEEP(gb, display, 20, 5); if (gb->object_fetch_aborted) { - gb->object_fetch_aborted = false; goto abort_fetching_object; } + gb->during_object_fetch = false; + gb->cycles_for_line++; + GB_SLEEP(gb, display, 39, 1); + /* TODO: what does the PPU read if DMA is active? */ const GB_object_t *object = &objects[gb->visible_objs[gb->n_visible_objs - 1]]; if (gb->oam_ppu_blocked) { @@ -973,6 +977,9 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } abort_fetching_object: + gb->object_fetch_aborted = false; + gb->during_object_fetch = false; + /* Handle window */ /* Todo: Timing (Including penalty and access timings) not verified by test ROM */ if (!gb->in_window && window_enabled(gb) && diff --git a/Core/gb.h b/Core/gb.h index 4e31e00..11bd10e 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -519,6 +519,7 @@ struct GB_gameboy_internal_s { bool vram_ppu_blocked; bool cgb_palettes_ppu_blocked; bool object_fetch_aborted; + bool during_object_fetch; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 1dbfc5e..4caaa34 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -19,6 +19,7 @@ typedef enum { GB_CONFLICT_PALETTE_DMG, GB_CONFLICT_PALETTE_CGB, GB_CONFLICT_DMG_LCDC, + GB_CONFLICT_SGB_LCDC, } GB_conflict_t; /* Todo: How does double speed mode affect these? */ @@ -56,7 +57,7 @@ static const GB_conflict_t dmg_conflict_map[0x80] = { static const GB_conflict_t sgb_conflict_map[0x80] = { [GB_IO_IF] = GB_CONFLICT_WRITE_CPU, [GB_IO_LYC] = GB_CONFLICT_READ_OLD, - [GB_IO_LCDC] = GB_CONFLICT_READ_NEW, + [GB_IO_LCDC] = GB_CONFLICT_SGB_LCDC, [GB_IO_SCY] = GB_CONFLICT_READ_NEW, [GB_IO_STAT] = GB_CONFLICT_STAT_DMG, @@ -207,16 +208,9 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) uint8_t old_value = GB_read_memory(gb, addr); GB_advance_cycles(gb, gb->pending_cycles - 2); - if (gb->current_lcd_line == 108) { - - } - /* Handle disabling objects while already fetching an object */ if ((old_value & 2) && !(value & 2)) { - if (gb->display_state == 27) { - old_value &= ~2; - } - else if (gb->display_state == 20 || gb->display_state == 28) { + if (gb->during_object_fetch) { gb->cycles_for_line -= gb->display_cycles; gb->display_cycles = 0; gb->object_fetch_aborted = true; @@ -231,10 +225,34 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) GB_advance_cycles(gb, 1); /* Handle disabling objects while already fetching an object */ if ((old_value & 2) && !(value & 2)) { - if (gb->display_state == 27) { - old_value &= ~2; + if (gb->during_object_fetch) { + gb->cycles_for_line -= gb->display_cycles; + gb->display_cycles = 0; + gb->object_fetch_aborted = true; } - else if (gb->display_state == 20 || gb->display_state == 28) { + } + GB_write_memory(gb, addr, value); + gb->pending_cycles = 5; + return; + } + + case GB_CONFLICT_SGB_LCDC: { + /* Simplified version of the above */ + + uint8_t old_value = GB_read_memory(gb, addr); + GB_advance_cycles(gb, gb->pending_cycles - 2); + /* Handle disabling objects while already fetching an object */ + if ((old_value & 2) && !(value & 2)) { + if (gb->during_object_fetch) { + gb->cycles_for_line -= gb->display_cycles; + gb->display_cycles = 0; + gb->object_fetch_aborted = true; + } + } + GB_advance_cycles(gb, 1); + /* Handle disabling objects while already fetching an object */ + if ((old_value & 2) && !(value & 2)) { + if (gb->during_object_fetch) { gb->cycles_for_line -= gb->display_cycles; gb->display_cycles = 0; gb->object_fetch_aborted = true; From 8409d3bcfb345f0c510ec2975266b6e22c562a9e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 16:43:51 +0200 Subject: [PATCH 023/125] Emulate changing sprite height mid-fetch --- Core/display.c | 61 ++++++++++++++++++++++++++++++----------------- Core/gb.h | 1 + Core/save_state.c | 2 ++ 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/Core/display.c b/Core/display.c index 7523f6d..c79e8bd 100644 --- a/Core/display.c +++ b/Core/display.c @@ -680,6 +680,30 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_state &= 7; } +static uint16_t get_object_line_address(GB_gameboy_t *gb, const GB_object_t *object) +{ + /* TODO: what does the PPU read if DMA is active? */ + if (gb->oam_ppu_blocked) { + static const GB_object_t blocked = {0xFF, 0xFF, 0xFF, 0xFF}; + object = &blocked; + } + + bool height_16 = (gb->io_registers[GB_IO_LCDC] & 4) != 0; /* Todo: Which T-cycle actually reads this? */ + uint8_t tile_y = (gb->current_line - object->y) & (height_16? 0xF : 7); + + if (object->flags & 0x40) { /* Flip Y */ + tile_y ^= height_16? 0xF : 7; + } + + /* Todo: I'm not 100% sure an access to OAM can't trigger the OAM bug while we're accessing this */ + uint16_t line_address = (height_16? object->tile & 0xFE : object->tile) * 0x10 + tile_y * 2; + + if (gb->cgb_mode && (object->flags & 0x8)) { /* Use VRAM bank 2 */ + line_address += 0x2000; + } + return line_address; +} + /* TODO: It seems that the STAT register's mode bits are always "late" by 4 T-cycles. The PPU logic can be greatly simplified if that delay is simply emulated. @@ -736,6 +760,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_STATE(gb, display, 37); GB_STATE(gb, display, 38); GB_STATE(gb, display, 39); + GB_STATE(gb, display, 40); } @@ -931,42 +956,34 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } } - gb->cycles_for_line += 5; - GB_SLEEP(gb, display, 20, 5); + gb->cycles_for_line += 4; + GB_SLEEP(gb, display, 20, 4); if (gb->object_fetch_aborted) { goto abort_fetching_object; } - gb->during_object_fetch = false; + + gb->object_low_line_address = get_object_line_address(gb, &objects[gb->visible_objs[gb->n_visible_objs - 1]]); + gb->cycles_for_line++; GB_SLEEP(gb, display, 39, 1); + if (gb->object_fetch_aborted) { + goto abort_fetching_object; + } + + gb->during_object_fetch = false; + gb->cycles_for_line++; + GB_SLEEP(gb, display, 40, 1); - /* TODO: what does the PPU read if DMA is active? */ const GB_object_t *object = &objects[gb->visible_objs[gb->n_visible_objs - 1]]; - if (gb->oam_ppu_blocked) { - static const GB_object_t blocked = {0xFF, 0xFF, 0xFF, 0xFF}; - object = &blocked; - } - bool height_16 = (gb->io_registers[GB_IO_LCDC] & 4) != 0; /* Todo: Which T-cycle actually reads this? */ - uint8_t tile_y = (gb->current_line - object->y) & (height_16? 0xF : 7); - - if (object->flags & 0x40) { /* Flip Y */ - tile_y ^= height_16? 0xF : 7; - } - - /* Todo: I'm not 100% sure an access to OAM can't trigger the OAM bug while we're accessing this */ - uint16_t line_address = (height_16? object->tile & 0xFE : object->tile) * 0x10 + tile_y * 2; - - if (gb->cgb_mode && (object->flags & 0x8)) { /* Use VRAM bank 2 */ - line_address += 0x2000; - } + uint16_t line_address = get_object_line_address(gb, object); uint8_t palette = (object->flags & 0x10) ? 1 : 0; if (gb->cgb_mode) { palette = object->flags & 0x7; } fifo_overlay_object_row(&gb->oam_fifo, - gb->vram_ppu_blocked? 0xFF : gb->vram[line_address], + gb->vram_ppu_blocked? 0xFF : gb->vram[gb->object_low_line_address], gb->vram_ppu_blocked? 0xFF : gb->vram[line_address + 1], palette, object->flags & 0x80, diff --git a/Core/gb.h b/Core/gb.h index 11bd10e..f44b967 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -520,6 +520,7 @@ struct GB_gameboy_internal_s { bool cgb_palettes_ppu_blocked; bool object_fetch_aborted; bool during_object_fetch; + uint16_t object_low_line_address; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/Core/save_state.c b/Core/save_state.c index 931a319..a0d88c2 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -265,6 +265,7 @@ int GB_load_state(GB_gameboy_t *gb, const char *path) gb->bg_fifo.write_end &= 0xF; gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.write_end &= 0xF; + gb->object_low_line_address &= gb->vram_size & ~1; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; @@ -374,6 +375,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le gb->bg_fifo.write_end &= 0xF; gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.write_end &= 0xF; + gb->object_low_line_address &= gb->vram_size & ~1; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; From f86e682d2c225b44d30e71b02485c8116bde93fb Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 17:22:57 +0200 Subject: [PATCH 024/125] Fix sign --- Core/sm83_cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 4caaa34..49115c7 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -211,7 +211,7 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) /* Handle disabling objects while already fetching an object */ if ((old_value & 2) && !(value & 2)) { if (gb->during_object_fetch) { - gb->cycles_for_line -= gb->display_cycles; + gb->cycles_for_line += gb->display_cycles; gb->display_cycles = 0; gb->object_fetch_aborted = true; } @@ -226,7 +226,7 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) /* Handle disabling objects while already fetching an object */ if ((old_value & 2) && !(value & 2)) { if (gb->during_object_fetch) { - gb->cycles_for_line -= gb->display_cycles; + gb->cycles_for_line += gb->display_cycles; gb->display_cycles = 0; gb->object_fetch_aborted = true; } @@ -244,7 +244,7 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) /* Handle disabling objects while already fetching an object */ if ((old_value & 2) && !(value & 2)) { if (gb->during_object_fetch) { - gb->cycles_for_line -= gb->display_cycles; + gb->cycles_for_line += gb->display_cycles; gb->display_cycles = 0; gb->object_fetch_aborted = true; } @@ -253,7 +253,7 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) /* Handle disabling objects while already fetching an object */ if ((old_value & 2) && !(value & 2)) { if (gb->during_object_fetch) { - gb->cycles_for_line -= gb->display_cycles; + gb->cycles_for_line += gb->display_cycles; gb->display_cycles = 0; gb->object_fetch_aborted = true; } From ea2f32b255aa1a31abab207f824c72a6f6d20639 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 21:44:44 +0200 Subject: [PATCH 025/125] The fetcher state machine advances even while handling an object --- Core/display.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index c79e8bd..13bd955 100644 --- a/Core/display.c +++ b/Core/display.c @@ -761,6 +761,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_STATE(gb, display, 38); GB_STATE(gb, display, 39); GB_STATE(gb, display, 40); + GB_STATE(gb, display, 41); } @@ -956,8 +957,16 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } } - gb->cycles_for_line += 4; - GB_SLEEP(gb, display, 20, 4); + advance_fetcher_state_machine(gb); + gb->cycles_for_line++; + GB_SLEEP(gb, display, 41, 1); + if (gb->object_fetch_aborted) { + goto abort_fetching_object; + } + advance_fetcher_state_machine(gb); + + gb->cycles_for_line += 3; + GB_SLEEP(gb, display, 20, 3); if (gb->object_fetch_aborted) { goto abort_fetching_object; } From 39b88d546ba4c180683e32367e47ab895a9ba192 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 21 Feb 2020 21:59:03 +0200 Subject: [PATCH 026/125] The upper bits of SCX might mid-line --- Core/display.c | 6 ++++-- Core/save_state.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index 13bd955..62e2acd 100644 --- a/Core/display.c +++ b/Core/display.c @@ -581,18 +581,20 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ uint8_t y = fetcher_y(gb); + uint8_t x = gb->in_window? gb->fetcher_x : + (((gb->io_registers[GB_IO_SCX] / 8) + (gb->position_in_line / 8) + 1) & 0x1F); if (gb->model > GB_MODEL_CGB_C) { /* This value is cached on the CGB-D and newer, so it cannot be used to mix tiles together */ gb->fetcher_y = y; } - gb->current_tile = gb->vram[map + gb->fetcher_x + y / 8 * 32]; + gb->current_tile = gb->vram[map + x + y / 8 * 32]; if (gb->vram_ppu_blocked) { gb->current_tile = 0xFF; } if (GB_is_cgb(gb)) { /* The CGB actually accesses both the tile index AND the attributes in the same T-cycle. This probably means the CGB has a 16-bit data bus for the VRAM. */ - gb->current_tile_attributes = gb->vram[map + gb->fetcher_x + y / 8 * 32 + 0x2000]; + gb->current_tile_attributes = gb->vram[map + x + y / 8 * 32 + 0x2000]; if (gb->vram_ppu_blocked) { gb->current_tile_attributes = 0xFF; } diff --git a/Core/save_state.c b/Core/save_state.c index a0d88c2..8f10152 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -266,6 +266,7 @@ int GB_load_state(GB_gameboy_t *gb, const char *path) gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.write_end &= 0xF; gb->object_low_line_address &= gb->vram_size & ~1; + gb->fetcher_x &= 0x1f; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; @@ -376,6 +377,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le gb->oam_fifo.read_end &= 0xF; gb->oam_fifo.write_end &= 0xF; gb->object_low_line_address &= gb->vram_size & ~1; + gb->fetcher_x &= 0x1f; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; From d8282fe3c9d79533b4feefd3e39db189519c3784 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 22 Feb 2020 00:45:52 +0200 Subject: [PATCH 027/125] Please pretend the last commit never happened --- Core/display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index 62e2acd..14071b1 100644 --- a/Core/display.c +++ b/Core/display.c @@ -582,7 +582,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ uint8_t y = fetcher_y(gb); uint8_t x = gb->in_window? gb->fetcher_x : - (((gb->io_registers[GB_IO_SCX] / 8) + (gb->position_in_line / 8) + 1) & 0x1F); + (((gb->io_registers[GB_IO_SCX] / 8) + gb->fetcher_x) & 0x1F); if (gb->model > GB_MODEL_CGB_C) { /* This value is cached on the CGB-D and newer, so it cannot be used to mix tiles together */ gb->fetcher_y = y; @@ -914,7 +914,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) /* Todo: find out actual access time of SCX */ gb->position_in_line = - (gb->io_registers[GB_IO_SCX] & 7) - 8; - gb->fetcher_x = ((gb->io_registers[GB_IO_SCX]) / 8) & 0x1f; + gb->fetcher_x = 0; gb->extra_penalty_for_sprite_at_0 = (gb->io_registers[GB_IO_SCX] & 7); From 83ea4edce295b467f9d00fb42acf7da29bd366eb Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 23 Feb 2020 00:16:15 +0200 Subject: [PATCH 028/125] Shut up, annoying log message --- Cocoa/Document.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index df15806..0418c56 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -1005,7 +1005,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) { CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef) data); CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); - CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; + CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGImageRef iref = CGImageCreate(width, From 2be58439bfba66e89655188cdac9aec9ed57ba54 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 23 Feb 2020 00:38:47 +0200 Subject: [PATCH 029/125] =?UTF-8?q?Starting=20over=20=E2=80=93=20removing?= =?UTF-8?q?=20all=20window=20related=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/display.c | 68 +++++--------------------------------------------- Core/display.h | 1 - Core/gb.h | 6 ++--- Core/memory.c | 5 +--- 4 files changed, 10 insertions(+), 70 deletions(-) diff --git a/Core/display.c b/Core/display.c index 14071b1..956bf80 100644 --- a/Core/display.c +++ b/Core/display.c @@ -111,16 +111,6 @@ typedef struct __attribute__((packed)) { uint8_t flags; } GB_object_t; -static bool window_enabled(GB_gameboy_t *gb) -{ - if ((gb->io_registers[GB_IO_LCDC] & 0x1) == 0) { - if (!gb->cgb_mode) { - return false; - } - } - return (gb->io_registers[GB_IO_LCDC] & 0x20) && gb->io_registers[GB_IO_WX] < 167; -} - static void display_vblank(GB_gameboy_t *gb) { gb->vblank_just_occured = true; @@ -388,9 +378,6 @@ void GB_lcd_off(GB_gameboy_t *gb) gb->vram_write_blocked = false; gb->cgb_palettes_blocked = false; - /* Reset window rendering state */ - gb->wy_diff = 0; - gb->window_disabled_while_active = false; gb->current_line = 0; gb->ly_for_comparison = 0; @@ -543,7 +530,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) static inline uint8_t fetcher_y(GB_gameboy_t *gb) { - return gb->current_line + (gb->in_window? - gb->io_registers[GB_IO_WY] - gb->wy_diff : gb->io_registers[GB_IO_SCY]); + return gb->current_line + gb->io_registers[GB_IO_SCY]; } static void advance_fetcher_state_machine(GB_gameboy_t *gb) @@ -572,17 +559,16 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) uint16_t map = 0x1800; /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ - if (gb->io_registers[GB_IO_LCDC] & 0x08 && !gb->in_window) { + if (gb->io_registers[GB_IO_LCDC] & 0x08 /* && !gb->in_window */) { map = 0x1C00; } - else if (gb->io_registers[GB_IO_LCDC] & 0x40 && gb->in_window) { + /* else if (gb->io_registers[GB_IO_LCDC] & 0x40 && gb->in_window) { map = 0x1C00; - } + } */ /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ uint8_t y = fetcher_y(gb); - uint8_t x = gb->in_window? gb->fetcher_x : - (((gb->io_registers[GB_IO_SCX] / 8) + gb->fetcher_x) & 0x1F); + uint8_t x = ((gb->io_registers[GB_IO_SCX] / 8) + gb->fetcher_x) & 0x1F; if (gb->model > GB_MODEL_CGB_C) { /* This value is cached on the CGB-D and newer, so it cannot be used to mix tiles together */ gb->fetcher_y = y; @@ -922,7 +908,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->fetcher_state = 0; gb->bg_fifo_paused = false; gb->oam_fifo_paused = false; - gb->in_window = false; while (true) { /* Handle objects */ /* When the sprite enabled bit is off, this proccess is skipped entirely on the DMG, but not on the CGB. @@ -1009,17 +994,7 @@ abort_fetching_object: gb->during_object_fetch = false; /* Handle window */ - /* Todo: Timing (Including penalty and access timings) not verified by test ROM */ - if (!gb->in_window && window_enabled(gb) && - gb->current_line >= gb->io_registers[GB_IO_WY] + gb->wy_diff && - (uint8_t)(gb->position_in_line + 7) == gb->io_registers[GB_IO_WX]) { - gb->in_window = true; - fifo_clear(&gb->bg_fifo); - gb->bg_fifo_paused = true; - gb->oam_fifo_paused = true; - gb->fetcher_x = 0; - gb->fetcher_state = 0; - } + /* TBD */ render_pixel_if_possible(gb); advance_fetcher_state_machine(gb); @@ -1154,9 +1129,6 @@ abort_fetching_object: GB_SLEEP(gb, display, 17, LINE_LENGTH - 24); - /* Reset window rendering state */ - gb->wy_diff = 0; - gb->window_disabled_while_active = false; gb->current_line = 0; // TODO: not the correct timing gb->current_lcd_line = 0; @@ -1343,31 +1315,3 @@ uint8_t GB_get_oam_info(GB_gameboy_t *gb, GB_oam_info_t *dest, uint8_t *sprite_h } return count; } - -/* Called when a write might enable or disable the window */ -void GB_window_related_write(GB_gameboy_t *gb, uint8_t addr, uint8_t value) -{ - bool before = window_enabled(gb); - gb->io_registers[addr] = value; - bool after = window_enabled(gb); - - if (before != after && gb->current_line < LINES) { - /* Window was disabled or enabled outside of vblank */ - if (gb->current_line >= gb->io_registers[GB_IO_WY]) { - if (after) { - if (!gb->window_disabled_while_active) { - /* Window was turned on for the first time this frame while LY > WY, - should start window in the next line */ - gb->wy_diff = gb->current_line + 1 - gb->io_registers[GB_IO_WY]; - } - else { - gb->wy_diff += gb->current_line; - } - } - else { - gb->wy_diff -= gb->current_line; - gb->window_disabled_while_active = true; - } - } - } -} diff --git a/Core/display.h b/Core/display.h index b9e3149..d539881 100644 --- a/Core/display.h +++ b/Core/display.h @@ -8,7 +8,6 @@ #ifdef GB_INTERNAL void GB_display_run(GB_gameboy_t *gb, uint8_t cycles); void GB_palette_changed(GB_gameboy_t *gb, bool background_palette, uint8_t index); -void GB_window_related_write(GB_gameboy_t *gb, uint8_t addr, uint8_t value); void GB_STAT_update(GB_gameboy_t *gb); void GB_lcd_off(GB_gameboy_t *gb); diff --git a/Core/gb.h b/Core/gb.h index f44b967..ccced99 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -472,7 +472,7 @@ struct GB_gameboy_internal_s { uint8_t position_in_line; bool stat_interrupt_line; uint8_t effective_scx; - uint8_t wy_diff; + GB_PADDING(uint8_t,wy_diff); /* The LCDC will skip the first frame it renders after turning it on. On the CGB, a frame is not skipped if the previous frame was skipped as well. See https://www.reddit.com/r/EmuDev/comments/6exyxu/ */ @@ -489,7 +489,7 @@ struct GB_gameboy_internal_s { bool vram_read_blocked; bool oam_write_blocked; bool vram_write_blocked; - bool window_disabled_while_active; + GB_PADDING(bool, window_disabled_while_active); uint8_t current_line; uint16_t ly_for_comparison; GB_fifo_t bg_fifo, oam_fifo; @@ -502,7 +502,7 @@ struct GB_gameboy_internal_s { uint8_t fetcher_state; bool bg_fifo_paused; bool oam_fifo_paused; - bool in_window; + GB_PADDING(bool, in_window); uint8_t visible_objs[10]; uint8_t obj_comparators[10]; uint8_t n_visible_objs; diff --git a/Core/memory.c b/Core/memory.c index 8e254bc..e1dd2d1 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -646,8 +646,6 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) /* Hardware registers */ switch (addr & 0xFF) { case GB_IO_WX: - GB_window_related_write(gb, addr & 0xFF, value); - break; case GB_IO_IF: case GB_IO_SCX: case GB_IO_SCY: @@ -740,8 +738,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) GB_timing_sync(gb); GB_lcd_off(gb); } - /* Writing to LCDC might enable to disable the window, so we write it via GB_window_related_write */ - GB_window_related_write(gb, addr & 0xFF, value); + gb->io_registers[GB_IO_LCDC] = value; return; case GB_IO_STAT: From c0ba898ef2ae7197796fa6b0aaf64a19b108fbfb Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 23 Feb 2020 23:16:45 +0200 Subject: [PATCH 030/125] Basic window implementation --- Core/display.c | 78 ++++++++++++++++++++++++++++++++++++++++++++------ Core/gb.h | 6 ++-- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/Core/display.c b/Core/display.c index 956bf80..cfbcb71 100644 --- a/Core/display.c +++ b/Core/display.c @@ -530,7 +530,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) static inline uint8_t fetcher_y(GB_gameboy_t *gb) { - return gb->current_line + gb->io_registers[GB_IO_SCY]; + return gb->wx_triggered? gb->window_y : gb->current_line + gb->io_registers[GB_IO_SCY]; } static void advance_fetcher_state_machine(GB_gameboy_t *gb) @@ -539,6 +539,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_GET_TILE, GB_FETCHER_GET_TILE_DATA_LOWER, GB_FETCHER_GET_TILE_DATA_HIGH, + GB_ADVANCE_TILES, GB_FETCHER_PUSH, GB_FETCHER_SLEEP, } fetcher_step_t; @@ -550,7 +551,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_GET_TILE_DATA_LOWER, GB_FETCHER_SLEEP, GB_FETCHER_GET_TILE_DATA_HIGH, - GB_FETCHER_SLEEP, + GB_ADVANCE_TILES, GB_FETCHER_PUSH, }; @@ -558,17 +559,27 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) case GB_FETCHER_GET_TILE: { uint16_t map = 0x1800; + if (!(gb->io_registers[GB_IO_LCDC] & 0x20)) { + gb->wx_triggered = false; + } + /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ - if (gb->io_registers[GB_IO_LCDC] & 0x08 /* && !gb->in_window */) { + if (gb->io_registers[GB_IO_LCDC] & 0x08 && !gb->wx_triggered) { map = 0x1C00; } - /* else if (gb->io_registers[GB_IO_LCDC] & 0x40 && gb->in_window) { + else if (gb->io_registers[GB_IO_LCDC] & 0x40 && gb->wx_triggered) { map = 0x1C00; - } */ + } /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ uint8_t y = fetcher_y(gb); - uint8_t x = ((gb->io_registers[GB_IO_SCX] / 8) + gb->fetcher_x) & 0x1F; + uint8_t x = 0; + if (gb->wx_triggered) { + x = gb->window_tile_x; + } + else { + x = ((gb->io_registers[GB_IO_SCX] / 8) + gb->fetcher_x) & 0x1F; + } if (gb->model > GB_MODEL_CGB_C) { /* This value is cached on the CGB-D and newer, so it cannot be used to mix tiles together */ gb->fetcher_y = y; @@ -585,8 +596,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->current_tile_attributes = 0xFF; } } - gb->fetcher_x++; - gb->fetcher_x &= 0x1f; } gb->fetcher_state++; break; @@ -648,6 +657,19 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_state++; break; + case GB_ADVANCE_TILES: { + if (gb->wx_triggered) { + gb->window_tile_x++; + gb->window_tile_x &= 0x1f; + } + else { + gb->fetcher_x++; + gb->fetcher_x &= 0x1f; + } + gb->fetcher_state++; + } + + case GB_FETCHER_PUSH: { if (fifo_size(&gb->bg_fifo) > 0) break; fifo_push_bg_row(&gb->bg_fifo, gb->current_tile_data[0], gb->current_tile_data[1], @@ -767,6 +789,15 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) /* Handle mode 2 on the very first line 0 */ gb->current_line = 0; + gb->window_y = -1; + /* Todo: verify timings */ + if (gb->io_registers[GB_IO_WY] == 0) { + gb->wy_triggered = true; + } + else { + gb->wy_triggered = false; + } + gb->ly_for_comparison = 0; gb->io_registers[GB_IO_STAT] &= ~3; gb->mode_for_interrupt = -1; @@ -813,7 +844,16 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) while (true) { /* Lines 0 - 143 */ + gb->window_y = -1; for (; gb->current_line < LINES; gb->current_line++) { + gb->wx_triggered = false; + /* Todo: verify timings */ + if ((gb->io_registers[GB_IO_WY] == gb->current_line || + (gb->current_line != 0 && gb->io_registers[GB_IO_WY] == gb->current_line - 1))) { + gb->wy_triggered = true; + } + gb->window_tile_x = 0; + gb->oam_write_blocked = GB_is_cgb(gb) && !gb->cgb_double_speed; gb->accessed_oam_row = 0; @@ -994,7 +1034,18 @@ abort_fetching_object: gb->during_object_fetch = false; /* Handle window */ - /* TBD */ + /* Todo: verify timings */ + if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { + if (gb->io_registers[GB_IO_WX] == gb->position_in_line + 7 || + gb->io_registers[GB_IO_WX] == gb->position_in_line + 6) { + gb->wx_triggered = true; + gb->window_y++; + fifo_clear(&gb->bg_fifo); + gb->bg_fifo_paused = true; + gb->oam_fifo_paused = true; + gb->fetcher_state = 0; + } + } render_pixel_if_possible(gb); advance_fetcher_state_machine(gb); @@ -1130,6 +1181,15 @@ abort_fetching_object: gb->current_line = 0; + /* Todo: verify timings */ + if ((gb->io_registers[GB_IO_LCDC] & 0x20) && + (gb->io_registers[GB_IO_WY] == 0)) { + gb->wy_triggered = true; + } + else { + gb->wy_triggered = false; + } + // TODO: not the correct timing gb->current_lcd_line = 0; if (gb->icd_vreset_callback) { diff --git a/Core/gb.h b/Core/gb.h index ccced99..e02c7ad 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -472,7 +472,7 @@ struct GB_gameboy_internal_s { uint8_t position_in_line; bool stat_interrupt_line; uint8_t effective_scx; - GB_PADDING(uint8_t,wy_diff); + uint8_t window_y; /* The LCDC will skip the first frame it renders after turning it on. On the CGB, a frame is not skipped if the previous frame was skipped as well. See https://www.reddit.com/r/EmuDev/comments/6exyxu/ */ @@ -502,7 +502,7 @@ struct GB_gameboy_internal_s { uint8_t fetcher_state; bool bg_fifo_paused; bool oam_fifo_paused; - GB_PADDING(bool, in_window); + bool wx_triggered; uint8_t visible_objs[10]; uint8_t obj_comparators[10]; uint8_t n_visible_objs; @@ -521,6 +521,8 @@ struct GB_gameboy_internal_s { bool object_fetch_aborted; bool during_object_fetch; uint16_t object_low_line_address; + bool wy_triggered; + uint8_t window_tile_x; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ From c22611c7010caf470156a0d1494c7dc454e4b346 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 23 Feb 2020 23:48:08 +0200 Subject: [PATCH 031/125] Minor bugfix --- Core/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/display.c b/Core/display.c index cfbcb71..6ecbf95 100644 --- a/Core/display.c +++ b/Core/display.c @@ -839,8 +839,8 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->vram_read_blocked = true; gb->vram_write_blocked = true; + gb->wx_triggered = false; goto mode_3_start; - while (true) { /* Lines 0 - 143 */ From 3864ff37e100041e7787920012a286f7509557b6 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 24 Feb 2020 00:20:58 +0200 Subject: [PATCH 032/125] Timing improvements --- Core/display.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Core/display.c b/Core/display.c index 6ecbf95..018b581 100644 --- a/Core/display.c +++ b/Core/display.c @@ -539,7 +539,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_GET_TILE, GB_FETCHER_GET_TILE_DATA_LOWER, GB_FETCHER_GET_TILE_DATA_HIGH, - GB_ADVANCE_TILES, GB_FETCHER_PUSH, GB_FETCHER_SLEEP, } fetcher_step_t; @@ -551,8 +550,8 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_GET_TILE_DATA_LOWER, GB_FETCHER_SLEEP, GB_FETCHER_GET_TILE_DATA_HIGH, - GB_ADVANCE_TILES, GB_FETCHER_PUSH, + GB_FETCHER_PUSH, // Compatibility }; switch (fetcher_state_machine[gb->fetcher_state]) { @@ -657,7 +656,10 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_state++; break; - case GB_ADVANCE_TILES: { + + case GB_FETCHER_PUSH: { + if (fifo_size(&gb->bg_fifo) > 0) break; + if (gb->wx_triggered) { gb->window_tile_x++; gb->window_tile_x &= 0x1f; @@ -666,17 +668,12 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_x++; gb->fetcher_x &= 0x1f; } - gb->fetcher_state++; - } - - case GB_FETCHER_PUSH: { - if (fifo_size(&gb->bg_fifo) > 0) break; fifo_push_bg_row(&gb->bg_fifo, gb->current_tile_data[0], gb->current_tile_data[1], gb->current_tile_attributes & 7, gb->current_tile_attributes & 0x80, gb->current_tile_attributes & 0x20); gb->bg_fifo_paused = false; gb->oam_fifo_paused = false; - gb->fetcher_state++; + gb->fetcher_state = 0; } break; @@ -984,12 +981,15 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } } + /* TODO: Can this be deleted? { */ advance_fetcher_state_machine(gb); gb->cycles_for_line++; GB_SLEEP(gb, display, 41, 1); if (gb->object_fetch_aborted) { goto abort_fetching_object; } + /* } */ + advance_fetcher_state_machine(gb); gb->cycles_for_line += 3; @@ -1036,8 +1036,11 @@ abort_fetching_object: /* Handle window */ /* Todo: verify timings */ if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { - if (gb->io_registers[GB_IO_WX] == gb->position_in_line + 7 || - gb->io_registers[GB_IO_WX] == gb->position_in_line + 6) { + if (gb->io_registers[GB_IO_WX] >= 166) { + // Too late to enable the window + } + else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || + gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6)) { gb->wx_triggered = true; gb->window_y++; fifo_clear(&gb->bg_fifo); From 25b51362e9fcfd1b70615051cea05541be750e74 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 24 Feb 2020 00:33:45 +0200 Subject: [PATCH 033/125] Safety first --- Core/save_state.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/save_state.c b/Core/save_state.c index 8f10152..fd7d814 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -267,6 +267,7 @@ int GB_load_state(GB_gameboy_t *gb, const char *path) gb->oam_fifo.write_end &= 0xF; gb->object_low_line_address &= gb->vram_size & ~1; gb->fetcher_x &= 0x1f; + gb->fetcher_state &= 7; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; @@ -378,6 +379,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le gb->oam_fifo.write_end &= 0xF; gb->object_low_line_address &= gb->vram_size & ~1; gb->fetcher_x &= 0x1f; + gb->fetcher_state &= 7; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; From 248e7bc332eb3799d082e3c41f94a982009a6dec Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 24 Feb 2020 20:46:00 +0200 Subject: [PATCH 034/125] Timing improvements --- Core/display.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/display.c b/Core/display.c index 018b581..b4d9f83 100644 --- a/Core/display.c +++ b/Core/display.c @@ -831,8 +831,8 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_SLEEP(gb, display, 37, 2); gb->cgb_palettes_blocked = true; - gb->cycles_for_line += 2; - GB_SLEEP(gb, display, 38, 2); + gb->cycles_for_line += 3; + GB_SLEEP(gb, display, 38, 3); gb->vram_read_blocked = true; gb->vram_write_blocked = true; @@ -1046,7 +1046,7 @@ abort_fetching_object: fifo_clear(&gb->bg_fifo); gb->bg_fifo_paused = true; gb->oam_fifo_paused = true; - gb->fetcher_state = 0; + gb->fetcher_state = 1; } } From 7456beb7b9ee08465ac13400d73aebbc408ce413 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 24 Feb 2020 21:23:06 +0200 Subject: [PATCH 035/125] Better emulation of negative WX positions --- Core/display.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/display.c b/Core/display.c index b4d9f83..2161328 100644 --- a/Core/display.c +++ b/Core/display.c @@ -434,12 +434,13 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } } + if (gb->bg_fifo_paused) return; + /* Drop pixels for scrollings */ if (gb->position_in_line >= 160 || (gb->disable_rendering && !gb->sgb)) { gb->position_in_line++; return; } - if (gb->bg_fifo_paused) return; /* Mixing */ From b37a0b285a4c31013df7d0f1990a97391687ae0f Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 24 Feb 2020 23:59:18 +0200 Subject: [PATCH 036/125] Window Y still advances if WX=166 --- Core/display.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Core/display.c b/Core/display.c index 2161328..c9ca8ce 100644 --- a/Core/display.c +++ b/Core/display.c @@ -1037,17 +1037,19 @@ abort_fetching_object: /* Handle window */ /* Todo: verify timings */ if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { - if (gb->io_registers[GB_IO_WX] >= 166) { + if (gb->io_registers[GB_IO_WX] >= 167) { // Too late to enable the window } else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6)) { - gb->wx_triggered = true; + gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6)) { gb->window_y++; - fifo_clear(&gb->bg_fifo); - gb->bg_fifo_paused = true; - gb->oam_fifo_paused = true; - gb->fetcher_state = 1; + if (gb->io_registers[GB_IO_WX] != 166) { + gb->wx_triggered = true; + fifo_clear(&gb->bg_fifo); + gb->bg_fifo_paused = true; + gb->oam_fifo_paused = true; + gb->fetcher_state = 1; + } } } From 9c7a8fdb1bf2e2fdf09aa2f0831ff406107ff271 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 26 Feb 2020 22:24:08 +0200 Subject: [PATCH 037/125] WY is tested every cycle --- Core/display.c | 1 + Core/memory.c | 5 ++++- Core/sm83_cpu.c | 9 ++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Core/display.c b/Core/display.c index c9ca8ce..908c551 100644 --- a/Core/display.c +++ b/Core/display.c @@ -382,6 +382,7 @@ void GB_lcd_off(GB_gameboy_t *gb) gb->ly_for_comparison = 0; gb->accessed_oam_row = -1; + gb->wy_triggered = false; } static void add_object_from_index(GB_gameboy_t *gb, unsigned index) diff --git a/Core/memory.c b/Core/memory.c index e1dd2d1..631b71f 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -645,6 +645,10 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) if (addr < 0xFF80) { /* Hardware registers */ switch (addr & 0xFF) { + case GB_IO_WY: + if (value == gb->current_line) { + gb->wy_triggered = true; + } case GB_IO_WX: case GB_IO_IF: case GB_IO_SCX: @@ -652,7 +656,6 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) case GB_IO_BGP: case GB_IO_OBP0: case GB_IO_OBP1: - case GB_IO_WY: case GB_IO_SB: case GB_IO_UNKNOWN2: case GB_IO_UNKNOWN3: diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 49115c7..b0e28f4 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -31,7 +31,6 @@ static const GB_conflict_t cgb_conflict_map[0x80] = { [GB_IO_OBP0] = GB_CONFLICT_PALETTE_CGB, [GB_IO_OBP1] = GB_CONFLICT_PALETTE_CGB, - /* Todo: most values not verified, and probably differ between revisions */ }; @@ -46,9 +45,9 @@ static const GB_conflict_t dmg_conflict_map[0x80] = { [GB_IO_BGP] = GB_CONFLICT_PALETTE_DMG, [GB_IO_OBP0] = GB_CONFLICT_PALETTE_DMG, [GB_IO_OBP1] = GB_CONFLICT_PALETTE_DMG, - + [GB_IO_WY] = GB_CONFLICT_READ_OLD, + /* Todo: these were not verified at all */ - [GB_IO_WY] = GB_CONFLICT_READ_NEW, [GB_IO_WX] = GB_CONFLICT_READ_NEW, [GB_IO_SCX] = GB_CONFLICT_READ_NEW, }; @@ -64,9 +63,9 @@ static const GB_conflict_t sgb_conflict_map[0x80] = { [GB_IO_BGP] = GB_CONFLICT_READ_NEW, [GB_IO_OBP0] = GB_CONFLICT_READ_NEW, [GB_IO_OBP1] = GB_CONFLICT_READ_NEW, - + [GB_IO_WY] = GB_CONFLICT_READ_OLD, + /* Todo: these were not verified at all */ - [GB_IO_WY] = GB_CONFLICT_READ_NEW, [GB_IO_WX] = GB_CONFLICT_READ_NEW, [GB_IO_SCX] = GB_CONFLICT_READ_NEW, }; From 89303ab04652fe147559772ed2b54016e08f1655 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 27 Feb 2020 00:12:42 +0200 Subject: [PATCH 038/125] WX access conflicts --- Core/display.c | 2 +- Core/gb.h | 3 +++ Core/sm83_cpu.c | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Core/display.c b/Core/display.c index 908c551..256d981 100644 --- a/Core/display.c +++ b/Core/display.c @@ -1042,7 +1042,7 @@ abort_fetching_object: // Too late to enable the window } else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6)) { + (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) { gb->window_y++; if (gb->io_registers[GB_IO_WX] != 166) { gb->wx_triggered = true; diff --git a/Core/gb.h b/Core/gb.h index e02c7ad..b8cbd97 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -651,6 +651,9 @@ struct GB_gameboy_internal_s { bool vblank_just_occured; // For slow operations involving syscalls; these should only run once per vblank uint8_t cycles_since_run; // How many cycles have passed since the last call to GB_run(), in 8MHz units double clock_multiplier; + + /* Temporary state */ + bool wx_just_changed; ); }; diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index b0e28f4..f25e14b 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -20,6 +20,7 @@ typedef enum { GB_CONFLICT_PALETTE_CGB, GB_CONFLICT_DMG_LCDC, GB_CONFLICT_SGB_LCDC, + GB_CONFLICT_WX, } GB_conflict_t; /* Todo: How does double speed mode affect these? */ @@ -46,9 +47,9 @@ static const GB_conflict_t dmg_conflict_map[0x80] = { [GB_IO_OBP0] = GB_CONFLICT_PALETTE_DMG, [GB_IO_OBP1] = GB_CONFLICT_PALETTE_DMG, [GB_IO_WY] = GB_CONFLICT_READ_OLD, + [GB_IO_WX] = GB_CONFLICT_WX, /* Todo: these were not verified at all */ - [GB_IO_WX] = GB_CONFLICT_READ_NEW, [GB_IO_SCX] = GB_CONFLICT_READ_NEW, }; @@ -64,9 +65,9 @@ static const GB_conflict_t sgb_conflict_map[0x80] = { [GB_IO_OBP0] = GB_CONFLICT_READ_NEW, [GB_IO_OBP1] = GB_CONFLICT_READ_NEW, [GB_IO_WY] = GB_CONFLICT_READ_OLD, + [GB_IO_WX] = GB_CONFLICT_WX, /* Todo: these were not verified at all */ - [GB_IO_WX] = GB_CONFLICT_READ_NEW, [GB_IO_SCX] = GB_CONFLICT_READ_NEW, }; @@ -261,6 +262,15 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) gb->pending_cycles = 5; return; } + + case GB_CONFLICT_WX: + GB_advance_cycles(gb, gb->pending_cycles); + GB_write_memory(gb, addr, value); + gb->wx_just_changed = true; + GB_advance_cycles(gb, 1); + gb->wx_just_changed = false; + gb->pending_cycles = 3; + return; } } From 67d5a53503eafae61f4639bf7d4cfb24499f496e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C4=85dzio=C5=82ka?= Date: Thu, 27 Feb 2020 18:11:10 +0100 Subject: [PATCH 039/125] Spell "length" properly --- Core/apu.c | 20 ++++++++++---------- Core/apu.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Core/apu.c b/Core/apu.c index 17aa452..c3be533 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -230,13 +230,13 @@ static void render(GB_gameboy_t *gb) gb->apu_output.sample_callback(gb, &filtered_output); } -static uint16_t new_sweep_sample_legnth(GB_gameboy_t *gb) +static uint16_t new_sweep_sample_length(GB_gameboy_t *gb) { - uint16_t delta = gb->apu.shadow_sweep_sample_legnth >> (gb->io_registers[GB_IO_NR10] & 7); + uint16_t delta = gb->apu.shadow_sweep_sample_length >> (gb->io_registers[GB_IO_NR10] & 7); if (gb->io_registers[GB_IO_NR10] & 8) { - return gb->apu.shadow_sweep_sample_legnth - delta; + return gb->apu.shadow_sweep_sample_length - delta; } - return gb->apu.shadow_sweep_sample_legnth + delta; + return gb->apu.shadow_sweep_sample_length + delta; } static void update_square_sample(GB_gameboy_t *gb, unsigned index) @@ -400,8 +400,8 @@ void GB_apu_div_event(GB_gameboy_t *gb) if (!--gb->apu.square_sweep_countdown) { if ((gb->io_registers[GB_IO_NR10] & 0x70) && (gb->io_registers[GB_IO_NR10] & 0x07)) { gb->apu.square_channels[GB_SQUARE_1].sample_length = - gb->apu.shadow_sweep_sample_legnth = - gb->apu.new_sweep_sample_legnth; + gb->apu.shadow_sweep_sample_length = + gb->apu.new_sweep_sample_length; } if (gb->io_registers[GB_IO_NR10] & 0x70) { @@ -435,8 +435,8 @@ void GB_apu_run(GB_gameboy_t *gb) } else { /* APU bug: sweep frequency is checked after adding the sweep delta twice */ - gb->apu.new_sweep_sample_legnth = new_sweep_sample_legnth(gb); - if (gb->apu.new_sweep_sample_legnth > 0x7ff) { + gb->apu.new_sweep_sample_length = new_sweep_sample_length(gb); + if (gb->apu.new_sweep_sample_length > 0x7ff) { gb->apu.is_active[GB_SQUARE_1] = false; update_sample(gb, GB_SQUARE_1, 0, gb->apu.square_sweep_calculate_countdown - cycles); gb->apu.sweep_enabled = false; @@ -724,8 +724,8 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) gb->apu.square_channels[index].sample_length &= 0xFF; gb->apu.square_channels[index].sample_length |= (value & 7) << 8; if (index == GB_SQUARE_1) { - gb->apu.shadow_sweep_sample_legnth = - gb->apu.new_sweep_sample_legnth = + gb->apu.shadow_sweep_sample_length = + gb->apu.new_sweep_sample_length = gb->apu.square_channels[0].sample_length; } if (value & 0x80) { diff --git a/Core/apu.h b/Core/apu.h index 933f14e..398b903 100644 --- a/Core/apu.h +++ b/Core/apu.h @@ -64,8 +64,8 @@ typedef struct uint8_t square_sweep_countdown; // In 128Hz uint8_t square_sweep_calculate_countdown; // In 2 MHz - uint16_t new_sweep_sample_legnth; - uint16_t shadow_sweep_sample_legnth; + uint16_t new_sweep_sample_length; + uint16_t shadow_sweep_sample_length; bool sweep_enabled; bool sweep_decreasing; From 0c716bd970540e57c35868eec6e33b2ad96e3ee6 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 27 Feb 2020 22:49:34 +0200 Subject: [PATCH 040/125] More accurate timing emulation of window-objects interaction --- Core/display.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/Core/display.c b/Core/display.c index 256d981..b4455fd 100644 --- a/Core/display.c +++ b/Core/display.c @@ -729,6 +729,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) return; } GB_object_t *objects = (GB_object_t *) &gb->oam; + bool window_got_activated = false; GB_STATE_MACHINE(gb, display, cycles, 2) { GB_STATE(gb, display, 1); @@ -771,6 +772,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_STATE(gb, display, 39); GB_STATE(gb, display, 40); GB_STATE(gb, display, 41); + GB_STATE(gb, display, 42); } @@ -948,6 +950,26 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->bg_fifo_paused = false; gb->oam_fifo_paused = false; while (true) { + /* Handle window */ + /* Todo: verify timings */ + if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { + if (gb->io_registers[GB_IO_WX] >= 167) { + // Too late to enable the window + } + else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || + (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) { + gb->window_y++; + if (gb->io_registers[GB_IO_WX] != 166) { + gb->wx_triggered = true; + fifo_clear(&gb->bg_fifo); + gb->bg_fifo_paused = true; + gb->oam_fifo_paused = true; + gb->fetcher_state = 1; + window_got_activated = true; + } + } + } + /* Handle objects */ /* When the sprite enabled bit is off, this proccess is skipped entirely on the DMG, but not on the CGB. On the CGB, this bit is checked only when the pixel is actually popped from the FIFO. */ @@ -962,6 +984,15 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) while (gb->n_visible_objs != 0 && (gb->io_registers[GB_IO_LCDC] & 2 || GB_is_cgb(gb)) && gb->obj_comparators[gb->n_visible_objs - 1] == (uint8_t)(gb->position_in_line + 8)) { + + /* TODO: This is wrong. It is only correct for a single object, not for more than one. */ + if (window_got_activated) { + window_got_activated = false; + gb->fetcher_state = 0; + gb->cycles_for_line += 6; + GB_SLEEP(gb, display, 42, 6); + } + while (gb->fetcher_state < 5) { advance_fetcher_state_machine(gb); gb->cycles_for_line++; @@ -1035,25 +1066,6 @@ abort_fetching_object: gb->object_fetch_aborted = false; gb->during_object_fetch = false; - /* Handle window */ - /* Todo: verify timings */ - if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { - if (gb->io_registers[GB_IO_WX] >= 167) { - // Too late to enable the window - } - else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) { - gb->window_y++; - if (gb->io_registers[GB_IO_WX] != 166) { - gb->wx_triggered = true; - fifo_clear(&gb->bg_fifo); - gb->bg_fifo_paused = true; - gb->oam_fifo_paused = true; - gb->fetcher_state = 1; - } - } - } - render_pixel_if_possible(gb); advance_fetcher_state_machine(gb); From 40868df7595af9d5e468307337a0e1f688965997 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 28 Feb 2020 14:05:29 +0200 Subject: [PATCH 041/125] Fix this bug again --- Cocoa/Document.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 0418c56..03d4acd 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -309,16 +309,17 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) GB_set_sample_rate(&gb, 96000); self.audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) { [audioLock lock]; - if (stopping) { - memset(buffer, 0, nFrames * sizeof(*buffer)); - [audioLock unlock]; - } if (audioBufferPosition < nFrames) { audioBufferNeeded = nFrames; [audioLock wait]; } + if (stopping) { + memset(buffer, 0, nFrames * sizeof(*buffer)); + [audioLock unlock]; + } + if (audioBufferPosition >= nFrames && audioBufferPosition < nFrames + 4800) { memcpy(buffer, audioBuffer, nFrames * sizeof(*buffer)); memmove(audioBuffer, audioBuffer + nFrames, (audioBufferPosition - nFrames) * sizeof(*buffer)); @@ -376,6 +377,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } [audioLock lock]; stopping = true; + [audioLock signal]; [audioLock unlock]; running = false; while (stopping); From 2a8f15c68be9b159d8536958ed0830fe58355189 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 28 Feb 2020 18:10:09 +0200 Subject: [PATCH 042/125] The fetcher pushes pixels to the FIFO as soon as it's empty --- Core/display.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Core/display.c b/Core/display.c index b4455fd..d6acaf3 100644 --- a/Core/display.c +++ b/Core/display.c @@ -656,7 +656,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) } } gb->fetcher_state++; - break; + // fallthrough case GB_FETCHER_PUSH: { @@ -964,7 +964,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) fifo_clear(&gb->bg_fifo); gb->bg_fifo_paused = true; gb->oam_fifo_paused = true; - gb->fetcher_state = 1; + gb->fetcher_state = 0; window_got_activated = true; } } @@ -988,7 +988,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) /* TODO: This is wrong. It is only correct for a single object, not for more than one. */ if (window_got_activated) { window_got_activated = false; - gb->fetcher_state = 0; gb->cycles_for_line += 6; GB_SLEEP(gb, display, 42, 6); } From e29246fd914b340b2408ae85059c61293c76f7fd Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 28 Feb 2020 18:28:47 +0200 Subject: [PATCH 043/125] Window tile is reset on WX trigger --- Core/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/display.c b/Core/display.c index d6acaf3..9aaf40b 100644 --- a/Core/display.c +++ b/Core/display.c @@ -853,7 +853,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) (gb->current_line != 0 && gb->io_registers[GB_IO_WY] == gb->current_line - 1))) { gb->wy_triggered = true; } - gb->window_tile_x = 0; gb->oam_write_blocked = GB_is_cgb(gb) && !gb->cgb_double_speed; gb->accessed_oam_row = 0; @@ -961,6 +960,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->window_y++; if (gb->io_registers[GB_IO_WX] != 166) { gb->wx_triggered = true; + gb->window_tile_x = 0; fifo_clear(&gb->bg_fifo); gb->bg_fifo_paused = true; gb->oam_fifo_paused = true; From 955860b4631d4dac7393c0317b6fd22d42fad391 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 28 Feb 2020 22:36:51 +0200 Subject: [PATCH 044/125] Get rid of the FIFO pause flags --- Core/display.c | 26 ++++++++++---------------- Core/gb.h | 6 +++--- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Core/display.c b/Core/display.c index 9aaf40b..85fc858 100644 --- a/Core/display.c +++ b/Core/display.c @@ -422,20 +422,21 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) bool draw_oam = false; bool bg_enabled = true, bg_priority = false; - if (!gb->bg_fifo_paused) { + if (fifo_size(&gb->bg_fifo)) { fifo_item = fifo_pop(&gb->bg_fifo); bg_priority = fifo_item->bg_priority; - } - - if (!gb->oam_fifo_paused && fifo_size(&gb->oam_fifo)) { - oam_fifo_item = fifo_pop(&gb->oam_fifo); - if (oam_fifo_item->pixel && (gb->io_registers[GB_IO_LCDC] & 2)) { - draw_oam = true; - bg_priority |= oam_fifo_item->bg_priority; + + if (fifo_size(&gb->oam_fifo)) { + oam_fifo_item = fifo_pop(&gb->oam_fifo); + if (oam_fifo_item->pixel && (gb->io_registers[GB_IO_LCDC] & 2)) { + draw_oam = true; + bg_priority |= oam_fifo_item->bg_priority; + } } } - if (gb->bg_fifo_paused) return; + + if (!fifo_item) return; /* Drop pixels for scrollings */ if (gb->position_in_line >= 160 || (gb->disable_rendering && !gb->sgb)) { @@ -658,7 +659,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->fetcher_state++; // fallthrough - case GB_FETCHER_PUSH: { if (fifo_size(&gb->bg_fifo) > 0) break; @@ -673,8 +673,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) fifo_push_bg_row(&gb->bg_fifo, gb->current_tile_data[0], gb->current_tile_data[1], gb->current_tile_attributes & 7, gb->current_tile_attributes & 0x80, gb->current_tile_attributes & 0x20); - gb->bg_fifo_paused = false; - gb->oam_fifo_paused = false; gb->fetcher_state = 0; } break; @@ -946,8 +944,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) /* The actual rendering cycle */ gb->fetcher_state = 0; - gb->bg_fifo_paused = false; - gb->oam_fifo_paused = false; while (true) { /* Handle window */ /* Todo: verify timings */ @@ -962,8 +958,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->wx_triggered = true; gb->window_tile_x = 0; fifo_clear(&gb->bg_fifo); - gb->bg_fifo_paused = true; - gb->oam_fifo_paused = true; gb->fetcher_state = 0; window_got_activated = true; } diff --git a/Core/gb.h b/Core/gb.h index b8cbd97..65cfb4c 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -489,7 +489,7 @@ struct GB_gameboy_internal_s { bool vram_read_blocked; bool oam_write_blocked; bool vram_write_blocked; - GB_PADDING(bool, window_disabled_while_active); + bool fifo_insertion_glitch; uint8_t current_line; uint16_t ly_for_comparison; GB_fifo_t bg_fifo, oam_fifo; @@ -500,8 +500,8 @@ struct GB_gameboy_internal_s { uint8_t current_tile_attributes; uint8_t current_tile_data[2]; uint8_t fetcher_state; - bool bg_fifo_paused; - bool oam_fifo_paused; + GB_PADDING(bool,bg_fifo_paused); + GB_PADDING(bool,oam_fifo_paused); bool wx_triggered; uint8_t visible_objs[10]; uint8_t obj_comparators[10]; From 39b999a68b1b7e34d03efebe0d6bbb931c84de22 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 29 Feb 2020 17:06:08 +0200 Subject: [PATCH 045/125] Emulate the FIFO insertion glitch (WX variant) --- Core/display.c | 11 +++++++++++ Core/gb.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Core/display.c b/Core/display.c index 85fc858..e01c789 100644 --- a/Core/display.c +++ b/Core/display.c @@ -524,6 +524,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } gb->position_in_line++; + gb->window_is_being_fetched = false; } /* All verified CGB timings are based on CGB CPU E. CGB CPUs >= D are known to have @@ -960,9 +961,19 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) fifo_clear(&gb->bg_fifo); gb->fetcher_state = 0; window_got_activated = true; + gb->window_is_being_fetched = true; } } } + + if (!GB_is_cgb(gb) && gb->wx_triggered && !gb->window_is_being_fetched && + gb->fetcher_state == 0 && gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) ) { + // Insert a pixel right at the FIFO's end + gb->bg_fifo.read_end--; + gb->bg_fifo.read_end &= GB_FIFO_LENGTH - 1; + gb->bg_fifo.fifo[gb->bg_fifo.read_end] = (GB_fifo_item_t){0,}; + gb->window_is_being_fetched = false; + } /* Handle objects */ /* When the sprite enabled bit is off, this proccess is skipped entirely on the DMG, but not on the CGB. diff --git a/Core/gb.h b/Core/gb.h index 65cfb4c..15c6442 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -500,7 +500,7 @@ struct GB_gameboy_internal_s { uint8_t current_tile_attributes; uint8_t current_tile_data[2]; uint8_t fetcher_state; - GB_PADDING(bool,bg_fifo_paused); + bool window_is_being_fetched; GB_PADDING(bool,oam_fifo_paused); bool wx_triggered; uint8_t visible_objs[10]; From 5ca602fbd2bb8c76d4635082ab97a4bcd2ad169d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 29 Feb 2020 18:26:16 +0200 Subject: [PATCH 046/125] WX=0 emulation --- Core/display.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index e01c789..3250103 100644 --- a/Core/display.c +++ b/Core/display.c @@ -772,7 +772,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_STATE(gb, display, 40); GB_STATE(gb, display, 41); GB_STATE(gb, display, 42); - + GB_STATE(gb, display, 43); } if (!(gb->io_registers[GB_IO_LCDC] & 0x80)) { @@ -948,14 +948,21 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) while (true) { /* Handle window */ /* Todo: verify timings */ + static const uint8_t scx_to_wx0_comparisons[] = {-7, -9, -10, -11, -12, -13, -14, -14}; if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { if (gb->io_registers[GB_IO_WX] >= 167) { // Too late to enable the window } else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) { + (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed) || + (gb->io_registers[GB_IO_WX] == 0 && (gb->position_in_line) == scx_to_wx0_comparisons[gb->io_registers[GB_IO_SCX] & 7])) { gb->window_y++; if (gb->io_registers[GB_IO_WX] != 166) { + /* TODO: Verify fetcher access timings in this case */ + if (gb->io_registers[GB_IO_WX] == 0 && (gb->io_registers[GB_IO_SCX] & 7)) { + gb->cycles_for_line++; + GB_SLEEP(gb, display, 43, 1); + } gb->wx_triggered = true; gb->window_tile_x = 0; fifo_clear(&gb->bg_fifo); From b7194402eb531fdea0fe83eaabc1c814337c3057 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 1 Mar 2020 00:17:45 +0200 Subject: [PATCH 047/125] Accurately emulate Window X = Object X --- Core/display.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Core/display.c b/Core/display.c index 3250103..3310685 100644 --- a/Core/display.c +++ b/Core/display.c @@ -728,7 +728,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) return; } GB_object_t *objects = (GB_object_t *) &gb->oam; - bool window_got_activated = false; GB_STATE_MACHINE(gb, display, cycles, 2) { GB_STATE(gb, display, 1); @@ -772,7 +771,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) GB_STATE(gb, display, 40); GB_STATE(gb, display, 41); GB_STATE(gb, display, 42); - GB_STATE(gb, display, 43); } if (!(gb->io_registers[GB_IO_LCDC] & 0x80)) { @@ -961,13 +959,12 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) /* TODO: Verify fetcher access timings in this case */ if (gb->io_registers[GB_IO_WX] == 0 && (gb->io_registers[GB_IO_SCX] & 7)) { gb->cycles_for_line++; - GB_SLEEP(gb, display, 43, 1); + GB_SLEEP(gb, display, 42, 1); } gb->wx_triggered = true; gb->window_tile_x = 0; fifo_clear(&gb->bg_fifo); gb->fetcher_state = 0; - window_got_activated = true; gb->window_is_being_fetched = true; } } @@ -997,14 +994,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) (gb->io_registers[GB_IO_LCDC] & 2 || GB_is_cgb(gb)) && gb->obj_comparators[gb->n_visible_objs - 1] == (uint8_t)(gb->position_in_line + 8)) { - /* TODO: This is wrong. It is only correct for a single object, not for more than one. */ - if (window_got_activated) { - window_got_activated = false; - gb->cycles_for_line += 6; - GB_SLEEP(gb, display, 42, 6); - } - - while (gb->fetcher_state < 5) { + while (gb->fetcher_state < 5 || fifo_size(&gb->bg_fifo) == 0) { advance_fetcher_state_machine(gb); gb->cycles_for_line++; GB_SLEEP(gb, display, 27, 1); From 2a8b26d5e6210bb8c956a25b288344342f5324ca Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 1 Mar 2020 00:23:50 +0200 Subject: [PATCH 048/125] Add TODO --- Core/display.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/display.c b/Core/display.c index 3310685..fef764d 100644 --- a/Core/display.c +++ b/Core/display.c @@ -970,6 +970,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } } + /* TODO: What happens when WX=0? */ if (!GB_is_cgb(gb) && gb->wx_triggered && !gb->window_is_being_fetched && gb->fetcher_state == 0 && gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) ) { // Insert a pixel right at the FIFO's end From e846f4f3b0ab2836e5f16501d547d7fc5e9aea53 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 1 Mar 2020 23:58:28 +0200 Subject: [PATCH 049/125] Hacky, but correct emulation of WX=166 --- Core/display.c | 72 +++++++++++++++++++++++++++++++++++--------------- Core/gb.h | 2 +- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/Core/display.c b/Core/display.c index fef764d..ce9f74f 100644 --- a/Core/display.c +++ b/Core/display.c @@ -564,6 +564,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) if (!(gb->io_registers[GB_IO_LCDC] & 0x20)) { gb->wx_triggered = false; + gb->wx166_glitch = false; } /* Todo: Verified for DMG (Tested: SGB2), CGB timing is wrong. */ @@ -838,13 +839,13 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->vram_read_blocked = true; gb->vram_write_blocked = true; gb->wx_triggered = false; + gb->wx166_glitch = false; goto mode_3_start; while (true) { /* Lines 0 - 143 */ gb->window_y = -1; for (; gb->current_line < LINES; gb->current_line++) { - gb->wx_triggered = false; /* Todo: verify timings */ if ((gb->io_registers[GB_IO_WY] == gb->current_line || (gb->current_line != 0 && gb->io_registers[GB_IO_WY] == gb->current_line - 1))) { @@ -945,29 +946,48 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->fetcher_state = 0; while (true) { /* Handle window */ - /* Todo: verify timings */ - static const uint8_t scx_to_wx0_comparisons[] = {-7, -9, -10, -11, -12, -13, -14, -14}; + /* TODO: It appears that WX checks if the window beings *next* pixel, not *this* pixel. For this reason, + WX=167 has no effect at all (It checks if the PPU X position is 161, which never happens) and WX=166 + has weird artifacts (It appears to activate the window during HBlank, as PPU X is temporarily 160 at + that point. The code should be updated to represent this, and this will fix the time travel hack in + WX's access conflict code. */ + if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20)) { - if (gb->io_registers[GB_IO_WX] >= 167) { - // Too late to enable the window - } - else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed) || - (gb->io_registers[GB_IO_WX] == 0 && (gb->position_in_line) == scx_to_wx0_comparisons[gb->io_registers[GB_IO_SCX] & 7])) { - gb->window_y++; - if (gb->io_registers[GB_IO_WX] != 166) { - /* TODO: Verify fetcher access timings in this case */ - if (gb->io_registers[GB_IO_WX] == 0 && (gb->io_registers[GB_IO_SCX] & 7)) { - gb->cycles_for_line++; - GB_SLEEP(gb, display, 42, 1); - } - gb->wx_triggered = true; - gb->window_tile_x = 0; - fifo_clear(&gb->bg_fifo); - gb->fetcher_state = 0; - gb->window_is_being_fetched = true; + bool should_activate_window = false; + if (gb->io_registers[GB_IO_WX] == 0) { + static const uint8_t scx_to_wx0_comparisons[] = {-7, -9, -10, -11, -12, -13, -14, -14}; + if (gb->position_in_line == scx_to_wx0_comparisons[gb->io_registers[GB_IO_SCX] & 7]) { + should_activate_window = true; } } + else if (gb->wx166_glitch) { + static const uint8_t scx_to_wx166_comparisons[] = {-8, -9, -10, -11, -12, -13, -14, -15}; + if (gb->position_in_line == scx_to_wx166_comparisons[gb->io_registers[GB_IO_SCX] & 7]) { + should_activate_window = true; + } + } + else if (gb->io_registers[GB_IO_WX] < 166 + GB_is_cgb(gb)) { + if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || + (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) + should_activate_window = true; + } + + if (should_activate_window) { + gb->window_y++; + /* TODO: Verify fetcher access timings in this case */ + if (gb->io_registers[GB_IO_WX] == 0 && (gb->io_registers[GB_IO_SCX] & 7)) { + gb->cycles_for_line++; + GB_SLEEP(gb, display, 42, 1); + } + gb->wx_triggered = true; + gb->window_tile_x = 0; + fifo_clear(&gb->bg_fifo); + gb->fetcher_state = 0; + gb->window_is_being_fetched = true; + } + else if (!GB_is_cgb(gb) && gb->io_registers[GB_IO_WX] == 166 && gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7)) { + gb->window_y++; + } } /* TODO: What happens when WX=0? */ @@ -1075,6 +1095,14 @@ abort_fetching_object: gb->cycles_for_line++; GB_SLEEP(gb, display, 21, 1); } + /* TODO: Verify timing */ + if (!GB_is_cgb(gb) && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20) && gb->io_registers[GB_IO_WX] == 166) { + gb->wx166_glitch = true; + } + else { + gb->wx166_glitch = false; + } + gb->wx_triggered = false; if (GB_is_cgb(gb) && gb->model <= GB_MODEL_CGB_C) { gb->cycles_for_line++; @@ -1129,7 +1157,7 @@ abort_fetching_object: gb->icd_hreset_callback(gb); } } - + gb->wx166_glitch = false; /* Lines 144 - 152 */ for (; gb->current_line < VIRTUAL_LINES - 1; gb->current_line++) { gb->io_registers[GB_IO_LY] = gb->current_line; diff --git a/Core/gb.h b/Core/gb.h index 15c6442..db99608 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -501,7 +501,7 @@ struct GB_gameboy_internal_s { uint8_t current_tile_data[2]; uint8_t fetcher_state; bool window_is_being_fetched; - GB_PADDING(bool,oam_fifo_paused); + bool wx166_glitch; bool wx_triggered; uint8_t visible_objs[10]; uint8_t obj_comparators[10]; From 409ab2a6d4ae64a3211a568acdb9a7f42a249fcd Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 3 Mar 2020 02:21:19 +0200 Subject: [PATCH 050/125] Accurate emulation of tilemap advancement timings --- Core/display.c | 34 ++++++++++++++++++++-------------- Core/memory.c | 4 ++++ Core/save_state.c | 2 -- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Core/display.c b/Core/display.c index ce9f74f..cbf4196 100644 --- a/Core/display.c +++ b/Core/display.c @@ -547,7 +547,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_SLEEP, } fetcher_step_t; - fetcher_step_t fetcher_state_machine [8] = { + fetcher_step_t fetcher_state_machine [9] = { GB_FETCHER_SLEEP, GB_FETCHER_GET_TILE, GB_FETCHER_SLEEP, @@ -555,9 +555,13 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_SLEEP, GB_FETCHER_GET_TILE_DATA_HIGH, GB_FETCHER_PUSH, - GB_FETCHER_PUSH, // Compatibility + GB_FETCHER_PUSH, + GB_FETCHER_PUSH, }; - + + if (gb->fetcher_state >= sizeof(fetcher_state_machine)) { + gb->fetcher_state = 0; + } switch (fetcher_state_machine[gb->fetcher_state]) { case GB_FETCHER_GET_TILE: { uint16_t map = 0x1800; @@ -659,19 +663,23 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) } } gb->fetcher_state++; + if (gb->wx_triggered) { + gb->window_tile_x++; + gb->window_tile_x &= 0x1f; + } + // fallthrough - case GB_FETCHER_PUSH: { - if (fifo_size(&gb->bg_fifo) > 0) break; - - if (gb->wx_triggered) { - gb->window_tile_x++; - gb->window_tile_x &= 0x1f; - } - else { + if (gb->fetcher_state == 7) { + /* The background map index increase at this specific point. If this state is not reached, + it will simply not increase. */ gb->fetcher_x++; gb->fetcher_x &= 0x1f; } + if (gb->fetcher_state < 8) { + gb->fetcher_state++; + } + if (fifo_size(&gb->bg_fifo) > 0) break; fifo_push_bg_row(&gb->bg_fifo, gb->current_tile_data[0], gb->current_tile_data[1], gb->current_tile_attributes & 7, gb->current_tile_attributes & 0x80, gb->current_tile_attributes & 0x20); @@ -685,8 +693,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) } break; } - - gb->fetcher_state &= 7; } static uint16_t get_object_line_address(GB_gameboy_t *gb, const GB_object_t *object) @@ -946,7 +952,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->fetcher_state = 0; while (true) { /* Handle window */ - /* TODO: It appears that WX checks if the window beings *next* pixel, not *this* pixel. For this reason, + /* TODO: It appears that WX checks if the window begins *next* pixel, not *this* pixel. For this reason, WX=167 has no effect at all (It checks if the PPU X position is 161, which never happens) and WX=166 has weird artifacts (It appears to activate the window during HBlank, as PPU X is temporarily 160 at that point. The code should be updated to represent this, and this will fix the time travel hack in diff --git a/Core/memory.c b/Core/memory.c index 631b71f..abad063 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -742,6 +742,10 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) GB_lcd_off(gb); } gb->io_registers[GB_IO_LCDC] = value; + if (!(value & 0x20)) { + gb->wx_triggered = false; + gb->wx166_glitch = false; + } return; case GB_IO_STAT: diff --git a/Core/save_state.c b/Core/save_state.c index fd7d814..8f10152 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -267,7 +267,6 @@ int GB_load_state(GB_gameboy_t *gb, const char *path) gb->oam_fifo.write_end &= 0xF; gb->object_low_line_address &= gb->vram_size & ~1; gb->fetcher_x &= 0x1f; - gb->fetcher_state &= 7; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; @@ -379,7 +378,6 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le gb->oam_fifo.write_end &= 0xF; gb->object_low_line_address &= gb->vram_size & ~1; gb->fetcher_x &= 0x1f; - gb->fetcher_state &= 7; if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; From 1c7351fc8511592454bd8f15e2f28ae836db586a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 4 Mar 2020 23:34:36 +0200 Subject: [PATCH 051/125] Missing braces --- Core/display.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index cbf4196..0ec436d 100644 --- a/Core/display.c +++ b/Core/display.c @@ -974,8 +974,9 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } else if (gb->io_registers[GB_IO_WX] < 166 + GB_is_cgb(gb)) { if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) - should_activate_window = true; + (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) { + should_activate_window = true; + } } if (should_activate_window) { From 4d2f56c42db1ddb6df8498d1dfd140a7794c6cb7 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 4 Mar 2020 23:43:05 +0200 Subject: [PATCH 052/125] Minor bug fix --- Core/display.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Core/display.c b/Core/display.c index 0ec436d..392cd93 100644 --- a/Core/display.c +++ b/Core/display.c @@ -547,7 +547,7 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_SLEEP, } fetcher_step_t; - fetcher_step_t fetcher_state_machine [9] = { + fetcher_step_t fetcher_state_machine [8] = { GB_FETCHER_SLEEP, GB_FETCHER_GET_TILE, GB_FETCHER_SLEEP, @@ -556,13 +556,8 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) GB_FETCHER_GET_TILE_DATA_HIGH, GB_FETCHER_PUSH, GB_FETCHER_PUSH, - GB_FETCHER_PUSH, }; - - if (gb->fetcher_state >= sizeof(fetcher_state_machine)) { - gb->fetcher_state = 0; - } - switch (fetcher_state_machine[gb->fetcher_state]) { + switch (fetcher_state_machine[gb->fetcher_state & 7]) { case GB_FETCHER_GET_TILE: { uint16_t map = 0x1800; @@ -662,7 +657,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) gb->current_tile_data[1] = 0xFF; } } - gb->fetcher_state++; if (gb->wx_triggered) { gb->window_tile_x++; gb->window_tile_x &= 0x1f; @@ -670,13 +664,13 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb) // fallthrough case GB_FETCHER_PUSH: { - if (gb->fetcher_state == 7) { + if (gb->fetcher_state == 6) { /* The background map index increase at this specific point. If this state is not reached, it will simply not increase. */ gb->fetcher_x++; gb->fetcher_x &= 0x1f; } - if (gb->fetcher_state < 8) { + if (gb->fetcher_state < 7) { gb->fetcher_state++; } if (fifo_size(&gb->bg_fifo) > 0) break; From c6f9d051240cd83de0772f8112da118cde7ee930 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 14:41:13 +0200 Subject: [PATCH 053/125] Emulate LCD-PPU horizontal desync on DMGs --- Core/display.c | 38 ++++++++++++++++++++++----- Core/gb.h | 1 + Core/save_state.c | 66 ++++++++++++++++++++--------------------------- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/Core/display.c b/Core/display.c index 392cd93..8072f37 100644 --- a/Core/display.c +++ b/Core/display.c @@ -459,10 +459,10 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) uint32_t *dest = NULL; if (!gb->sgb) { if (gb->border_mode != GB_BORDER_ALWAYS) { - dest = gb->screen + gb->position_in_line + gb->current_line * WIDTH; + dest = gb->screen + gb->lcd_x + gb->current_line * WIDTH; } else { - dest = gb->screen + gb->position_in_line + gb->current_line * BORDERED_WIDTH + (BORDERED_WIDTH - WIDTH) / 2 + (BORDERED_HEIGHT - LINES) / 2 * BORDERED_WIDTH; + dest = gb->screen + gb->lcd_x + gb->current_line * BORDERED_WIDTH + (BORDERED_WIDTH - WIDTH) / 2 + (BORDERED_HEIGHT - LINES) / 2 * BORDERED_WIDTH; } } @@ -476,7 +476,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } if (gb->sgb) { if (gb->current_lcd_line < LINES) { - gb->sgb->screen_buffer[gb->position_in_line + gb->current_lcd_line * WIDTH] = gb->stopped? 0 : pixel; + gb->sgb->screen_buffer[gb->lcd_x + gb->current_lcd_line * WIDTH] = gb->stopped? 0 : pixel; } } else if (gb->model & GB_MODEL_NO_SFC_BIT) { @@ -500,7 +500,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } if (gb->sgb) { if (gb->current_lcd_line < LINES) { - gb->sgb->screen_buffer[gb->position_in_line + gb->current_lcd_line * WIDTH] = gb->stopped? 0 : pixel; + gb->sgb->screen_buffer[gb->lcd_x + gb->current_lcd_line * WIDTH] = gb->stopped? 0 : pixel; } } else if (gb->model & GB_MODEL_NO_SFC_BIT) { @@ -524,6 +524,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } gb->position_in_line++; + gb->lcd_x++; gb->window_is_being_fetched = false; } @@ -937,6 +938,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) fifo_push_bg_row(&gb->bg_fifo, 0, 0, 0, false, false); /* Todo: find out actual access time of SCX */ gb->position_in_line = - (gb->io_registers[GB_IO_SCX] & 7) - 8; + gb->lcd_x = 0; gb->fetcher_x = 0; gb->extra_penalty_for_sprite_at_0 = (gb->io_registers[GB_IO_SCX] & 7); @@ -967,10 +969,19 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } } else if (gb->io_registers[GB_IO_WX] < 166 + GB_is_cgb(gb)) { - if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) || - (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed)) { + if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7)) { should_activate_window = true; } + else if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 6) && !gb->wx_just_changed) { + should_activate_window = true; + /* LCD-PPU horizontal desync! It only appears to happen on DMGs, but not all of them. + This doesn't seem to be CPU revision dependent, but most revisions */ + if ((gb->model & GB_MODEL_FAMILY_MASK) == GB_MODEL_DMG_FAMILY && !GB_is_sgb(gb)) { + if (gb->lcd_x > 0) { + gb->lcd_x--; + } + } + } } if (should_activate_window) { @@ -1096,6 +1107,21 @@ abort_fetching_object: gb->cycles_for_line++; GB_SLEEP(gb, display, 21, 1); } + + while (gb->lcd_x != 160 && !gb->disable_rendering && gb->screen && !gb->sgb) { + /* Oh no! The PPU and LCD desynced! Fill the rest of the line whith white. */ + uint32_t *dest = NULL; + if (gb->border_mode != GB_BORDER_ALWAYS) { + dest = gb->screen + gb->lcd_x + gb->current_line * WIDTH; + } + else { + dest = gb->screen + gb->lcd_x + gb->current_line * BORDERED_WIDTH + (BORDERED_WIDTH - WIDTH) / 2 + (BORDERED_HEIGHT - LINES) / 2 * BORDERED_WIDTH; + } + *dest = gb->background_palettes_rgb[0]; + gb->lcd_x++; + + } + /* TODO: Verify timing */ if (!GB_is_cgb(gb) && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & 0x20) && gb->io_registers[GB_IO_WX] == 166) { gb->wx166_glitch = true; diff --git a/Core/gb.h b/Core/gb.h index db99608..88e2991 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -523,6 +523,7 @@ struct GB_gameboy_internal_s { uint16_t object_low_line_address; bool wy_triggered; uint8_t window_tile_x; + uint8_t lcd_x; // The LCD can go out of sync since the push signal is skipped in some cases. ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/Core/save_state.c b/Core/save_state.c index 8f10152..a53ccba 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -180,6 +180,32 @@ static bool verify_state_compatibility(GB_gameboy_t *gb, GB_gameboy_t *save) return true; } +static void sanitize_state(GB_gameboy_t *gb) +{ + if (gb->cartridge_type->has_rumble && gb->rumble_callback) { + gb->rumble_callback(gb, gb->rumble_state); + } + + for (unsigned i = 0; i < 32; i++) { + GB_palette_changed(gb, false, i * 2); + GB_palette_changed(gb, true, i * 2); + } + + gb->bg_fifo.read_end &= 0xF; + gb->bg_fifo.write_end &= 0xF; + gb->oam_fifo.read_end &= 0xF; + gb->oam_fifo.write_end &= 0xF; + gb->object_low_line_address &= gb->vram_size & ~1; + gb->fetcher_x &= 0x1f; + if (gb->lcd_x > gb->position_in_line) { + gb->lcd_x = gb->position_in_line; + } + + if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { + gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; + } +} + #define READ_SECTION(gb, f, section) read_section(f, GB_GET_SECTION(gb, section), GB_SECTION_SIZE(section)) int GB_load_state(GB_gameboy_t *gb, const char *path) @@ -252,25 +278,7 @@ int GB_load_state(GB_gameboy_t *gb, const char *path) errno = 0; - if (gb->cartridge_type->has_rumble && gb->rumble_callback) { - gb->rumble_callback(gb, gb->rumble_state); - } - - for (unsigned i = 0; i < 32; i++) { - GB_palette_changed(gb, false, i * 2); - GB_palette_changed(gb, true, i * 2); - } - - gb->bg_fifo.read_end &= 0xF; - gb->bg_fifo.write_end &= 0xF; - gb->oam_fifo.read_end &= 0xF; - gb->oam_fifo.write_end &= 0xF; - gb->object_low_line_address &= gb->vram_size & ~1; - gb->fetcher_x &= 0x1f; - - if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { - gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; - } + sanitize_state(gb); error: fclose(f); @@ -363,25 +371,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le memcpy(gb, &save, sizeof(save)); - if (gb->cartridge_type->has_rumble && gb->rumble_callback) { - gb->rumble_callback(gb, gb->rumble_state); - } - - for (unsigned i = 0; i < 32; i++) { - GB_palette_changed(gb, false, i * 2); - GB_palette_changed(gb, true, i * 2); - } - - gb->bg_fifo.read_end &= 0xF; - gb->bg_fifo.write_end &= 0xF; - gb->oam_fifo.read_end &= 0xF; - gb->oam_fifo.write_end &= 0xF; - gb->object_low_line_address &= gb->vram_size & ~1; - gb->fetcher_x &= 0x1f; - - if (gb->object_priority == GB_OBJECT_PRIORITY_UNDEFINED) { - gb->object_priority = gb->cgb_mode? GB_OBJECT_PRIORITY_INDEX : GB_OBJECT_PRIORITY_X; - } + sanitize_state(gb); return 0; } From 78b552fe822e54140f4d52942fb955fe995e7b34 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 17:37:04 +0200 Subject: [PATCH 054/125] More attempts to fix this bug --- Cocoa/Document.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 03d4acd..8264fb3 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -318,6 +318,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) if (stopping) { memset(buffer, 0, nFrames * sizeof(*buffer)); [audioLock unlock]; + return; } if (audioBufferPosition >= nFrames && audioBufferPosition < nFrames + 4800) { @@ -380,7 +381,11 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [audioLock signal]; [audioLock unlock]; running = false; - while (stopping); + while (stopping) { + [audioLock lock]; + [audioLock signal]; + [audioLock unlock]; + } GB_debugger_set_disabled(&gb, false); } From ee939a378258b647fa95a6c61aaf3314d6b69f42 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 17:37:18 +0200 Subject: [PATCH 055/125] New boot ROM animation in the DMG boot ROM --- BootROMs/dmg_boot.asm | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/BootROMs/dmg_boot.asm b/BootROMs/dmg_boot.asm index 6fb74fb..97a12e7 100644 --- a/BootROMs/dmg_boot.asm +++ b/BootROMs/dmg_boot.asm @@ -24,7 +24,7 @@ Start: ldh [$24], a ; Init BG palette - ld a, $fc + ld a, $54 ldh [$47], a ; Load logo from ROM. @@ -69,14 +69,36 @@ Start: jr .tilemapLoop .tilemapDone + ld a, 30 + ldh [$ff42], a + ; Turn on LCD ld a, $91 ldh [$40], a -; Wait ~0.75 seconds - ld b, 45 - call WaitBFrames - + ld d, (-119) & $FF + ld c, 15 + +.animate + call WaitFrame + ld a, d + sra a + sra a + ldh [$ff42], a + ld a, d + add c + ld d, a + ld a, c + cp 8 + jr nz, .noPaletteChange + ld a, $A8 + ldh [$47], a +.noPaletteChange + dec c + jr nz, .animate + ld a, $fc + ldh [$47], a + ; Play first sound ld a, $83 call PlaySound @@ -85,9 +107,11 @@ Start: ; Play second sound ld a, $c1 call PlaySound + -; Wait ~1.15 seconds - ld b, 70 + +; Wait ~1 second + ld b, 60 call WaitBFrames ; Set registers to match the original DMG boot From 4963ec4cc43529adec95efe79a5e24d9cd5aaf65 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 17:37:29 +0200 Subject: [PATCH 056/125] Gamma correction in the CRT shader --- Shaders/CRT.fsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Shaders/CRT.fsh b/Shaders/CRT.fsh index 8684451..c1ae7ef 100644 --- a/Shaders/CRT.fsh +++ b/Shaders/CRT.fsh @@ -158,6 +158,8 @@ STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 ou ret *= output_resolution.y - pixel_position.y; } + // Gamma correction + ret = pow(ret, 0.72); return ret; } From fe7667a00c92eca2089d1b8058123eb452443e51 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 17:37:47 +0200 Subject: [PATCH 057/125] Add drop shadows to the Monochrome LCD shader --- Shaders/MonoLCD.fsh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Shaders/MonoLCD.fsh b/Shaders/MonoLCD.fsh index 1a641af..009e1db 100644 --- a/Shaders/MonoLCD.fsh +++ b/Shaders/MonoLCD.fsh @@ -34,5 +34,17 @@ STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 ou multiplier *= (1.0 - sub_pos.x) * SCANLINE_DEPTH + (1 - SCANLINE_DEPTH); } - return mix(texture(image, position) * multiplier, mix(r1, r2, s.y), BLOOM); + vec4 pre_shadow = mix(texture(image, position) * multiplier, mix(r1, r2, s.y), BLOOM); + pixel += vec2(-0.6, -0.8); + + q11 = texture(image, (floor(pixel) + 0.5) / input_resolution); + q12 = texture(image, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / input_resolution); + q21 = texture(image, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / input_resolution); + q22 = texture(image, (ceil(pixel) + 0.5) / input_resolution); + + r1 = mix(q11, q21, fract(pixel.x)); + r2 = mix(q12, q22, fract(pixel.x)); + + vec4 shadow = mix(r1, r2, fract(pixel.y)); + return mix(min(shadow, pre_shadow), pre_shadow, 0.75); } From 34cf0f558da9f716b277aff5a0bbea6730c1e08c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 18:56:51 +0200 Subject: [PATCH 058/125] It's more reasonable to do it this way --- Core/memory.c | 8 ++++++++ Core/sm83_cpu.c | 17 ----------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Core/memory.c b/Core/memory.c index abad063..fccfd86 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -741,6 +741,14 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) GB_timing_sync(gb); GB_lcd_off(gb); } + /* Handle disabling objects while already fetching an object */ + if ((gb->io_registers[GB_IO_LCDC] & 2) && !(value & 2)) { + if (gb->during_object_fetch) { + gb->cycles_for_line += gb->display_cycles; + gb->display_cycles = 0; + gb->object_fetch_aborted = true; + } + } gb->io_registers[GB_IO_LCDC] = value; if (!(value & 0x20)) { gb->wx_triggered = false; diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index f25e14b..73e2ee1 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -208,29 +208,12 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) uint8_t old_value = GB_read_memory(gb, addr); GB_advance_cycles(gb, gb->pending_cycles - 2); - /* Handle disabling objects while already fetching an object */ - if ((old_value & 2) && !(value & 2)) { - if (gb->during_object_fetch) { - gb->cycles_for_line += gb->display_cycles; - gb->display_cycles = 0; - gb->object_fetch_aborted = true; - } - } - if (/* gb->model != GB_MODEL_MGB && */ gb->position_in_line == 0 && (old_value & 2) && !(value & 2)) { old_value &= ~2; } GB_write_memory(gb, addr, old_value | (value & 1)); GB_advance_cycles(gb, 1); - /* Handle disabling objects while already fetching an object */ - if ((old_value & 2) && !(value & 2)) { - if (gb->during_object_fetch) { - gb->cycles_for_line += gb->display_cycles; - gb->display_cycles = 0; - gb->object_fetch_aborted = true; - } - } GB_write_memory(gb, addr, value); gb->pending_cycles = 5; return; From e7f6ac8828dc021fcb11389dc787cca1beb84412 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 6 Mar 2020 21:19:53 +0200 Subject: [PATCH 059/125] Do the same for SGB --- Core/sm83_cpu.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 73e2ee1..da980eb 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -224,23 +224,10 @@ static void cycle_write(GB_gameboy_t *gb, uint16_t addr, uint8_t value) uint8_t old_value = GB_read_memory(gb, addr); GB_advance_cycles(gb, gb->pending_cycles - 2); - /* Handle disabling objects while already fetching an object */ - if ((old_value & 2) && !(value & 2)) { - if (gb->during_object_fetch) { - gb->cycles_for_line += gb->display_cycles; - gb->display_cycles = 0; - gb->object_fetch_aborted = true; - } - } + /* Hack to force aborting object fetch */ + GB_write_memory(gb, addr, value); + GB_write_memory(gb, addr, old_value); GB_advance_cycles(gb, 1); - /* Handle disabling objects while already fetching an object */ - if ((old_value & 2) && !(value & 2)) { - if (gb->during_object_fetch) { - gb->cycles_for_line += gb->display_cycles; - gb->display_cycles = 0; - gb->object_fetch_aborted = true; - } - } GB_write_memory(gb, addr, value); gb->pending_cycles = 5; return; From 84e8e45b7beaf15d67b32fe2e7bd01f60746e482 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 13 Mar 2020 13:35:54 +0200 Subject: [PATCH 060/125] Implement ATTR_CHR --- Core/sgb.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Core/sgb.c b/Core/sgb.c index d712e27..271b681 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -17,6 +17,7 @@ enum { ATTR_BLK = 0x04, ATTR_LIN = 0x05, ATTR_DIV = 0x06, + ATTR_CHR = 0x07, PAL_SET = 0x0A, PAL_TRN = 0x0B, DATA_SND = 0x0F, @@ -254,6 +255,52 @@ static void command_ready(GB_gameboy_t *gb) } break; } + case ATTR_CHR: { + struct __attribute__((packed)) { + uint8_t x, y; + uint16_t length; + uint8_t direction; + uint8_t data[]; + } *command = (void *)(gb->sgb->command + 1); + + uint16_t count = command->length; +#ifdef GB_BIG_ENDIAN + count = __builtin_bswap16(count); +#endif + uint8_t x = command->x; + uint8_t y = command->y; + if (x >= 20 || y >= 18 || (count + 3) / 4 > sizeof(gb->sgb->command) - sizeof(*command) - 1) { + /* TODO: Verify with the SFC BIOS */ + break; + } + + for (unsigned i = 0; i < count; i++) { + uint8_t palette = (command->data[i / 4] >> (((~i) & 3) << 1)) & 3; + gb->sgb->attribute_map[x + 20 * y] = palette; + if (command->direction) { + y++; + if (y == 18) { + x++; + y = 0; + if (x == 20) { + x = 0; + } + } + } + else { + x++; + if (x == 20) { + y++; + x = 0; + if (y == 18) { + y = 0; + } + } + } + } + + break; + } case ATTR_LIN: { struct { uint8_t count; From e94e7cc501fea44c4d4a37cfd5091bed88cfbc98 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 25 Mar 2020 20:33:13 +0200 Subject: [PATCH 061/125] Add another color correction mode --- Cocoa/Preferences.xib | 5 +++-- Core/display.c | 18 ++++++++++++++++-- Core/display.h | 1 + SDL/gui.c | 6 +++--- libretro/libretro.c | 9 ++++++++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib index e7d96aa..7eb0587 100644 --- a/Cocoa/Preferences.xib +++ b/Cocoa/Preferences.xib @@ -152,6 +152,7 @@ + @@ -203,7 +204,7 @@ - + @@ -459,7 +460,7 @@ - + diff --git a/Core/display.c b/Core/display.c index 8072f37..0ed973e 100644 --- a/Core/display.c +++ b/Core/display.c @@ -133,7 +133,7 @@ static void display_vblank(GB_gameboy_t *gb) if (!GB_is_sgb(gb)) { uint32_t color = 0; if (GB_is_cgb(gb)) { - color = gb->rgb_encode_callback(gb, 0xFF, 0xFF, 0xFF); + color = GB_convert_rgb15(gb, 0x7FFF, false); } else { color = is_ppu_stopped ? @@ -261,7 +261,21 @@ uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border) } new_r = r; new_b = b; - if (gb->color_correction_mode == GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS) { + if (gb->color_correction_mode == GB_COLOR_CORRECTION_REDUCE_CONTRAST) { + r = new_r; + g = new_r; + b = new_r; + + new_r = new_r * 7 / 8 + ( g + b) / 16; + new_g = new_g * 7 / 8 + (r + b) / 16; + new_b = new_b * 7 / 8 + (r + g ) / 16; + + + new_r = new_r * (224 - 32) / 255 + 32; + new_g = new_g * (220 - 36) / 255 + 36; + new_b = new_b * (216 - 40) / 255 + 40; + } + else if (gb->color_correction_mode == GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS) { uint8_t old_max = MAX(r, MAX(g, b)); uint8_t new_max = MAX(new_r, MAX(new_g, new_b)); diff --git a/Core/display.h b/Core/display.h index d539881..4c37f99 100644 --- a/Core/display.h +++ b/Core/display.h @@ -50,6 +50,7 @@ typedef enum { GB_COLOR_CORRECTION_CORRECT_CURVES, GB_COLOR_CORRECTION_EMULATE_HARDWARE, GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS, + GB_COLOR_CORRECTION_REDUCE_CONTRAST, } GB_color_correction_mode_t; void GB_draw_tileset(GB_gameboy_t *gb, uint32_t *dest, GB_palette_type_t palette_type, uint8_t palette_index); diff --git a/SDL/gui.c b/SDL/gui.c index 6646a17..b6b0f03 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -422,7 +422,7 @@ const char *current_scaling_mode(unsigned index) const char *current_color_correction_mode(unsigned index) { - return (const char *[]){"Disabled", "Correct Color Curves", "Emulate Hardware", "Preserve Brightness"} + return (const char *[]){"Disabled", "Correct Color Curves", "Emulate Hardware", "Preserve Brightness", "Reduce Contrast"} [configuration.color_correction_mode]; } @@ -462,7 +462,7 @@ void cycle_scaling_backwards(unsigned index) static void cycle_color_correction(unsigned index) { - if (configuration.color_correction_mode == GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS) { + if (configuration.color_correction_mode == GB_COLOR_CORRECTION_REDUCE_CONTRAST) { configuration.color_correction_mode = GB_COLOR_CORRECTION_DISABLED; } else { @@ -473,7 +473,7 @@ static void cycle_color_correction(unsigned index) static void cycle_color_correction_backwards(unsigned index) { if (configuration.color_correction_mode == GB_COLOR_CORRECTION_DISABLED) { - configuration.color_correction_mode = GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS; + configuration.color_correction_mode = GB_COLOR_CORRECTION_REDUCE_CONTRAST; } else { configuration.color_correction_mode--; diff --git a/libretro/libretro.c b/libretro/libretro.c index 59dfdc4..8cd1324 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -202,7 +202,7 @@ static retro_environment_t environ_cb; /* variables for single cart mode */ static const struct retro_variable vars_single[] = { - { "sameboy_color_correction_mode", "Color correction; off|correct curves|emulate hardware|preserve brightness" }, + { "sameboy_color_correction_mode", "Color correction; off|correct curves|emulate hardware|preserve brightness|reduce contrast" }, { "sameboy_high_pass_filter_mode", "High-pass filter; off|accurate|remove dc offset" }, { "sameboy_model", "Emulated model; Auto|Game Boy|Game Boy Color|Game Boy Advance|Super Game Boy|Super Game Boy 2" }, { "sameboy_border", "Super Game Boy border; enabled|disabled" }, @@ -497,6 +497,8 @@ static void check_variables() GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_EMULATE_HARDWARE); else if (strcmp(var.value, "preserve brightness") == 0) GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS); + else if (strcmp(var.value, "reduce_contrast") == 0) + GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_REDUCE_CONTRAST); } var.key = "sameboy_high_pass_filter_mode"; @@ -561,6 +563,8 @@ static void check_variables() GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_EMULATE_HARDWARE); else if (strcmp(var.value, "preserve brightness") == 0) GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS); + else if (strcmp(var.value, "reduce_contrast") == 0) + GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_REDUCE_CONTRAST); } var.key = "sameboy_color_correction_mode_2"; @@ -575,6 +579,9 @@ static void check_variables() GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_EMULATE_HARDWARE); else if (strcmp(var.value, "preserve brightness") == 0) GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS); + else if (strcmp(var.value, "reduce_contrast") == 0) + GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_REDUCE_CONTRAST); + } var.key = "sameboy_high_pass_filter_mode_1"; From 5ecb8456624642e18328450864a6a9cbd015a7ee Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 26 Mar 2020 20:54:18 +0200 Subject: [PATCH 062/125] Add accurate frame blending option --- Cocoa/AppDelegate.m | 2 ++ Cocoa/Document.m | 21 +++++++++-------- Cocoa/GBGLShader.h | 3 ++- Cocoa/GBGLShader.m | 10 ++++---- Cocoa/GBOpenGLView.m | 5 ++-- Cocoa/GBPreferencesWindow.h | 1 + Cocoa/GBPreferencesWindow.m | 22 ++++++++++++++++-- Cocoa/GBView.h | 10 +++++++- Cocoa/GBView.m | 21 +++++++++++++---- Cocoa/GBViewMetal.m | 20 ++++++++-------- Cocoa/Preferences.xib | 44 +++++++++++++++++++++++++++++------ Core/display.c | 10 ++++++++ Core/display.h | 1 + Core/gb.h | 1 + SDL/gui.c | 43 ++++++++++++++++++++++++++++------ SDL/gui.h | 2 +- SDL/main.c | 2 +- SDL/shader.c | 7 +++--- SDL/shader.h | 13 +++++++++-- Shaders/MasterShader.fsh | 46 +++++++++++++++++++++++++++++++------ Shaders/MasterShader.metal | 43 ++++++++++++++++++++++++++++++---- 21 files changed, 258 insertions(+), 69 deletions(-) diff --git a/Cocoa/AppDelegate.m b/Cocoa/AppDelegate.m index bbaa3ae..b941eb4 100644 --- a/Cocoa/AppDelegate.m +++ b/Cocoa/AppDelegate.m @@ -1,5 +1,6 @@ #import "AppDelegate.h" #include "GBButtons.h" +#include "GBView.h" #include #import @@ -36,6 +37,7 @@ @"GBColorCorrection": @(GB_COLOR_CORRECTION_EMULATE_HARDWARE), @"GBHighpassFilter": @(GB_HIGHPASS_REMOVE_DC_OFFSET), @"GBRewindLength": @(10), + @"GBFrameBlendingMode": @([defaults boolForKey:@"DisableFrameBlending"]? GB_FRAME_BLENDING_MODE_DISABLED : GB_FRAME_BLENDING_MODE_ACCURATE), @"GBDMGModel": @(GB_MODEL_DMG_B), @"GBCGBModel": @(GB_MODEL_CGB_E), diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 8264fb3..b835233 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -492,7 +492,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) self.consoleOutput.textContainerInset = NSMakeSize(4, 4); [self.view becomeFirstResponder]; - self.view.shouldBlendFrameWithPrevious = ![[NSUserDefaults standardUserDefaults] boolForKey:@"DisableFrameBlending"]; + self.view.frameBlendingMode = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBFrameBlendingMode"]; CGRect window_frame = self.mainWindow.frame; window_frame.size.width = MAX([[NSUserDefaults standardUserDefaults] integerForKey:@"LastWindowWidth"], window_frame.size.width); @@ -521,6 +521,11 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) name:@"GBColorCorrectionChanged" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(updateFrameBlendingMode) + name:@"GBFrameBlendingModeChanged" + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePalette) name:@"GBColorPaletteChanged" @@ -677,12 +682,6 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [[NSUserDefaults standardUserDefaults] setBool:!self.audioClient.isPlaying forKey:@"Mute"]; } -- (IBAction)toggleBlend:(id)sender -{ - self.view.shouldBlendFrameWithPrevious ^= YES; - [[NSUserDefaults standardUserDefaults] setBool:!self.view.shouldBlendFrameWithPrevious forKey:@"DisableFrameBlending"]; -} - - (BOOL)validateUserInterfaceItem:(id)anItem { if([anItem action] == @selector(mute:)) { @@ -695,9 +694,6 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) else if ([anItem action] == @selector(reset:) && anItem.tag != MODEL_NONE) { [(NSMenuItem*)anItem setState:anItem.tag == current_model]; } - else if ([anItem action] == @selector(toggleBlend:)) { - [(NSMenuItem*)anItem setState:self.view.shouldBlendFrameWithPrevious]; - } else if ([anItem action] == @selector(interrupt:)) { if (![[NSUserDefaults standardUserDefaults] boolForKey:@"DeveloperMode"]) { return false; @@ -1617,6 +1613,11 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } } +- (void) updateFrameBlendingMode +{ + self.view.frameBlendingMode = (GB_frame_blending_mode_t) [[NSUserDefaults standardUserDefaults] integerForKey:@"GBFrameBlendingMode"]; +} + - (void) updateRewindLength { [self performAtomicBlock:^{ diff --git a/Cocoa/GBGLShader.h b/Cocoa/GBGLShader.h index 1a12617..8e46f93 100644 --- a/Cocoa/GBGLShader.h +++ b/Cocoa/GBGLShader.h @@ -1,6 +1,7 @@ #import +#import "GBView.h" @interface GBGLShader : NSObject - (instancetype)initWithName:(NSString *) shaderName; -- (void) renderBitmap: (void *)bitmap previous:(void*) previous sized:(NSSize)srcSize inSize:(NSSize)dstSize scale: (double) scale; +- (void) renderBitmap: (void *)bitmap previous:(void*) previous sized:(NSSize)srcSize inSize:(NSSize)dstSize scale: (double) scale withBlendingMode: (GB_frame_blending_mode_t)blendingMode; @end diff --git a/Cocoa/GBGLShader.m b/Cocoa/GBGLShader.m index fe636f8..d57f43d 100644 --- a/Cocoa/GBGLShader.m +++ b/Cocoa/GBGLShader.m @@ -21,7 +21,7 @@ void main(void) {\n\ GLuint resolution_uniform; GLuint texture_uniform; GLuint previous_texture_uniform; - GLuint mix_previous_uniform; + GLuint frame_blending_mode_uniform; GLuint position_attribute; GLuint texture; @@ -70,7 +70,7 @@ void main(void) {\n\ glBindTexture(GL_TEXTURE_2D, 0); previous_texture_uniform = glGetUniformLocation(program, "previous_image"); - mix_previous_uniform = glGetUniformLocation(program, "mix_previous"); + frame_blending_mode_uniform = glGetUniformLocation(program, "frame_blending_mode"); // Configure OpenGL [self configureOpenGL]; @@ -79,7 +79,7 @@ void main(void) {\n\ return self; } -- (void) renderBitmap: (void *)bitmap previous:(void*) previous sized:(NSSize)srcSize inSize:(NSSize)dstSize scale: (double) scale +- (void) renderBitmap: (void *)bitmap previous:(void*) previous sized:(NSSize)srcSize inSize:(NSSize)dstSize scale: (double) scale withBlendingMode:(GB_frame_blending_mode_t)blendingMode { glUseProgram(program); glUniform2f(resolution_uniform, dstSize.width * scale, dstSize.height * scale); @@ -87,8 +87,8 @@ void main(void) {\n\ glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, srcSize.width, srcSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap); glUniform1i(texture_uniform, 0); - glUniform1i(mix_previous_uniform, previous != NULL); - if (previous) { + glUniform1i(frame_blending_mode_uniform, blendingMode); + if (blendingMode) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, previous_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, srcSize.width, srcSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, previous); diff --git a/Cocoa/GBOpenGLView.m b/Cocoa/GBOpenGLView.m index 67a9f8d..fd845e1 100644 --- a/Cocoa/GBOpenGLView.m +++ b/Cocoa/GBOpenGLView.m @@ -14,10 +14,11 @@ glViewport(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale); [self.shader renderBitmap:gbview.currentBuffer - previous:gbview.shouldBlendFrameWithPrevious? gbview.previousBuffer : NULL + previous:gbview.frameBlendingMode? gbview.previousBuffer : NULL sized:NSMakeSize(GB_get_screen_width(gbview.gb), GB_get_screen_height(gbview.gb)) inSize:self.bounds.size - scale:scale]; + scale:scale + withBlendingMode:gbview.frameBlendingMode]; glFlush(); } diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h index 2d6b0fc..27b5aa5 100644 --- a/Cocoa/GBPreferencesWindow.h +++ b/Cocoa/GBPreferencesWindow.h @@ -7,6 +7,7 @@ @property (strong) IBOutlet NSButton *aspectRatioCheckbox; @property (strong) IBOutlet NSPopUpButton *highpassFilterPopupButton; @property (strong) IBOutlet NSPopUpButton *colorCorrectionPopupButton; +@property (strong) IBOutlet NSPopUpButton *frameBlendingModePopupButton; @property (strong) IBOutlet NSPopUpButton *colorPalettePopupButton; @property (strong) IBOutlet NSPopUpButton *displayBorderPopupButton; @property (strong) IBOutlet NSPopUpButton *rewindPopupButton; diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m index 0303771..1b5aa4f 100644 --- a/Cocoa/GBPreferencesWindow.m +++ b/Cocoa/GBPreferencesWindow.m @@ -14,6 +14,7 @@ NSPopUpButton *_graphicsFilterPopupButton; NSPopUpButton *_highpassFilterPopupButton; NSPopUpButton *_colorCorrectionPopupButton; + NSPopUpButton *_frameBlendingModePopupButton; NSPopUpButton *_colorPalettePopupButton; NSPopUpButton *_displayBorderPopupButton; NSPopUpButton *_rewindPopupButton; @@ -87,6 +88,18 @@ return _colorCorrectionPopupButton; } +- (void)setFrameBlendingModePopupButton:(NSPopUpButton *)frameBlendingModePopupButton +{ + _frameBlendingModePopupButton = frameBlendingModePopupButton; + NSInteger mode = [[NSUserDefaults standardUserDefaults] integerForKey:@"GBFrameBlendingMode"]; + [_frameBlendingModePopupButton selectItemAtIndex:mode]; +} + +- (NSPopUpButton *)frameBlendingModePopupButton +{ + return _frameBlendingModePopupButton; +} + - (void)setColorPalettePopupButton:(NSPopUpButton *)colorPalettePopupButton { _colorPalettePopupButton = colorPalettePopupButton; @@ -223,7 +236,14 @@ [[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem]) forKey:@"GBColorCorrection"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"GBColorCorrectionChanged" object:nil]; +} +- (IBAction)franeBlendingModeChanged:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem]) + forKey:@"GBFrameBlendingMode"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"GBFrameBlendingModeChanged" object:nil]; + } - (IBAction)colorPaletteChanged:(id)sender @@ -231,7 +251,6 @@ [[NSUserDefaults standardUserDefaults] setObject:@([sender indexOfSelectedItem]) forKey:@"GBColorPalette"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"GBColorPaletteChanged" object:nil]; - } - (IBAction)displayBorderChanged:(id)sender @@ -239,7 +258,6 @@ [[NSUserDefaults standardUserDefaults] setObject:@([sender selectedItem].tag) forKey:@"GBBorderMode"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"GBBorderModeChanged" object:nil]; - } - (IBAction)rewindLengthChanged:(id)sender diff --git a/Cocoa/GBView.h b/Cocoa/GBView.h index f4c5e44..474e3c7 100644 --- a/Cocoa/GBView.h +++ b/Cocoa/GBView.h @@ -2,11 +2,19 @@ #include #import "GBJoystickListener.h" +typedef enum { + GB_FRAME_BLENDING_MODE_DISABLED, + GB_FRAME_BLENDING_MODE_SIMPLE, + GB_FRAME_BLENDING_MODE_ACCURATE, + GB_FRAME_BLENDING_MODE_ACCURATE_EVEN = GB_FRAME_BLENDING_MODE_ACCURATE, + GB_FRAME_BLENDING_MODE_ACCURATE_ODD, +} GB_frame_blending_mode_t; + @interface GBView : NSView - (void) flip; - (uint32_t *) pixels; @property GB_gameboy_t *gb; -@property (nonatomic) BOOL shouldBlendFrameWithPrevious; +@property (nonatomic) GB_frame_blending_mode_t frameBlendingMode; @property (getter=isMouseHidingEnabled) BOOL mouseHidingEnabled; @property bool isRewinding; @property NSView *internalView; diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index e3026fd..0267344 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -19,6 +19,7 @@ bool underclockKeyDown; double clockMultiplier; NSEventModifierFlags previousModifiers; + GB_frame_blending_mode_t _frameBlendingMode; } + (instancetype)alloc @@ -43,8 +44,7 @@ } - (void) _init -{ - _shouldBlendFrameWithPrevious = 1; +{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ratioKeepingChanged) name:@"GBAspectChanged" object:nil]; tracking_area = [ [NSTrackingArea alloc] initWithRect:(NSRect){} options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect @@ -79,15 +79,26 @@ [self setFrame:self.superview.frame]; } -- (void) setShouldBlendFrameWithPrevious:(BOOL)shouldBlendFrameWithPrevious +- (void) setFrameBlendingMode:(GB_frame_blending_mode_t)frameBlendingMode { - _shouldBlendFrameWithPrevious = shouldBlendFrameWithPrevious; + _frameBlendingMode = frameBlendingMode; [self setNeedsDisplay:YES]; } + +- (GB_frame_blending_mode_t)frameBlendingMode +{ + if (_frameBlendingMode == GB_FRAME_BLENDING_MODE_ACCURATE) { + if (GB_is_sgb(_gb)) { + return GB_FRAME_BLENDING_MODE_SIMPLE; + } + return GB_is_odd_frame(_gb)? GB_FRAME_BLENDING_MODE_ACCURATE_ODD : GB_FRAME_BLENDING_MODE_ACCURATE_EVEN; + } + return _frameBlendingMode; +} - (unsigned char) numberOfBuffers { - return _shouldBlendFrameWithPrevious? 3 : 2; + return _frameBlendingMode? 3 : 2; } - (void)dealloc diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index fde4b7e..093ed2a 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -15,7 +15,7 @@ static const vector_float2 rect[] = id vertices; id pipeline_state; id command_queue; - id mix_previous_buffer; + id frame_blending_mode_buffer; id output_resolution_buffer; vector_float2 output_resolution; } @@ -23,7 +23,7 @@ static const vector_float2 rect[] = + (bool)isSupported { if (MTLCopyAllDevices) { - return [MTLCopyAllDevices() count]; + return false; //[MTLCopyAllDevices() count]; } return false; } @@ -56,10 +56,10 @@ static const vector_float2 rect[] = length:sizeof(rect) options:MTLResourceStorageModeShared]; - static const bool default_mix_value = false; - mix_previous_buffer = [device newBufferWithBytes:&default_mix_value - length:sizeof(default_mix_value) - options:MTLResourceStorageModeShared]; + static const GB_frame_blending_mode_t default_blending_mode = GB_FRAME_BLENDING_MODE_DISABLED; + frame_blending_mode_buffer = [device newBufferWithBytes:&default_blending_mode + length:sizeof(default_blending_mode) + options:MTLResourceStorageModeShared]; output_resolution_buffer = [device newBufferWithBytes:&output_resolution length:sizeof(output_resolution) @@ -147,7 +147,7 @@ static const vector_float2 rect[] = mipmapLevel:0 withBytes:[self currentBuffer] bytesPerRow:texture.width * 4]; - if ([self shouldBlendFrameWithPrevious]) { + if ([self frameBlendingMode]) { [previous_texture replaceRegion:region mipmapLevel:0 withBytes:[self previousBuffer] @@ -157,9 +157,9 @@ static const vector_float2 rect[] = MTLRenderPassDescriptor *render_pass_descriptor = view.currentRenderPassDescriptor; id command_buffer = [command_queue commandBuffer]; - if(render_pass_descriptor != nil) + if (render_pass_descriptor != nil) { - *(bool *)[mix_previous_buffer contents] = [self shouldBlendFrameWithPrevious]; + *(GB_frame_blending_mode_t *)[frame_blending_mode_buffer contents] = [self frameBlendingMode]; *(vector_float2 *)[output_resolution_buffer contents] = output_resolution; id render_encoder = @@ -176,7 +176,7 @@ static const vector_float2 rect[] = offset:0 atIndex:0]; - [render_encoder setFragmentBuffer:mix_previous_buffer + [render_encoder setFragmentBuffer:frame_blending_mode_buffer offset:0 atIndex:0]; diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib index 7eb0587..eeb1cf2 100644 --- a/Cocoa/Preferences.xib +++ b/Cocoa/Preferences.xib @@ -69,6 +69,7 @@ + @@ -80,11 +81,11 @@ - + - + @@ -93,7 +94,7 @@ - + @@ -130,7 +131,7 @@ - + @@ -139,7 +140,7 @@ - + @@ -160,6 +161,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -231,7 +261,7 @@ - + @@ -460,7 +490,7 @@ - + diff --git a/Core/display.c b/Core/display.c index 0ed973e..a7dda7d 100644 --- a/Core/display.c +++ b/Core/display.c @@ -797,6 +797,8 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) return; } + gb->is_odd_frame = false; + if (!GB_is_cgb(gb)) { GB_SLEEP(gb, display, 23, 1); } @@ -1228,6 +1230,7 @@ abort_fetching_object: } else { if (!GB_is_sgb(gb) || gb->current_lcd_line < LINES) { + gb->is_odd_frame ^= true; display_vblank(gb); } gb->frame_skip_state = GB_FRAMESKIP_SECOND_FRAME_RENDERED; @@ -1236,6 +1239,7 @@ abort_fetching_object: else { gb->frame_skip_state = GB_FRAMESKIP_SECOND_FRAME_RENDERED; if (!GB_is_sgb(gb) || gb->current_lcd_line < LINES) { + gb->is_odd_frame ^= true; display_vblank(gb); } } @@ -1465,3 +1469,9 @@ uint8_t GB_get_oam_info(GB_gameboy_t *gb, GB_oam_info_t *dest, uint8_t *sprite_h } return count; } + + +bool GB_is_odd_frame(GB_gameboy_t *gb) +{ + return gb->is_odd_frame; +} diff --git a/Core/display.h b/Core/display.h index 4c37f99..5bdeba8 100644 --- a/Core/display.h +++ b/Core/display.h @@ -58,4 +58,5 @@ void GB_draw_tilemap(GB_gameboy_t *gb, uint32_t *dest, GB_palette_type_t palette uint8_t GB_get_oam_info(GB_gameboy_t *gb, GB_oam_info_t *dest, uint8_t *sprite_height); uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border); void GB_set_color_correction_mode(GB_gameboy_t *gb, GB_color_correction_mode_t mode); +bool GB_is_odd_frame(GB_gameboy_t *gb); #endif /* display_h */ diff --git a/Core/gb.h b/Core/gb.h index 88e2991..b4ef658 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -524,6 +524,7 @@ struct GB_gameboy_internal_s { bool wy_triggered; uint8_t window_tile_x; uint8_t lcd_x; // The LCD can go out of sync since the push signal is skipped in some cases. + bool is_odd_frame; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */ diff --git a/SDL/gui.c b/SDL/gui.c index b6b0f03..e34028d 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -46,9 +46,22 @@ void render_texture(void *pixels, void *previous) } glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); + GB_frame_blending_mode_t mode = configuration.blending_mode; + if (!previous) { + mode = GB_FRAME_BLENDING_MODE_DISABLED; + } + else if (mode == GB_FRAME_BLENDING_MODE_ACCURATE) { + if (GB_is_sgb(&gb)) { + mode = GB_FRAME_BLENDING_MODE_SIMPLE; + } + else { + mode = GB_is_odd_frame(&gb)? GB_FRAME_BLENDING_MODE_ACCURATE_ODD : GB_FRAME_BLENDING_MODE_ACCURATE_EVEN; + } + } render_bitmap_with_shader(&shader, _pixels, previous, GB_get_screen_width(&gb), GB_get_screen_height(&gb), - rect.x, rect.y, rect.w, rect.h); + rect.x, rect.y, rect.w, rect.h, + mode); SDL_GL_SwapWindow(window); } } @@ -91,7 +104,7 @@ configuration_t configuration = .color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE, .highpass_mode = GB_HIGHPASS_ACCURATE, .scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR, - .blend_frames = true, + .blending_mode = GB_FRAME_BLENDING_MODE_ACCURATE, .rewind_length = 60 * 2, .model = MODEL_CGB }; @@ -600,23 +613,39 @@ const char *current_filter_name(unsigned index) return shaders[i].display_name; } -static void toggle_blend_frames(unsigned index) +static void cycle_blending_mode(unsigned index) { - configuration.blend_frames ^= true; + if (configuration.blending_mode == GB_FRAME_BLENDING_MODE_ACCURATE) { + configuration.blending_mode = GB_FRAME_BLENDING_MODE_DISABLED; + } + else { + configuration.blending_mode++; + } } -const char *blend_frames_string(unsigned index) +static void cycle_blending_mode_backwards(unsigned index) { - return configuration.blend_frames? "Enabled" : "Disabled"; + if (configuration.blending_mode == GB_FRAME_BLENDING_MODE_DISABLED) { + configuration.blending_mode = GB_FRAME_BLENDING_MODE_ACCURATE; + } + else { + configuration.blending_mode--; + } +} + +const char *blending_mode_string(unsigned index) +{ + return (const char *[]){"Disabled", "Simple", "Accurate"} + [configuration.blending_mode]; } static const struct menu_item graphics_menu[] = { {"Scaling Mode:", cycle_scaling, current_scaling_mode, cycle_scaling_backwards}, {"Scaling Filter:", cycle_filter, current_filter_name, cycle_filter_backwards}, {"Color Correction:", cycle_color_correction, current_color_correction_mode, cycle_color_correction_backwards}, + {"Frame Blending:", cycle_blending_mode, blending_mode_string, cycle_blending_mode_backwards}, {"Mono Palette:", cycle_palette, current_palette, cycle_palette_backwards}, {"Display Border:", cycle_border_mode, current_border_mode, cycle_border_mode_backwards}, - {"Blend Frames:", toggle_blend_frames, blend_frames_string, toggle_blend_frames}, {"Back", return_to_root_menu}, {NULL,} }; diff --git a/SDL/gui.h b/SDL/gui.h index 41e9bf2..8ef2a68 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -70,7 +70,7 @@ typedef struct { SDL_Scancode keys[9]; GB_color_correction_mode_t color_correction_mode; enum scaling_mode scaling_mode; - bool blend_frames; + uint8_t blending_mode; GB_highpass_mode_t highpass_mode; diff --git a/SDL/main.c b/SDL/main.c index 06159c9..c2b5549 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -372,7 +372,7 @@ static void vblank(GB_gameboy_t *gb) clock_mutliplier += 1.0/16; GB_set_clock_multiplier(gb, clock_mutliplier); } - if (configuration.blend_frames) { + if (configuration.blending_mode) { render_texture(active_pixel_buffer, previous_pixel_buffer); uint32_t *temp = active_pixel_buffer; active_pixel_buffer = previous_pixel_buffer; diff --git a/SDL/shader.c b/SDL/shader.c index 37e5be7..250046b 100644 --- a/SDL/shader.c +++ b/SDL/shader.c @@ -130,7 +130,7 @@ bool init_shader_with_name(shader_t *shader, const char *name) glBindTexture(GL_TEXTURE_2D, 0); shader->previous_texture_uniform = glGetUniformLocation(shader->program, "previous_image"); - shader->mix_previous_uniform = glGetUniformLocation(shader->program, "mix_previous"); + shader->blending_mode_uniform = glGetUniformLocation(shader->program, "frame_blending_mode"); // Program @@ -164,7 +164,8 @@ bool init_shader_with_name(shader_t *shader, const char *name) void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, unsigned source_width, unsigned source_height, - unsigned x, unsigned y, unsigned w, unsigned h) + unsigned x, unsigned y, unsigned w, unsigned h, + GB_frame_blending_mode_t blending_mode) { glUseProgram(shader->program); glUniform2f(shader->origin_uniform, x, y); @@ -173,7 +174,7 @@ void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, glBindTexture(GL_TEXTURE_2D, shader->texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap); glUniform1i(shader->texture_uniform, 0); - glUniform1i(shader->mix_previous_uniform, previous != NULL); + glUniform1i(shader->blending_mode_uniform, previous? blending_mode : GB_FRAME_BLENDING_MODE_DISABLED); if (previous) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, shader->previous_texture); diff --git a/SDL/shader.h b/SDL/shader.h index 3a1c304..149958d 100644 --- a/SDL/shader.h +++ b/SDL/shader.h @@ -8,7 +8,7 @@ typedef struct shader_s { GLuint origin_uniform; GLuint texture_uniform; GLuint previous_texture_uniform; - GLuint mix_previous_uniform; + GLuint blending_mode_uniform; GLuint position_attribute; GLuint texture; @@ -16,10 +16,19 @@ typedef struct shader_s { GLuint program; } shader_t; +typedef enum { + GB_FRAME_BLENDING_MODE_DISABLED, + GB_FRAME_BLENDING_MODE_SIMPLE, + GB_FRAME_BLENDING_MODE_ACCURATE, + GB_FRAME_BLENDING_MODE_ACCURATE_EVEN = GB_FRAME_BLENDING_MODE_ACCURATE, + GB_FRAME_BLENDING_MODE_ACCURATE_ODD, +} GB_frame_blending_mode_t; + bool init_shader_with_name(shader_t *shader, const char *name); void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, unsigned source_width, unsigned source_height, - unsigned x, unsigned y, unsigned w, unsigned h); + unsigned x, unsigned y, unsigned w, unsigned h, + GB_frame_blending_mode_t blending_mode); void free_shader(struct shader_s *shader); #endif /* shader_h */ diff --git a/Shaders/MasterShader.fsh b/Shaders/MasterShader.fsh index cd569c2..729ab5f 100644 --- a/Shaders/MasterShader.fsh +++ b/Shaders/MasterShader.fsh @@ -1,7 +1,7 @@ #version 150 uniform sampler2D image; uniform sampler2D previous_image; -uniform bool mix_previous; +uniform int frame_blending_mode; uniform vec2 output_resolution; uniform vec2 origin; @@ -15,6 +15,15 @@ out vec4 frag_color; #line 1 {filter} + +#define BLEND_BIAS (1.0/3.0) + +#define DISABLED 0 +#define SIMPLE 1 +#define ACCURATE 2 +#define ACCURATE_EVEN ACCURATE +#define ACCURATE_ODD 3 + void main() { vec2 position = gl_FragCoord.xy - origin; @@ -22,11 +31,34 @@ void main() position.y = 1 - position.y; vec2 input_resolution = textureSize(image, 0); - if (mix_previous) { - frag_color = mix(scale(image, position, input_resolution, output_resolution), - scale(previous_image, position, input_resolution, output_resolution), 0.5); - } - else { - frag_color = scale(image, position, input_resolution, output_resolution); + float ratio; + switch (frame_blending_mode) { + default: + case DISABLED: + frag_color = scale(image, position, input_resolution, output_resolution); + return; + case SIMPLE: + ratio = 0.5; + break; + case ACCURATE_EVEN: + if ((int(position.y * input_resolution.y) & 1) == 0) { + ratio = BLEND_BIAS; + } + else { + ratio = 1 - BLEND_BIAS; + } + break; + case ACCURATE_ODD: + if ((int(position.y * input_resolution.y) & 1) == 0) { + ratio = 1 - BLEND_BIAS; + } + else { + ratio = BLEND_BIAS; + } + break; } + + frag_color = mix(scale(image, position, input_resolution, output_resolution), + scale(previous_image, position, input_resolution, output_resolution), ratio); + } diff --git a/Shaders/MasterShader.metal b/Shaders/MasterShader.metal index 4cae3ae..ee8dec9 100644 --- a/Shaders/MasterShader.metal +++ b/Shaders/MasterShader.metal @@ -42,19 +42,52 @@ static inline float4 texture(texture2d texture, float2 pos) #line 1 {filter} +#define BLEND_BIAS (1.0/3.0) + +enum frame_blending_mode { + DISABLED, + SIMPLE, + ACCURATE, + ACCURATE_EVEN = ACCURATE, + ACCURATE_ODD, +}; + fragment float4 fragment_shader(rasterizer_data in [[stage_in]], texture2d image [[ texture(0) ]], texture2d previous_image [[ texture(1) ]], - constant bool *mix_previous [[ buffer(0) ]], + constant enum frame_blending_mode *frame_blending_mode [[ buffer(0) ]], constant float2 *output_resolution [[ buffer(1) ]]) { float2 input_resolution = float2(image.get_width(), image.get_height()); in.texcoords.y = 1 - in.texcoords.y; - if (*mix_previous) { - return mix(scale(image, in.texcoords, input_resolution, *output_resolution), - scale(previous_image, in.texcoords, input_resolution, *output_resolution), 0.5); + float ratio; + switch (*frame_blending_mode) { + default: + case DISABLED: + return scale(image, in.texcoords, input_resolution, *output_resolution); + case SIMPLE: + ratio = 0.5; + break; + case ACCURATE_EVEN: + if (((int)(in.texcoords.y * input_resolution.y) & 1) == 0) { + ratio = BLEND_BIAS; + } + else { + ratio = 1 - BLEND_BIAS; + } + break; + case ACCURATE_ODD: + if (((int)(in.texcoords.y * input_resolution.y) & 1) == 0) { + ratio = 1 - BLEND_BIAS; + } + else { + ratio = BLEND_BIAS; + } + break; } - return scale(image, in.texcoords, input_resolution, *output_resolution); + + return mix(scale(image, in.texcoords, input_resolution, *output_resolution), + scale(previous_image, in.texcoords, input_resolution, *output_resolution), ratio); } From 7a807f5cae4ab208a9993d0bce68610994c46214 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 26 Mar 2020 22:18:31 +0200 Subject: [PATCH 063/125] Fix #243 --- HexFiend/HFRepresenterTextViewCallout.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HexFiend/HFRepresenterTextViewCallout.m b/HexFiend/HFRepresenterTextViewCallout.m index ae46bd8..bb4b58e 100644 --- a/HexFiend/HFRepresenterTextViewCallout.m +++ b/HexFiend/HFRepresenterTextViewCallout.m @@ -432,7 +432,7 @@ static double distanceMod1(double a, double b) { // Compute the vertical offset CGFloat textYOffset = (glyphCount == 1 ? 4 : 5); // LOL - if ([_label isEqualToString:@"6"] || [_label isEqualToString:@"7"] == 7) textYOffset -= 1; + if ([_label isEqualToString:@"6"]) textYOffset -= 1; // Apply this text matrix From fa1c84f18fb25dfa987690364b667ae9fb4afc99 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 15:43:30 +0300 Subject: [PATCH 064/125] Remove the Blend Frames menu item --- Cocoa/MainMenu.xib | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Cocoa/MainMenu.xib b/Cocoa/MainMenu.xib index 844aa0c..ee989ee 100644 --- a/Cocoa/MainMenu.xib +++ b/Cocoa/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -342,13 +342,6 @@ - - - - - - - @@ -454,6 +447,7 @@ + From 4cb56dc76fd7858aef8a558bf5e917433b470359 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 16:35:36 +0300 Subject: [PATCH 065/125] Improve MBC2 emulation. Fixes #238 --- Core/memory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/memory.c b/Core/memory.c index fccfd86..d3d9aaa 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -456,9 +456,9 @@ static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t value) } break; case GB_MBC2: - switch (addr & 0xF000) { - case 0x0000: case 0x1000: if (!(addr & 0x100)) gb->mbc_ram_enable = (value & 0xF) == 0xA; break; - case 0x2000: case 0x3000: if ( addr & 0x100) gb->mbc2.rom_bank = value; break; + switch (addr & 0x4100) { + case 0x0000: gb->mbc_ram_enable = (value & 0xF) == 0xA; break; + case 0x0100: gb->mbc2.rom_bank = value; break; } break; case GB_MBC3: From 588c0734a9bf366aee9520cf6696520b6a823458 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 17:22:50 +0300 Subject: [PATCH 066/125] Fix a crash --- Cocoa/GBView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 0267344..0e52811 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -89,7 +89,7 @@ - (GB_frame_blending_mode_t)frameBlendingMode { if (_frameBlendingMode == GB_FRAME_BLENDING_MODE_ACCURATE) { - if (GB_is_sgb(_gb)) { + if (!_gb || GB_is_sgb(_gb)) { return GB_FRAME_BLENDING_MODE_SIMPLE; } return GB_is_odd_frame(_gb)? GB_FRAME_BLENDING_MODE_ACCURATE_ODD : GB_FRAME_BLENDING_MODE_ACCURATE_EVEN; From 876b36ac1cf18dff51fd3e2c51b103c94a46cb72 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 17:26:51 +0300 Subject: [PATCH 067/125] More crash fixes, restore Metal support --- Cocoa/GBOpenGLView.m | 14 ++++++++------ Cocoa/GBViewMetal.m | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cocoa/GBOpenGLView.m b/Cocoa/GBOpenGLView.m index fd845e1..8831b62 100644 --- a/Cocoa/GBOpenGLView.m +++ b/Cocoa/GBOpenGLView.m @@ -13,12 +13,14 @@ double scale = self.window.backingScaleFactor; glViewport(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale); - [self.shader renderBitmap:gbview.currentBuffer - previous:gbview.frameBlendingMode? gbview.previousBuffer : NULL - sized:NSMakeSize(GB_get_screen_width(gbview.gb), GB_get_screen_height(gbview.gb)) - inSize:self.bounds.size - scale:scale - withBlendingMode:gbview.frameBlendingMode]; + if (gbview.gb) { + [self.shader renderBitmap:gbview.currentBuffer + previous:gbview.frameBlendingMode? gbview.previousBuffer : NULL + sized:NSMakeSize(GB_get_screen_width(gbview.gb), GB_get_screen_height(gbview.gb)) + inSize:self.bounds.size + scale:scale + withBlendingMode:gbview.frameBlendingMode]; + } glFlush(); } diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 093ed2a..4c8a5d5 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -23,7 +23,7 @@ static const vector_float2 rect[] = + (bool)isSupported { if (MTLCopyAllDevices) { - return false; //[MTLCopyAllDevices() count]; + return [MTLCopyAllDevices() count]; } return false; } From 05403d3a56883b8acee642c5b85e801281ed66d1 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 17:36:55 +0300 Subject: [PATCH 068/125] Fix the Joypad interrupt. Fixes #237 --- Core/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/memory.c b/Core/memory.c index d3d9aaa..148c986 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -780,7 +780,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) } else if ((gb->io_registers[GB_IO_JOYP] & 0x30) != (value & 0x30)) { GB_sgb_write(gb, value); - gb->io_registers[GB_IO_JOYP] = value & 0xF0; + gb->io_registers[GB_IO_JOYP] = (value & 0xF0) | (gb->io_registers[GB_IO_JOYP] & 0x0F); GB_update_joyp(gb); } return; From 1a3572316f0f9e2fc6b35c4cf0d99b3cfd279b8e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 17:49:14 +0300 Subject: [PATCH 069/125] next now skips over halt, closes #233 --- Core/debugger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/debugger.c b/Core/debugger.c index 8b6d6cf..e7f6881 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -2059,7 +2059,7 @@ void GB_debugger_run(GB_gameboy_t *gb) if (gb->debug_disable) return; char *input = NULL; - if (gb->debug_next_command && gb->debug_call_depth <= 0) { + if (gb->debug_next_command && gb->debug_call_depth <= 0 && !gb->halted) { gb->debug_stopped = true; } if (gb->debug_fin_command && gb->debug_call_depth == -1) { From 2f1b8e5b5785395ccf79eab33c0123ff7fa0a454 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 18:56:47 +0300 Subject: [PATCH 070/125] IME is now available under the registers command --- Core/debugger.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index e7f6881..71f0861 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -816,16 +816,17 @@ static bool registers(GB_gameboy_t *gb, char *arguments, char *modifiers, const } - GB_log(gb, "AF = $%04x (%c%c%c%c)\n", gb->registers[GB_REGISTER_AF], /* AF can't really be an address */ + GB_log(gb, "AF = $%04x (%c%c%c%c)\n", gb->registers[GB_REGISTER_AF], /* AF can't really be an address */ (gb->f & GB_CARRY_FLAG)? 'C' : '-', (gb->f & GB_HALF_CARRY_FLAG)? 'H' : '-', (gb->f & GB_SUBTRACT_FLAG)? 'N' : '-', (gb->f & GB_ZERO_FLAG)? 'Z' : '-'); - GB_log(gb, "BC = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_BC], false)); - GB_log(gb, "DE = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_DE], false)); - GB_log(gb, "HL = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_HL], false)); - GB_log(gb, "SP = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_SP], false)); - GB_log(gb, "PC = %s\n", value_to_string(gb, gb->pc, false)); + GB_log(gb, "BC = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_BC], false)); + GB_log(gb, "DE = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_DE], false)); + GB_log(gb, "HL = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_HL], false)); + GB_log(gb, "SP = %s\n", value_to_string(gb, gb->registers[GB_REGISTER_SP], false)); + GB_log(gb, "PC = %s\n", value_to_string(gb, gb->pc, false)); + GB_log(gb, "IME = %s\n", gb->ime? "Enabled" : "Disabled"); return true; } From 9f3bffd4ddfd4422391d83c83a67268deea555b2 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 27 Mar 2020 19:10:42 +0300 Subject: [PATCH 071/125] Add volume control to SDL --- SDL/gui.c | 27 ++++++++++++++++++++++++++- SDL/gui.h | 1 + SDL/main.c | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/SDL/gui.c b/SDL/gui.c index e34028d..8bc6551 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -106,7 +106,8 @@ configuration_t configuration = .scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR, .blending_mode = GB_FRAME_BLENDING_MODE_ACCURATE, .rewind_length = 60 * 2, - .model = MODEL_CGB + .model = MODEL_CGB, + .volume = 100, }; @@ -681,8 +682,32 @@ void cycle_highpass_filter_backwards(unsigned index) } } +const char *volume_string(unsigned index) +{ + static char ret[5]; + sprintf(ret, "%d%%", configuration.volume); + return ret; +} + +void increase_volume(unsigned index) +{ + configuration.volume += 5; + if (configuration.volume > 100) { + configuration.volume = 100; + } +} + +void decrease_volume(unsigned index) +{ + configuration.volume -= 5; + if (configuration.volume > 100) { + configuration.volume = 0; + } +} + static const struct menu_item audio_menu[] = { {"Highpass Filter:", cycle_highpass_filter, highpass_filter_string, cycle_highpass_filter_backwards}, + {"Volume:", increase_volume, volume_string, decrease_volume}, {"Back", return_to_root_menu}, {NULL,} }; diff --git a/SDL/gui.h b/SDL/gui.h index 8ef2a68..4a3b55f 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -104,6 +104,7 @@ typedef struct { /* v0.13 */ uint8_t dmg_palette; GB_border_mode_t border_mode; + uint8_t volume; } configuration_t; extern configuration_t configuration; diff --git a/SDL/main.c b/SDL/main.c index c2b5549..35c9a75 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -420,6 +420,11 @@ static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) return; } + if (configuration.volume != 100) { + sample->left = sample->left * configuration.volume / 100; + sample->right = sample->right * configuration.volume / 100; + } + SDL_QueueAudio(device_id, sample, sizeof(*sample)); } From d75b7c00232834cea1b7a756c9e62db1b5d422a0 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 28 Mar 2020 22:56:19 +0300 Subject: [PATCH 072/125] Feature request; allow loading prefs.bin relatively --- SDL/main.c | 10 +++++++--- Windows/stdio.h | 6 +++++- Windows/utf8_compat.c | 12 +++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/SDL/main.c b/SDL/main.c index 35c9a75..4b6afea 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -11,6 +11,7 @@ #ifndef _WIN32 #define AUDIO_FREQUENCY 96000 +#include #else #include /* Windows (well, at least my VM) can't handle 96KHz sound well :( */ @@ -686,9 +687,12 @@ int main(int argc, char **argv) SDL_EventState(SDL_DROPFILE, SDL_ENABLE); - char *prefs_dir = SDL_GetPrefPath("", "SameBoy"); - snprintf(prefs_path, sizeof(prefs_path) - 1, "%sprefs.bin", prefs_dir); - SDL_free(prefs_dir); + strcpy(prefs_path, resource_path("prefs.bin")); + if (access(prefs_path, R_OK | W_OK) != 0) { + char *prefs_dir = SDL_GetPrefPath("", "SameBoy"); + snprintf(prefs_path, sizeof(prefs_path) - 1, "%sprefs.bin", prefs_dir); + SDL_free(prefs_dir); + } FILE *prefs_file = fopen(prefs_path, "rb"); if (prefs_file) { diff --git a/Windows/stdio.h b/Windows/stdio.h index d68c956..0595b01 100755 --- a/Windows/stdio.h +++ b/Windows/stdio.h @@ -2,6 +2,10 @@ #include_next #include +int access(const char *filename, int mode); +#define R_OK 2 +#define W_OK 4 + #ifndef __MINGW32__ #ifndef __LIBRETRO__ static inline int vasprintf(char **str, const char *fmt, va_list args) @@ -72,4 +76,4 @@ static inline size_t getline(char **lineptr, size_t *n, FILE *stream) { return p - bufptr - 1; } -#define snprintf _snprintf \ No newline at end of file +#define snprintf _snprintf diff --git a/Windows/utf8_compat.c b/Windows/utf8_compat.c index 1005f22..0347211 100755 --- a/Windows/utf8_compat.c +++ b/Windows/utf8_compat.c @@ -1,6 +1,7 @@ #include #include #include +#include FILE *fopen(const char *filename, const char *mode) { @@ -11,4 +12,13 @@ FILE *fopen(const char *filename, const char *mode) MultiByteToWideChar(CP_UTF8, 0, mode, -1, w_mode, sizeof(w_mode) / sizeof(w_mode[0])); return _wfopen(w_filename, w_mode); -} \ No newline at end of file +} + +int access(const char *filename, int mode) +{ + wchar_t w_filename[MAX_PATH] = {0,}; + MultiByteToWideChar(CP_UTF8, 0, filename, -1, w_filename, sizeof(w_filename) / sizeof(w_filename[0])); + + return _waccess(w_filename, mode); +} + From 0ed5cf6b3879c0b7d6adfe769354e55fe04d1d1b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 8 Apr 2020 19:07:29 +0300 Subject: [PATCH 073/125] Proper MBC30 support, more accurate MBC3 emulation. Fixes #244 --- Core/debugger.c | 23 ++++++++++++++--------- Core/gb.h | 6 +++--- Core/mbc.c | 11 +++++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index 71f0861..8e7151b 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -1420,15 +1420,20 @@ static bool mbc(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg } if (cartridge->mbc_type) { - static const char * const mapper_names[] = { - [GB_MBC1] = "MBC1", - [GB_MBC2] = "MBC2", - [GB_MBC3] = "MBC3", - [GB_MBC5] = "MBC5", - [GB_HUC1] = "HUC1", - [GB_HUC3] = "HUC3", - }; - GB_log(gb, "%s\n", mapper_names[cartridge->mbc_type]); + if (gb->is_mbc30) { + GB_log(gb, "MBC30\n"); + } + else { + static const char *const mapper_names[] = { + [GB_MBC1] = "MBC1", + [GB_MBC2] = "MBC2", + [GB_MBC3] = "MBC3", + [GB_MBC5] = "MBC5", + [GB_HUC1] = "HUC1", + [GB_HUC3] = "HUC3", + }; + GB_log(gb, "%s\n", mapper_names[cartridge->mbc_type]); + } GB_log(gb, "Current mapped ROM bank: %x\n", gb->mbc_rom_bank); if (cartridge->has_ram) { GB_log(gb, "Current mapped RAM bank: %x\n", gb->mbc_ram_bank); diff --git a/Core/gb.h b/Core/gb.h index b4ef658..0b188d6 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -403,9 +403,8 @@ struct GB_gameboy_internal_s { } mbc2; struct { - uint8_t rom_bank:7; - uint8_t padding:1; - uint8_t ram_bank:4; + uint8_t rom_bank:8; + uint8_t ram_bank:3; } mbc3; struct { @@ -538,6 +537,7 @@ struct GB_gameboy_internal_s { GB_STANDARD_MBC1_WIRING, GB_MBC1M_WIRING, } mbc1_wiring; + bool is_mbc30; unsigned pending_cycles; diff --git a/Core/mbc.c b/Core/mbc.c index d3791a1..2a96219 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -86,6 +86,10 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) case GB_MBC3: gb->mbc_rom_bank = gb->mbc3.rom_bank; gb->mbc_ram_bank = gb->mbc3.ram_bank; + if (!gb->is_mbc30) { + gb->mbc_rom_bank &= 0x7F; + gb->mbc_ram_bank &= 0x3; + } if (gb->mbc_rom_bank == 0) { gb->mbc_rom_bank = 1; } @@ -147,6 +151,13 @@ void GB_configure_cart(GB_gameboy_t *gb) } } + /* Detect MBC30 */ + if (gb->cartridge_type->mbc_type == GB_MBC3) { + if (gb->rom_size > 0x200000 || gb->mbc_ram_size > 0x8000) { + gb->is_mbc30 = true; + } + } + /* Set MBC5's bank to 1 correctly */ if (gb->cartridge_type->mbc_type == GB_MBC5) { gb->mbc5.rom_bank_low = 1; From d8e89f5114cb58b754baee4e1941bef21d42b861 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 8 Apr 2020 19:17:45 +0300 Subject: [PATCH 074/125] Fix banked 16-bit assignments; fixes #245 --- Core/debugger.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/debugger.c b/Core/debugger.c index 8e7151b..65d9885 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -220,7 +220,8 @@ static value_t read_lvalue(GB_gameboy_t *gb, lvalue_t lvalue) banking_state_t state; save_banking_state(gb, &state); switch_banking_state(gb, lvalue.memory_address.bank); - value_t r = VALUE_16(GB_read_memory(gb, lvalue.memory_address.value)); + value_t r = VALUE_16(GB_read_memory(gb, lvalue.memory_address.value) | + (GB_read_memory(gb, lvalue.memory_address.value + 1) * 0x100)); restore_banking_state(gb, &state); return r; } @@ -261,6 +262,7 @@ static void write_lvalue(GB_gameboy_t *gb, lvalue_t lvalue, uint16_t value) save_banking_state(gb, &state); switch_banking_state(gb, lvalue.memory_address.bank); GB_write_memory(gb, lvalue.memory_address.value, value); + GB_write_memory(gb, lvalue.memory_address.value + 1, value >> 8); restore_banking_state(gb, &state); return; } From 92d6cc6394f5c7f8114842af271e2b47ab98ff29 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 9 Apr 2020 02:36:27 +0300 Subject: [PATCH 075/125] Use official register names --- Core/gb.h | 6 +++--- Core/memory.c | 14 +++++++------- Misc/registers.sym | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/gb.h b/Core/gb.h index 0b188d6..3b83b6d 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -185,7 +185,7 @@ enum { // Unfortunately it is not readable or writable after boot has finished, so research of this // register is quite limited. The value written to this register, however, can be controlled // in some cases. - GB_IO_MODE = 0x4c, + GB_IO_KEY0 = 0x4c, /* General CGB features */ GB_IO_KEY1 = 0x4d, // CGB Mode Only - Prepare Speed Switch @@ -193,7 +193,7 @@ enum { /* Missing */ GB_IO_VBK = 0x4f, // CGB Mode Only - VRAM Bank - GB_IO_BIOS = 0x50, // Write to disable the BIOS mapping + GB_IO_BANK = 0x50, // Write to disable the BIOS mapping /* CGB DMA */ GB_IO_HDMA1 = 0x51, // CGB Mode Only - New DMA Source, High @@ -212,7 +212,7 @@ enum { GB_IO_BGPD = 0x69, // CGB Mode Only - Background Palette Data GB_IO_OBPI = 0x6a, // CGB Mode Only - Sprite Palette Index GB_IO_OBPD = 0x6b, // CGB Mode Only - Sprite Palette Data - GB_IO_OBJECT_PRIORITY = 0x6c, // Affects object priority (X based or index based) + GB_IO_OPRI = 0x6c, // Affects object priority (X based or index based) /* Missing */ diff --git a/Core/memory.c b/Core/memory.c index 148c986..27f58e1 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -295,11 +295,11 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) return gb->io_registers[GB_IO_TAC] | 0xF8; case GB_IO_STAT: return gb->io_registers[GB_IO_STAT] | 0x80; - case GB_IO_OBJECT_PRIORITY: + case GB_IO_OPRI: if (!GB_is_cgb(gb)) { return 0xFF; } - return gb->io_registers[GB_IO_OBJECT_PRIORITY] | 0xFE; + return gb->io_registers[GB_IO_OPRI] | 0xFE; case GB_IO_PCM_12: if (!GB_is_cgb(gb)) return 0xFF; @@ -663,8 +663,8 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) case GB_IO_UNKNOWN5: gb->io_registers[addr & 0xFF] = value; return; - case GB_IO_OBJECT_PRIORITY: - if ((!gb->boot_rom_finished || (gb->io_registers[GB_IO_MODE] & 8)) && GB_is_cgb(gb)) { + case GB_IO_OPRI: + if ((!gb->boot_rom_finished || (gb->io_registers[GB_IO_KEY0] & 8)) && GB_is_cgb(gb)) { gb->io_registers[addr & 0xFF] = value; gb->object_priority = (value & 1) ? GB_OBJECT_PRIORITY_X : GB_OBJECT_PRIORITY_INDEX; } @@ -785,14 +785,14 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) } return; - case GB_IO_BIOS: + case GB_IO_BANK: gb->boot_rom_finished = true; return; - case GB_IO_MODE: + case GB_IO_KEY0: if (GB_is_cgb(gb) && !gb->boot_rom_finished) { gb->cgb_mode = !(value & 0xC); /* The real "contents" of this register aren't quite known yet. */ - gb->io_registers[GB_IO_MODE] = value; + gb->io_registers[GB_IO_KEY0] = value; } return; diff --git a/Misc/registers.sym b/Misc/registers.sym index ea76ab3..3b31b74 100644 --- a/Misc/registers.sym +++ b/Misc/registers.sym @@ -41,10 +41,10 @@ 00:FF49 IO_OBP1 00:FF4A IO_WY 00:FF4B IO_WX -00:FF4C IO_DMG_EMULATION +00:FF4C IO_KEY0 00:FF4D IO_KEY1 00:FF4F IO_VBK -00:FF50 IO_BIOS +00:FF50 IO_BANK 00:FF51 IO_HDMA1 00:FF52 IO_HDMA2 00:FF53 IO_HDMA3 @@ -55,7 +55,7 @@ 00:FF69 IO_BGPD 00:FF6A IO_OBPI 00:FF6B IO_OBPD -00:FF6C IO_OBJECT_PRIORITY +00:FF6C IO_OPRI 00:FF70 IO_SVBK 00:FF72 IO_UNKNOWN2 00:FF73 IO_UNKNOWN3 From a9cd3f2c1195e874f6368792d057aa61ee1353ba Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 9 Apr 2020 14:21:07 +0300 Subject: [PATCH 076/125] Fix operator priorities, fix parsing debugger bug --- Core/debugger.c | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index 65d9885..7d2ae89 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -334,7 +334,7 @@ static value_t bank(value_t a, value_t b) {return (value_t) {true, a.value, b.va static struct { const char *string; - char priority; + int8_t priority; value_t (*operator)(value_t, value_t); value_t (*lvalue_operator)(GB_gameboy_t *, lvalue_t, uint16_t); } operators[] = @@ -352,15 +352,15 @@ static struct { {"&", 1, and}, {"^", 1, xor}, {"<<", 2, shleft}, - {"<=", -1, lower_equals}, - {"<", -1, lower}, + {"<=", 3, lower_equals}, + {"<", 3, lower}, {">>", 2, shright}, - {">=", -1, greater_equals}, - {">", -1, greater}, - {"==", -1, equals}, - {"=", -2, NULL, assign}, - {"!=", -1, different}, - {":", 3, bank}, + {">=", 3, greater_equals}, + {">", 3, greater}, + {"==", 3, equals}, + {"=", -1, NULL, assign}, + {"!=", 3, different}, + {":", 4, bank}, }; value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, @@ -388,8 +388,8 @@ static lvalue_t debugger_evaluate_lvalue(GB_gameboy_t *gb, const char *string, } if (string[0] == '(' && string[length - 1] == ')') { // Attempt to strip parentheses - signed int depth = 0; - for (int i = 0; i < length; i++) { + signed depth = 0; + for (unsigned i = 0; i < length; i++) { if (string[i] == '(') depth++; if (depth == 0) { // First and last are not matching @@ -402,8 +402,8 @@ static lvalue_t debugger_evaluate_lvalue(GB_gameboy_t *gb, const char *string, } else if (string[0] == '[' && string[length - 1] == ']') { // Attempt to strip square parentheses (memory dereference) - signed int depth = 0; - for (int i = 0; i < length; i++) { + signed depth = 0; + for (unsigned i = 0; i < length; i++) { if (string[i] == '[') depth++; if (depth == 0) { // First and last are not matching @@ -418,8 +418,8 @@ static lvalue_t debugger_evaluate_lvalue(GB_gameboy_t *gb, const char *string, } else if (string[0] == '{' && string[length - 1] == '}') { // Attempt to strip curly parentheses (memory dereference) - signed int depth = 0; - for (int i = 0; i < length; i++) { + signed depth = 0; + for (unsigned i = 0; i < length; i++) { if (string[i] == '{') depth++; if (depth == 0) { // First and last are not matching @@ -495,8 +495,8 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, } if (string[0] == '(' && string[length - 1] == ')') { // Attempt to strip parentheses - signed int depth = 0; - for (int i = 0; i < length; i++) { + signed depth = 0; + for (unsigned i = 0; i < length; i++) { if (string[i] == '(') depth++; if (depth == 0) { // First and last are not matching @@ -512,8 +512,8 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, } else if (string[0] == '[' && string[length - 1] == ']') { // Attempt to strip square parentheses (memory dereference) - signed int depth = 0; - for (int i = 0; i < length; i++) { + signed depth = 0; + for (unsigned i = 0; i < length; i++) { if (string[i] == '[') depth++; if (depth == 0) { // First and last are not matching @@ -539,8 +539,8 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, } else if (string[0] == '{' && string[length - 1] == '}') { // Attempt to strip curly parentheses (memory dereference) - signed int depth = 0; - for (int i = 0; i < length; i++) { + signed depth = 0; + for (unsigned i = 0; i < length; i++) { if (string[i] == '{') depth++; if (depth == 0) { // First and last are not matching @@ -565,7 +565,7 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, } } // Search for lowest priority operator - signed int depth = 0; + signed depth = 0; unsigned operator_index = -1; unsigned operator_pos = 0; for (int i = 0; i < length; i++) { @@ -574,15 +574,15 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, else if (string[i] == '[') depth++; else if (string[i] == ']') depth--; else if (depth == 0) { - for (int j = 0; j < sizeof(operators) / sizeof(operators[0]); j++) { - if (strlen(operators[j].string) > length - i) continue; // Operator too big. - // Priority higher than what we already have. - unsigned long operator_length = strlen(operators[j].string); + for (unsigned j = 0; j < sizeof(operators) / sizeof(operators[0]); j++) { + unsigned operator_length = strlen(operators[j].string); + if (operator_length > length - i) continue; // Operator too long + if (memcmp(string + i, operators[j].string, operator_length) == 0) { if (operator_index != -1 && operators[operator_index].priority < operators[j].priority) { /* for supporting = vs ==, etc*/ i += operator_length - 1; - continue; + break; } // Found an operator! operator_pos = i; @@ -669,7 +669,7 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, } char *end; - int base = 10; + unsigned base = 10; if (string[0] == '$') { string++; base = 16; From a6567d9ee16141d7e2e39f9b93251564613a99f8 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 9 Apr 2020 14:32:52 +0300 Subject: [PATCH 077/125] Update old coding style --- Cocoa/Document.m | 10 +++++----- Core/apu.c | 2 +- Core/camera.c | 6 +++--- Core/debugger.c | 20 ++++++++++---------- Core/display.c | 2 +- Core/gb.c | 2 +- Core/gb.h | 14 +++++++------- Core/mbc.c | 2 +- Core/sm83_cpu.c | 14 +++++++------- Core/symbol_hash.c | 8 ++++---- SDL/gui.c | 6 +++--- SDL/shader.c | 2 +- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index b835233..92d5f97 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -731,8 +731,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSRect rect = window.contentView.frame; - int titlebarSize = window.contentView.superview.frame.size.height - rect.size.height; - int step = width / [[window screen] backingScaleFactor]; + unsigned titlebarSize = window.contentView.superview.frame.size.height - rect.size.height; + unsigned step = width / [[window screen] backingScaleFactor]; rect.size.width = floor(rect.size.width / step) * step + step; rect.size.height = rect.size.width * height / width + titlebarSize; @@ -1468,7 +1468,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; if (tableView == self.paletteTableView) { if (columnIndex == 0) { - return [NSString stringWithFormat:@"%s %d", row >=8 ? "Object" : "Background", (int)(row & 7)]; + return [NSString stringWithFormat:@"%s %u", row >=8 ? "Object" : "Background", (unsigned)(row & 7)]; } uint8_t *palette_data = GB_get_direct_access(&gb, row >= 8? GB_DIRECT_ACCESS_OBP : GB_DIRECT_ACCESS_BGP, NULL, NULL); @@ -1486,9 +1486,9 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) height:oamHeight scale:16.0/oamHeight]; case 1: - return @((int)oamInfo[row].x - 8); + return @((unsigned)oamInfo[row].x - 8); case 2: - return @((int)oamInfo[row].y - 16); + return @((unsigned)oamInfo[row].y - 16); case 3: return [NSString stringWithFormat:@"$%02x", oamInfo[row].tile]; case 4: diff --git a/Core/apu.c b/Core/apu.c index c3be533..feda3c8 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -548,7 +548,7 @@ uint8_t GB_apu_read(GB_gameboy_t *gb, uint8_t reg) { if (reg == GB_IO_NR52) { uint8_t value = 0; - for (int i = 0; i < GB_N_CHANNELS; i++) { + for (unsigned i = 0; i < GB_N_CHANNELS; i++) { value >>= 1; if (gb->apu.is_active[i]) { value |= 0x8; diff --git a/Core/camera.c b/Core/camera.c index 9b34998..bef8489 100644 --- a/Core/camera.c +++ b/Core/camera.c @@ -1,17 +1,17 @@ #include "gb.h" -static int noise_seed = 0; +static signed noise_seed = 0; /* This is not a complete emulation of the camera chip. Only the features used by the GameBoy Camera ROMs are supported. We also do not emulate the timing of the real cart, as it might be actually faster than the webcam. */ static uint8_t generate_noise(uint8_t x, uint8_t y) { - int value = (x + y * 128 + noise_seed); + signed value = (x + y * 128 + noise_seed); uint8_t *data = (uint8_t *) &value; unsigned hash = 0; - while ((int *) data != &value + 1) { + while ((signed *) data != &value + 1) { hash ^= (*data << 8); if (hash & 0x8000) { hash ^= 0x8a00; diff --git a/Core/debugger.c b/Core/debugger.c index 7d2ae89..4e3bd63 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -568,7 +568,7 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, signed depth = 0; unsigned operator_index = -1; unsigned operator_pos = 0; - for (int i = 0; i < length; i++) { + for (unsigned i = 0; i < length; i++) { if (string[i] == '(') depth++; else if (string[i] == ')') depth--; else if (string[i] == '[') depth++; @@ -841,8 +841,8 @@ static uint16_t find_breakpoint(GB_gameboy_t *gb, value_t addr) uint32_t key = BP_KEY(addr); - int min = 0; - int max = gb->n_breakpoints; + unsigned min = 0; + unsigned max = gb->n_breakpoints; while (min < max) { uint16_t pivot = (min + max) / 2; if (gb->breakpoints[pivot].key == key) return pivot; @@ -1008,8 +1008,8 @@ static uint16_t find_watchpoint(GB_gameboy_t *gb, value_t addr) return 0; } uint32_t key = WP_KEY(addr); - int min = 0; - int max = gb->n_watchpoints; + unsigned min = 0; + unsigned max = gb->n_watchpoints; while (min < max) { uint16_t pivot = (min + max) / 2; if (gb->watchpoints[pivot].key == key) return pivot; @@ -1342,7 +1342,7 @@ static bool examine(GB_gameboy_t *gb, char *arguments, char *modifiers, const de while (count) { GB_log(gb, "%02x:%04x: ", addr.bank, addr.value); - for (int i = 0; i < 16 && count; i++) { + for (unsigned i = 0; i < 16 && count; i++) { GB_log(gb, "%02x ", GB_read_memory(gb, addr.value + i)); count--; } @@ -1355,7 +1355,7 @@ static bool examine(GB_gameboy_t *gb, char *arguments, char *modifiers, const de else { while (count) { GB_log(gb, "%04x: ", addr.value); - for (int i = 0; i < 16 && count; i++) { + for (unsigned i = 0; i < 16 && count; i++) { GB_log(gb, "%02x ", GB_read_memory(gb, addr.value + i)); count--; } @@ -1493,7 +1493,7 @@ static bool ticks(GB_gameboy_t *gb, char *arguments, char *modifiers, const debu return true; } - GB_log(gb, "Ticks: %lu. (Resetting)\n", gb->debugger_ticks); + GB_log(gb, "Ticks: %llu. (Resetting)\n", (unsigned long long)gb->debugger_ticks); gb->debugger_ticks = 0; return true; @@ -2197,13 +2197,13 @@ void GB_debugger_load_symbol_file(GB_gameboy_t *gb, const char *path) void GB_debugger_clear_symbols(GB_gameboy_t *gb) { - for (int i = sizeof(gb->bank_symbols) / sizeof(gb->bank_symbols[0]); i--;) { + for (unsigned i = sizeof(gb->bank_symbols) / sizeof(gb->bank_symbols[0]); i--;) { if (gb->bank_symbols[i]) { GB_map_free(gb->bank_symbols[i]); gb->bank_symbols[i] = 0; } } - for (int i = sizeof(gb->reversed_symbol_map.buckets) / sizeof(gb->reversed_symbol_map.buckets[0]); i--;) { + for (unsigned i = sizeof(gb->reversed_symbol_map.buckets) / sizeof(gb->reversed_symbol_map.buckets[0]); i--;) { while (gb->reversed_symbol_map.buckets[i]) { GB_symbol_t *next = gb->reversed_symbol_map.buckets[i]->next; free(gb->reversed_symbol_map.buckets[i]); diff --git a/Core/display.c b/Core/display.c index a7dda7d..356e742 100644 --- a/Core/display.c +++ b/Core/display.c @@ -1421,7 +1421,7 @@ uint8_t GB_get_oam_info(GB_gameboy_t *gb, GB_oam_info_t *dest, uint8_t *sprite_h GB_object_t *sprite = (GB_object_t *) &gb->oam; uint8_t sprites_in_line = 0; for (uint8_t i = 0; i < 40; i++, sprite++) { - int sprite_y = sprite->y - 16; + signed sprite_y = sprite->y - 16; bool obscured = false; // Is sprite not in this line? if (sprite_y > y || sprite_y + *sprite_height <= y) continue; diff --git a/Core/gb.c b/Core/gb.c index 31fff0d..ba3f20a 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -709,7 +709,7 @@ void GB_set_infrared_input(GB_gameboy_t *gb, bool state) gb->ir_queue_length = 0; } -void GB_queue_infrared_input(GB_gameboy_t *gb, bool state, long cycles_after_previous_change) +void GB_queue_infrared_input(GB_gameboy_t *gb, bool state, uint64_t cycles_after_previous_change) { if (gb->ir_queue_length == GB_MAX_IR_QUEUE) { GB_log(gb, "IR Queue is full\n"); diff --git a/Core/gb.h b/Core/gb.h index 3b83b6d..1f3bacf 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -265,7 +265,7 @@ typedef void (*GB_vblank_callback_t)(GB_gameboy_t *gb); typedef void (*GB_log_callback_t)(GB_gameboy_t *gb, const char *string, GB_log_attributes attributes); typedef char *(*GB_input_callback_t)(GB_gameboy_t *gb); typedef uint32_t (*GB_rgb_encode_callback_t)(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b); -typedef void (*GB_infrared_callback_t)(GB_gameboy_t *gb, bool on, long cycles_since_last_update); +typedef void (*GB_infrared_callback_t)(GB_gameboy_t *gb, bool on, uint64_t cycles_since_last_update); typedef void (*GB_rumble_callback_t)(GB_gameboy_t *gb, bool rumble_on); typedef void (*GB_serial_transfer_bit_start_callback_t)(GB_gameboy_t *gb, bool bit_to_send); typedef bool (*GB_serial_transfer_bit_end_callback_t)(GB_gameboy_t *gb); @@ -278,7 +278,7 @@ typedef void (*GB_boot_rom_load_callback_t)(GB_gameboy_t *gb, GB_boot_rom_t type typedef struct { bool state; - long delay; + uint64_t delay; } GB_ir_queue_item_t; struct GB_breakpoint_s; @@ -587,8 +587,8 @@ struct GB_gameboy_internal_s { GB_boot_rom_load_callback_t boot_rom_load_callback; /* IR */ - long cycles_since_ir_change; // In 8MHz units - long cycles_since_input_ir_change; // In 8MHz units + uint64_t cycles_since_ir_change; // In 8MHz units + uint64_t cycles_since_input_ir_change; // In 8MHz units GB_ir_queue_item_t ir_queue[GB_MAX_IR_QUEUE]; size_t ir_queue_length; @@ -605,7 +605,7 @@ struct GB_gameboy_internal_s { /* SLD (Todo: merge with backtrace) */ bool stack_leak_detection; - int debug_call_depth; + signed debug_call_depth; uint16_t sp_for_call_depth[0x200]; /* Should be much more than enough */ uint16_t addr_for_call_depth[0x200]; @@ -626,7 +626,7 @@ struct GB_gameboy_internal_s { GB_reversed_symbol_map_t reversed_symbol_map; /* Ticks command */ - unsigned long debugger_ticks; + uint64_t debugger_ticks; /* Rewind */ #define GB_REWIND_FRAMES_PER_KEY 255 @@ -732,7 +732,7 @@ void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output); void GB_set_border_mode(GB_gameboy_t *gb, GB_border_mode_t border_mode); void GB_set_infrared_input(GB_gameboy_t *gb, bool state); -void GB_queue_infrared_input(GB_gameboy_t *gb, bool state, long cycles_after_previous_change); /* In 8MHz units*/ +void GB_queue_infrared_input(GB_gameboy_t *gb, bool state, uint64_t cycles_after_previous_change); /* In 8MHz units*/ void GB_set_vblank_callback(GB_gameboy_t *gb, GB_vblank_callback_t callback); void GB_set_log_callback(GB_gameboy_t *gb, GB_log_callback_t callback); diff --git a/Core/mbc.c b/Core/mbc.c index 2a96219..2ee53e8 100644 --- a/Core/mbc.c +++ b/Core/mbc.c @@ -132,7 +132,7 @@ void GB_configure_cart(GB_gameboy_t *gb) gb->mbc_ram_size = 0x200; } else { - static const int ram_sizes[256] = {0, 0x800, 0x2000, 0x8000, 0x20000, 0x10000}; + static const unsigned ram_sizes[256] = {0, 0x800, 0x2000, 0x8000, 0x20000, 0x10000}; gb->mbc_ram_size = ram_sizes[gb->rom[0x149]]; } gb->mbc_ram = malloc(gb->mbc_ram_size); diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index da980eb..2b7b1dd 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -471,7 +471,7 @@ static void add_hl_rr(GB_gameboy_t *gb, uint8_t opcode) gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if ( ((unsigned long) hl + (unsigned long) rr) & 0x10000) { + if ( ((unsigned) hl + (unsigned) rr) & 0x10000) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } @@ -802,7 +802,7 @@ static void add_a_r(GB_gameboy_t *gb, uint8_t opcode) if ((a & 0xF) + (value & 0xF) > 0x0F) { gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if (((unsigned long) a) + ((unsigned long) value) > 0xFF) { + if (((unsigned) a) + ((unsigned) value) > 0xFF) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } @@ -821,7 +821,7 @@ static void adc_a_r(GB_gameboy_t *gb, uint8_t opcode) if ((a & 0xF) + (value & 0xF) + carry > 0x0F) { gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if (((unsigned long) a) + ((unsigned long) value) + carry > 0xFF) { + if (((unsigned) a) + ((unsigned) value) + carry > 0xFF) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } @@ -857,7 +857,7 @@ static void sbc_a_r(GB_gameboy_t *gb, uint8_t opcode) if ((a & 0xF) < (value & 0xF) + carry) { gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if (((unsigned long) a) - ((unsigned long) value) - carry > 0xFF) { + if (((unsigned) a) - ((unsigned) value) - carry > 0xFF) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } @@ -1001,7 +1001,7 @@ static void add_a_d8(GB_gameboy_t *gb, uint8_t opcode) if ((a & 0xF) + (value & 0xF) > 0x0F) { gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if (((unsigned long) a) + ((unsigned long) value) > 0xFF) { + if (((unsigned) a) + ((unsigned) value) > 0xFF) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } @@ -1020,7 +1020,7 @@ static void adc_a_d8(GB_gameboy_t *gb, uint8_t opcode) if ((a & 0xF) + (value & 0xF) + carry > 0x0F) { gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if (((unsigned long) a) + ((unsigned long) value) + carry > 0xFF) { + if (((unsigned) a) + ((unsigned) value) + carry > 0xFF) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } @@ -1056,7 +1056,7 @@ static void sbc_a_d8(GB_gameboy_t *gb, uint8_t opcode) if ((a & 0xF) < (value & 0xF) + carry) { gb->registers[GB_REGISTER_AF] |= GB_HALF_CARRY_FLAG; } - if (((unsigned long) a) - ((unsigned long) value) - carry > 0xFF) { + if (((unsigned) a) - ((unsigned) value) - carry > 0xFF) { gb->registers[GB_REGISTER_AF] |= GB_CARRY_FLAG; } } diff --git a/Core/symbol_hash.c b/Core/symbol_hash.c index 208e72d..33e3399 100644 --- a/Core/symbol_hash.c +++ b/Core/symbol_hash.c @@ -71,9 +71,9 @@ void GB_map_free(GB_symbol_map_t *map) free(map); } -static int hash_name(const char *name) +static unsigned hash_name(const char *name) { - int r = 0; + unsigned r = 0; while (*name) { r <<= 1; if (r & 0x400) { @@ -87,7 +87,7 @@ static int hash_name(const char *name) void GB_reversed_map_add_symbol(GB_reversed_symbol_map_t *map, uint16_t bank, GB_bank_symbol_t *bank_symbol) { - int hash = hash_name(bank_symbol->name); + unsigned hash = hash_name(bank_symbol->name); GB_symbol_t *symbol = malloc(sizeof(*symbol)); symbol->name = bank_symbol->name; symbol->addr = bank_symbol->addr; @@ -98,7 +98,7 @@ void GB_reversed_map_add_symbol(GB_reversed_symbol_map_t *map, uint16_t bank, GB const GB_symbol_t *GB_reversed_map_find_symbol(GB_reversed_symbol_map_t *map, const char *name) { - int hash = hash_name(name); + unsigned hash = hash_name(name); GB_symbol_t *symbol = map->buckets[hash]; while (symbol) { diff --git a/SDL/gui.c b/SDL/gui.c index 8bc6551..201452a 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -142,8 +142,8 @@ void update_viewport(void) double y_factor = win_height / (double) GB_get_screen_height(&gb); if (configuration.scaling_mode == GB_SDL_SCALING_INTEGER_FACTOR) { - x_factor = (int)(x_factor); - y_factor = (int)(y_factor); + x_factor = (unsigned)(x_factor); + y_factor = (unsigned)(y_factor); } if (configuration.scaling_mode != GB_SDL_SCALING_ENTIRE_WINDOW) { @@ -1265,7 +1265,7 @@ void run_gui(bool is_running) } if (item->value_getter && !item->backwards_handler) { char line[25]; - snprintf(line, sizeof(line), "%s%*s", item->string, 24 - (int)strlen(item->string), item->value_getter(i)); + snprintf(line, sizeof(line), "%s%*s", item->string, 24 - (unsigned)strlen(item->string), item->value_getter(i)); draw_text_centered(pixels, width, height, y + y_offset, line, gui_palette_native[3], gui_palette_native[0], i == current_selection ? DECORATION_SELECTION : DECORATION_NONE); y += 12; diff --git a/SDL/shader.c b/SDL/shader.c index 250046b..de2ba56 100644 --- a/SDL/shader.c +++ b/SDL/shader.c @@ -75,7 +75,7 @@ bool init_shader_with_name(shader_t *shader, const char *name) static char master_shader_code[0x801] = {0,}; static char shader_code[0x10001] = {0,}; static char final_shader_code[0x10801] = {0,}; - static signed long filter_token_location = 0; + static ssize_t filter_token_location = 0; if (!master_shader_code[0]) { FILE *master_shader_f = fopen(resource_path("Shaders/MasterShader.fsh"), "r"); From 4a21dd323226272b2c66ae2cc4236e13f98e2514 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 9 Apr 2020 15:29:49 +0300 Subject: [PATCH 078/125] The Cocoa sidebar is now resizeable and collapseable --- Cocoa/Document.h | 5 +- Cocoa/Document.m | 38 ++++++ Cocoa/Document.xib | 304 ++++++++++++++++++++++++-------------------- Cocoa/GBSplitView.h | 15 +++ Cocoa/GBSplitView.m | 28 ++++ 5 files changed, 251 insertions(+), 139 deletions(-) create mode 100644 Cocoa/GBSplitView.h create mode 100644 Cocoa/GBSplitView.m diff --git a/Cocoa/Document.h b/Cocoa/Document.h index 412e6ff..0a7f7e8 100644 --- a/Cocoa/Document.h +++ b/Cocoa/Document.h @@ -1,8 +1,9 @@ #import #include "GBView.h" #include "GBImageView.h" +#include "GBSplitView.h" -@interface Document : NSDocument +@interface Document : NSDocument @property (strong) IBOutlet GBView *view; @property (strong) IBOutlet NSTextView *consoleOutput; @property (strong) IBOutlet NSPanel *consoleWindow; @@ -30,6 +31,8 @@ @property (strong) IBOutlet NSButton *feedSaveButton; @property (strong) IBOutlet NSTextView *debuggerSideViewInput; @property (strong) IBOutlet NSTextView *debuggerSideView; +@property (strong) IBOutlet GBSplitView *debuggerSplitView; +@property (strong) IBOutlet NSBox *debuggerVerticalLine; -(uint8_t) readMemory:(uint16_t) addr; -(void) writeMemory:(uint16_t) addr value:(uint8_t)value; diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 92d5f97..b7b56cf 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -505,6 +505,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [self.feedSaveButton removeFromSuperview]; self.consoleWindow.title = [NSString stringWithFormat:@"Debug Console – %@", [[self.fileURL path] lastPathComponent]]; + self.debuggerSplitView.dividerColor = [NSColor clearColor]; /* contentView.superview.subviews.lastObject is the titlebar view */ NSView *titleView = self.printerFeedWindow.contentView.superview.subviews.lastObject; @@ -1661,4 +1662,41 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } +- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; +{ + if ([[splitView arrangedSubviews] lastObject] == subview) { + return YES; + } + return NO; +} + +- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex +{ + return 600; +} + +- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { + return splitView.frame.size.width - 321; +} + +- (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view { + if ([[splitView arrangedSubviews] lastObject] == view) { + return NO; + } + return YES; +} + +- (void)splitViewDidResizeSubviews:(NSNotification *)notification +{ + NSSplitView *splitview = notification.object; + if ([[[splitview arrangedSubviews] firstObject] frame].size.width < 600) { + [splitview setPosition:600 ofDividerAtIndex:0]; + } + /* NSSplitView renders its separator without the proper vibrancy, so we made it transparent and move an + NSBox-based separator that renders properly so it acts like the split view's separator. */ + NSRect rect = self.debuggerVerticalLine.frame; + rect.origin.x = [[[splitview arrangedSubviews] firstObject] frame].size.width - 1; + self.debuggerVerticalLine.frame = rect; +} + @end diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib index ae9cf90..c680df5 100644 --- a/Cocoa/Document.xib +++ b/Cocoa/Document.xib @@ -1,8 +1,8 @@ - + - + @@ -14,6 +14,8 @@ + + @@ -39,7 +41,7 @@ - + @@ -50,11 +52,11 @@ - + - + @@ -67,7 +69,7 @@ - + @@ -78,38 +80,7 @@ - - - - - - - - - - - - - - - - - NSAllRomanInputSourcesLocaleIdentifier - - - - - - - - - - - - + @@ -124,83 +95,140 @@ - + - - - - - - - - - - - - - - - - NSAllRomanInputSourcesLocaleIdentifier - - - - - - - - - - - - - - - - - - - - - - - - - - - NSAllRomanInputSourcesLocaleIdentifier - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + + + + + + + - + @@ -208,7 +236,7 @@ - + @@ -248,7 +276,7 @@ - + @@ -265,7 +293,7 @@ - + @@ -284,7 +312,7 @@ - + @@ -292,13 +320,13 @@ - + - + - + @@ -307,17 +335,17 @@ - + - + - + @@ -326,7 +354,7 @@ - + @@ -358,7 +386,7 @@ - - + @@ -397,7 +425,7 @@ - + @@ -430,7 +458,7 @@ - + @@ -448,7 +476,7 @@ - + @@ -474,10 +502,10 @@ - + - + @@ -597,11 +625,11 @@ - - + @@ -765,7 +793,7 @@ - + diff --git a/Cocoa/GBSplitView.h b/Cocoa/GBSplitView.h new file mode 100644 index 0000000..143b8f6 --- /dev/null +++ b/Cocoa/GBSplitView.h @@ -0,0 +1,15 @@ +// +// GBSplitView.h +// SameBoySDL +// +// Created by Lior Halphon on 9/4/20. +// Copyright © 2020 Lior Halphon. All rights reserved. +// + +#import + +@interface GBSplitView : NSSplitView + +-(void) setDividerColor:(NSColor *)color; + +@end diff --git a/Cocoa/GBSplitView.m b/Cocoa/GBSplitView.m new file mode 100644 index 0000000..425d965 --- /dev/null +++ b/Cocoa/GBSplitView.m @@ -0,0 +1,28 @@ +// +// GBSplitView.m +// SameBoySDL +// +// Created by Lior Halphon on 9/4/20. +// Copyright © 2020 Lior Halphon. All rights reserved. +// + +#import "GBSplitView.h" + +@implementation GBSplitView +{ + NSColor *_dividerColor; +} + +- (void)setDividerColor:(NSColor *)color { + _dividerColor = color; + [self setNeedsDisplay:YES]; +} + +- (NSColor *)dividerColor { + if (_dividerColor) { + return _dividerColor; + } + return [super dividerColor]; +} + +@end From 1d80c185d85314c7d23b3e07d821ab1c3f88ea3b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 9 Apr 2020 17:25:14 +0300 Subject: [PATCH 079/125] Remove IDE comment --- Cocoa/GBSplitView.h | 8 -------- Cocoa/GBSplitView.m | 8 -------- 2 files changed, 16 deletions(-) diff --git a/Cocoa/GBSplitView.h b/Cocoa/GBSplitView.h index 143b8f6..7b2faa2 100644 --- a/Cocoa/GBSplitView.h +++ b/Cocoa/GBSplitView.h @@ -1,11 +1,3 @@ -// -// GBSplitView.h -// SameBoySDL -// -// Created by Lior Halphon on 9/4/20. -// Copyright © 2020 Lior Halphon. All rights reserved. -// - #import @interface GBSplitView : NSSplitView diff --git a/Cocoa/GBSplitView.m b/Cocoa/GBSplitView.m index 425d965..0a30fe0 100644 --- a/Cocoa/GBSplitView.m +++ b/Cocoa/GBSplitView.m @@ -1,11 +1,3 @@ -// -// GBSplitView.m -// SameBoySDL -// -// Created by Lior Halphon on 9/4/20. -// Copyright © 2020 Lior Halphon. All rights reserved. -// - #import "GBSplitView.h" @implementation GBSplitView From 337e74352d5666c20ebe4a5982fa3424a5c8406b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 9 Apr 2020 20:11:55 +0300 Subject: [PATCH 080/125] Add cheats API, with GameShark and GameGenie import --- Core/cheats.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++ Core/cheats.h | 33 ++++++++++ Core/gb.c | 3 + Core/gb.h | 6 ++ Core/memory.c | 6 +- 5 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 Core/cheats.c create mode 100644 Core/cheats.h diff --git a/Core/cheats.c b/Core/cheats.c new file mode 100644 index 0000000..36b4afb --- /dev/null +++ b/Core/cheats.c @@ -0,0 +1,173 @@ +#include "gb.h" +#include "cheats.h" +#include + +static inline uint8_t hash_addr(uint16_t addr) +{ + return addr; +} + +static uint16_t bank_for_addr(GB_gameboy_t *gb, uint16_t addr) +{ + if (addr < 0x4000) { + return gb->mbc_rom0_bank; + } + + if (addr < 0x8000) { + return gb->mbc_rom_bank; + } + + if (addr < 0xD000) { + return 0; + } + + if (addr < 0xE000) { + return gb->cgb_ram_bank; + } + + return 0; +} + +void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value) +{ + const GB_cheat_hash_t *hash = gb->cheat_hash[hash_addr(address)]; + if (hash) { + for (unsigned i = 0; i < hash->size; i++) { + GB_cheat_t *cheat = hash->cheats[i]; + if (cheat->address == address && cheat->enabled && (!cheat->use_old_value || cheat->old_value == *value)) { + if (cheat->bank == GB_CHEAT_ANY_BANK || cheat->bank == bank_for_addr(gb, address)) { + *value = cheat->value; + break; + } + } + } + } +} + +void GB_add_cheat(GB_gameboy_t *gb, const char *description, uint16_t address, uint16_t bank, uint8_t value, uint8_t old_value, bool use_old_value, bool enabled) +{ + GB_cheat_t *cheat = malloc(sizeof(*cheat)); + cheat->address = address; + cheat->bank = bank; + cheat->value = value; + cheat->old_value = old_value; + cheat->use_old_value = use_old_value; + cheat->enabled = enabled; + strncpy(cheat->description, description, sizeof(cheat->description)); + cheat->description[sizeof(cheat->description) - 1] = 0; + gb->cheats = realloc(gb->cheats, (++gb->cheat_count) * sizeof(*cheat)); + gb->cheats[gb->cheat_count - 1] = cheat; + + GB_cheat_hash_t **hash = &gb->cheat_hash[hash_addr(address)]; + if (!*hash) { + *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat)); + (*hash)->size = 1; + (*hash)->cheats[0] = cheat; + } + else { + (*hash)->size++; + *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + (*hash)->cheats[(*hash)->size - 1] = cheat; + } +} + +const GB_cheat_t *const *GB_get_cheats(GB_gameboy_t *gb, size_t *size) +{ + *size = gb->cheat_count; + return (void *)gb->cheats; +} +void GB_remove_cheat(GB_gameboy_t *gb, const GB_cheat_t *cheat) +{ + for (unsigned i = 0; i < gb->cheat_count; i++) { + if (gb->cheats[i] == cheat) { + gb->cheats[i] = gb->cheats[--gb->cheat_count]; + if (gb->cheat_count == 0) { + free(gb->cheats); + gb->cheats = NULL; + } + else { + gb->cheats = realloc(gb->cheats, gb->cheat_count * sizeof(*cheat)); + } + break; + } + } + + GB_cheat_hash_t **hash = &gb->cheat_hash[hash_addr(cheat->address)]; + for (unsigned i = 0; i < (*hash)->size; i++) { + if ((*hash)->cheats[i] == cheat) { + (*hash)->cheats[i] = (*hash)->cheats[(*hash)->size--]; + if ((*hash)->size == 0) { + free(*hash); + *hash = NULL; + } + else { + *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + } + break; + } + } + + free((void *)cheat); +} + +bool GB_import_cheat(GB_gameboy_t *gb, const char *cheat, const char *description, bool enabled) +{ + uint8_t dummy; + /* GameShark */ + { + uint8_t bank; + uint8_t value; + uint16_t address; + if (sscanf(cheat, "%02hhx%02hhx%04hx%c", &bank, &value, &address, &dummy) == 3) { + if (address > 0x7FFF) { + return false; + } + if (bank >= 0x80) { + bank &= 0xF; + } + GB_add_cheat(gb, description, address, bank, value, 0, false, enabled); + return true; + } + } + + /* GameGnie */ + { + char stripped_cheat[10] = {0,}; + for (unsigned i = 0; i < 9 && *cheat; i++) { + stripped_cheat[i] = *(cheat++); + while (*cheat == '-') { + cheat++; + } + } + + // Delete the 7th character; + stripped_cheat[7] = stripped_cheat[8]; + stripped_cheat[8] = 0; + + uint8_t old_value; + uint8_t value; + uint16_t address; + if (sscanf(stripped_cheat, "%02hhx%04hx%02hhx%c", &value, &address, &old_value, &dummy) == 3) { + address = (uint16_t)(address >> 4) | (uint16_t)(address << 12); + address ^= 0xF000; + if (address > 0x7FFF) { + return false; + } + old_value = (uint8_t)(old_value >> 2) | (uint8_t)(old_value << 6); + old_value ^= 0xBA; + GB_add_cheat(gb, description, address, GB_CHEAT_ANY_BANK, value, old_value, true, enabled); + return true; + } + + if (sscanf(stripped_cheat, "%02hhx%04hx%c", &value, &address, &dummy) == 2) { + address = (uint16_t)(address >> 4) | (uint16_t)(address << 12); + address ^= 0xF000; + if (address > 0x7FFF) { + return false; + } + GB_add_cheat(gb, description, address, GB_CHEAT_ANY_BANK, value, false, true, enabled); + return true; + } + } + return false; +} diff --git a/Core/cheats.h b/Core/cheats.h new file mode 100644 index 0000000..c461f22 --- /dev/null +++ b/Core/cheats.h @@ -0,0 +1,33 @@ +#ifndef cheats_h +#define cheats_h +#include "gb_struct_def.h" + +#define GB_CHEAT_ANY_BANK 0xFFFF + +typedef struct GB_cheat_s GB_cheat_t; + +void GB_add_cheat(GB_gameboy_t *gb, const char *description, uint16_t address, uint16_t bank, uint8_t value, uint8_t old_value, bool use_old_value, bool enabled); +bool GB_import_cheat(GB_gameboy_t *gb, const char *cheat, const char *description, bool enabled); +const GB_cheat_t *const *GB_get_cheats(GB_gameboy_t *gb, size_t *size); +void GB_remove_cheat(GB_gameboy_t *gb, const GB_cheat_t *cheat); + +#ifdef GB_INTERNAL +void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value); +#endif + +typedef struct { + size_t size; + GB_cheat_t *cheats[]; +} GB_cheat_hash_t; + +struct GB_cheat_s { + uint16_t address; + uint16_t bank; + uint8_t value; + uint8_t old_value; + bool use_old_value; + bool enabled; + char description[128]; +}; + +#endif diff --git a/Core/gb.c b/Core/gb.c index ba3f20a..75538e1 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -197,6 +197,9 @@ void GB_free(GB_gameboy_t *gb) GB_debugger_clear_symbols(gb); #endif GB_rewind_free(gb); + while (gb->cheats) { + GB_remove_cheat(gb, gb->cheats[0]); + } memset(gb, 0, sizeof(*gb)); } diff --git a/Core/gb.h b/Core/gb.h index 1f3bacf..8a60770 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -21,6 +21,7 @@ #include "sm83_cpu.h" #include "symbol_hash.h" #include "sgb.h" +#include "cheats.h" #define GB_STRUCT_VERSION 13 @@ -644,6 +645,11 @@ struct GB_gameboy_internal_s { double sgb_intro_jingle_phases[7]; double sgb_intro_sweep_phase; double sgb_intro_sweep_previous_sample; + + /* Cheats */ + size_t cheat_count; + GB_cheat_t **cheats; + GB_cheat_hash_t *cheat_hash[256]; /* Misc */ bool turbo; diff --git a/Core/memory.c b/Core/memory.c index 27f58e1..58b96bb 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -435,12 +435,12 @@ uint8_t GB_read_memory(GB_gameboy_t *gb, uint16_t addr) if (is_addr_in_dma_use(gb, addr)) { addr = gb->dma_current_src; } + uint8_t data = read_map[addr >> 12](gb, addr); + GB_apply_cheat(gb, addr, &data); if (gb->read_memory_callback) { - uint8_t data = read_map[addr >> 12](gb, addr); data = gb->read_memory_callback(gb, addr, data); - return data; } - return read_map[addr >> 12](gb, addr); + return data; } static void write_mbc(GB_gameboy_t *gb, uint16_t addr, uint8_t value) From 852a6997ed869d14a5d92d97e62165dd3532cee5 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 18:03:10 +0300 Subject: [PATCH 081/125] Add cheats UI to Cocoa --- Cocoa/Document.h | 1 + Cocoa/Document.m | 13 ++ Cocoa/Document.xib | 293 +++++++++++++++++++++++++++-- Cocoa/GBCheatTextFieldCell.h | 5 + Cocoa/GBCheatTextFieldCell.m | 121 ++++++++++++ Cocoa/GBCheatWindowController.h | 17 ++ Cocoa/GBCheatWindowController.m | 234 +++++++++++++++++++++++ Cocoa/GBImageCell.m | 2 +- Cocoa/GBImageView.m | 2 +- Cocoa/GBOptionalVisualEffectView.h | 6 + Cocoa/GBOptionalVisualEffectView.m | 18 ++ Cocoa/MainMenu.xib | 18 ++ Core/cheats.c | 69 ++++++- Core/cheats.h | 3 + Core/gb.h | 1 + Makefile | 2 +- 16 files changed, 782 insertions(+), 23 deletions(-) create mode 100644 Cocoa/GBCheatTextFieldCell.h create mode 100644 Cocoa/GBCheatTextFieldCell.m create mode 100644 Cocoa/GBCheatWindowController.h create mode 100644 Cocoa/GBCheatWindowController.m create mode 100644 Cocoa/GBOptionalVisualEffectView.h create mode 100644 Cocoa/GBOptionalVisualEffectView.m diff --git a/Cocoa/Document.h b/Cocoa/Document.h index 0a7f7e8..1117c26 100644 --- a/Cocoa/Document.h +++ b/Cocoa/Document.h @@ -33,6 +33,7 @@ @property (strong) IBOutlet NSTextView *debuggerSideView; @property (strong) IBOutlet GBSplitView *debuggerSplitView; @property (strong) IBOutlet NSBox *debuggerVerticalLine; +@property (strong) IBOutlet NSPanel *cheatsWindow; -(uint8_t) readMemory:(uint16_t) addr; -(void) writeMemory:(uint16_t) addr value:(uint8_t)value; diff --git a/Cocoa/Document.m b/Cocoa/Document.m index b7b56cf..71436d3 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -706,6 +706,9 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) else if ([anItem action] == @selector(connectPrinter:)) { [(NSMenuItem*)anItem setState:accessory == GBAccessoryPrinter]; } + else if ([anItem action] == @selector(toggleCheats:)) { + [(NSMenuItem*)anItem setState:GB_cheats_enabled(&gb)]; + } return [super validateUserInterfaceItem:anItem]; } @@ -1699,4 +1702,14 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) self.debuggerVerticalLine.frame = rect; } +- (IBAction)showCheats:(id)sender +{ + [self.cheatsWindow makeKeyAndOrderFront:nil]; +} + +- (IBAction)toggleCheats:(id)sender +{ + GB_set_cheats_enabled(&gb, !GB_cheats_enabled(&gb)); +} + @end diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib index c680df5..338650b 100644 --- a/Cocoa/Document.xib +++ b/Cocoa/Document.xib @@ -9,6 +9,7 @@ + @@ -44,8 +45,7 @@ - - + @@ -69,11 +69,10 @@ - + - - + @@ -103,7 +102,7 @@ - + @@ -228,11 +227,10 @@ - - + + - - + @@ -312,11 +310,10 @@ - - + + - - + @@ -784,10 +781,9 @@ - - - - + + + @@ -803,7 +799,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Cocoa/GBCheatTextFieldCell.h b/Cocoa/GBCheatTextFieldCell.h new file mode 100644 index 0000000..473e0f3 --- /dev/null +++ b/Cocoa/GBCheatTextFieldCell.h @@ -0,0 +1,5 @@ +#import + +@interface GBCheatTextFieldCell : NSTextFieldCell +@property bool usesAddressFormat; +@end diff --git a/Cocoa/GBCheatTextFieldCell.m b/Cocoa/GBCheatTextFieldCell.m new file mode 100644 index 0000000..611cade --- /dev/null +++ b/Cocoa/GBCheatTextFieldCell.m @@ -0,0 +1,121 @@ +#import "GBCheatTextFieldCell.h" + +@interface GBCheatTextView : NSTextView +@property bool usesAddressFormat; +@end + +@implementation GBCheatTextView + +- (bool)_insertText:(NSString *)string replacementRange:(NSRange)range +{ + if (range.location == NSNotFound) { + range = self.selectedRange; + } + + NSString *new = [self.string stringByReplacingCharactersInRange:range withString:string]; + if (!self.usesAddressFormat) { + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^(\\$[0-9A-Fa-f]{1,2}|[0-9]{1,3})$" options:0 error:NULL]; + if ([regex numberOfMatchesInString:new options:0 range:NSMakeRange(0, new.length)]) { + [super insertText:string replacementRange:range]; + return true; + } + if ([regex numberOfMatchesInString:[@"$" stringByAppendingString:new] options:0 range:NSMakeRange(0, new.length + 1)]) { + [super insertText:string replacementRange:range]; + [super insertText:@"$" replacementRange:NSMakeRange(0, 0)]; + return true; + } + if ([new isEqualToString:@"$"] || [string length] == 0) { + self.string = @"$00"; + self.selectedRange = NSMakeRange(1, 2); + return true; + } + } + else { + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^(\\$[0-9A-Fa-f]{1,3}:)?\\$[0-9a-fA-F]{1,4}$" options:0 error:NULL]; + if ([regex numberOfMatchesInString:new options:0 range:NSMakeRange(0, new.length)]) { + [super insertText:string replacementRange:range]; + return true; + } + if ([string length] == 0) { + NSUInteger index = [new rangeOfString:@":"].location; + if (index != NSNotFound) { + if (range.location > index) { + self.string = [[new componentsSeparatedByString:@":"] firstObject]; + self.selectedRange = NSMakeRange(self.string.length, 0); + return true; + } + self.string = [[new componentsSeparatedByString:@":"] lastObject]; + self.selectedRange = NSMakeRange(0, 0); + return true; + } + else if ([[self.string substringWithRange:range] isEqualToString:@":"]) { + self.string = [[self.string componentsSeparatedByString:@":"] lastObject]; + self.selectedRange = NSMakeRange(0, 0); + return true; + } + } + if ([new isEqualToString:@"$"] || [string length] == 0) { + self.string = @"$0000"; + self.selectedRange = NSMakeRange(1, 4); + return true; + } + if (([string isEqualToString:@"$"] || [string isEqualToString:@":"]) && range.length == 0 && range.location == 0) { + if ([self _insertText:@"$00:" replacementRange:range]) { + self.selectedRange = NSMakeRange(1, 2); + return true; + } + } + if ([string isEqualToString:@":"] && range.length + range.location == self.string.length) { + if ([self _insertText:@":$0" replacementRange:range]) { + self.selectedRange = NSMakeRange(self.string.length - 2, 2); + return true; + } + } + if ([string isEqualToString:@"$"]) { + if ([self _insertText:@"$0" replacementRange:range]) { + self.selectedRange = NSMakeRange(range.location + 1, 1); + return true; + } + } + } + return false; +} + +- (NSUndoManager *)undoManager +{ + return nil; +} + +- (void)insertText:(id)string replacementRange:(NSRange)replacementRange +{ + if (![self _insertText:string replacementRange:replacementRange]) { + NSBeep(); + } +} + +/* Private API, don't tell the police! */ +- (void)_userReplaceRange:(NSRange)range withString:(NSString *)string +{ + [self insertText:string replacementRange:range]; +} + +@end + +@implementation GBCheatTextFieldCell +{ + bool _drawing, _editing; + GBCheatTextView *_fieldEditor; +} + +- (NSTextView *)fieldEditorForView:(NSView *)controlView +{ + if (_fieldEditor) { + _fieldEditor.usesAddressFormat = self.usesAddressFormat; + return _fieldEditor; + } + _fieldEditor = [[GBCheatTextView alloc] initWithFrame:controlView.frame]; + _fieldEditor.fieldEditor = YES; + _fieldEditor.usesAddressFormat = self.usesAddressFormat; + return _fieldEditor; +} +@end diff --git a/Cocoa/GBCheatWindowController.h b/Cocoa/GBCheatWindowController.h new file mode 100644 index 0000000..adb0bf8 --- /dev/null +++ b/Cocoa/GBCheatWindowController.h @@ -0,0 +1,17 @@ +#import +#import +#import "Document.h" + +@interface GBCheatWindowController : NSObject +@property (weak) IBOutlet NSTableView *cheatsTable; +@property (weak) IBOutlet NSTextField *addressField; +@property (weak) IBOutlet NSTextField *valueField; +@property (weak) IBOutlet NSTextField *oldValueField; +@property (weak) IBOutlet NSButton *oldValueCheckbox; +@property (weak) IBOutlet NSTextField *descriptionField; +@property (weak) IBOutlet NSTextField *importCodeField; +@property (weak) IBOutlet NSTextField *importDescriptionField; +@property (weak) IBOutlet Document *document; + +@end + diff --git a/Cocoa/GBCheatWindowController.m b/Cocoa/GBCheatWindowController.m new file mode 100644 index 0000000..994d5e1 --- /dev/null +++ b/Cocoa/GBCheatWindowController.m @@ -0,0 +1,234 @@ +#import "GBCheatWindowController.h" +#import "GBWarningPopover.h" +#import "GBCheatTextFieldCell.h" + +@implementation GBCheatWindowController + ++ (NSString *)addressStringFromCheat:(const GB_cheat_t *)cheat +{ + if (cheat->bank != GB_CHEAT_ANY_BANK) { + return [NSString stringWithFormat:@"$%x:$%04x", cheat->bank, cheat->address]; + } + return [NSString stringWithFormat:@"$%04x", cheat->address]; +} + ++ (NSString *)actionDescriptionForCheat:(const GB_cheat_t *)cheat +{ + if (cheat->use_old_value) { + return [NSString stringWithFormat:@"[%@]($%02x) = $%02x", [self addressStringFromCheat:cheat], cheat->old_value, cheat->value]; + } + return [NSString stringWithFormat:@"[%@] = $%02x", [self addressStringFromCheat:cheat], cheat->value]; +} + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView +{ + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return 0; + size_t cheatCount; + GB_get_cheats(gb, &cheatCount); + return cheatCount + 1; +} + +- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row +{ + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return nil; + size_t cheatCount; + GB_get_cheats(gb, &cheatCount); + NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; + if (row >= cheatCount && columnIndex == 0) { + return [[NSCell alloc] init]; + } + return nil; +} + +- (nullable id)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row +{ + size_t cheatCount; + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return nil; + const GB_cheat_t *const *cheats = GB_get_cheats(gb, &cheatCount); + NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; + if (row >= cheatCount) { + switch (columnIndex) { + case 0: + return @(YES); + + case 1: + return @NO; + + case 2: + return @"Add Cheat..."; + + case 3: + return @""; + } + } + + switch (columnIndex) { + case 0: + return @(NO); + + case 1: + return @(cheats[row]->enabled); + + case 2: + return @(cheats[row]->description); + + case 3: + return [GBCheatWindowController actionDescriptionForCheat:cheats[row]]; + } + + return nil; +} + +- (IBAction)importCheat:(id)sender +{ + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return; + + [self.document performAtomicBlock:^{ + if (GB_import_cheat(gb, + self.importCodeField.stringValue.UTF8String, + self.importDescriptionField.stringValue.UTF8String, + true)) { + self.importCodeField.stringValue = @""; + self.importDescriptionField.stringValue = @""; + [self.cheatsTable reloadData]; + [self tableViewSelectionDidChange:nil]; + } + else { + NSBeep(); + [GBWarningPopover popoverWithContents:@"This code is not a valid GameShark or GameGenie code" onView:self.importCodeField]; + } + }]; +} + +- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row +{ + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return; + size_t cheatCount; + const GB_cheat_t *const *cheats = GB_get_cheats(gb, &cheatCount); + NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; + [self.document performAtomicBlock:^{ + if (columnIndex == 1) { + if (row >= cheatCount) { + GB_add_cheat(gb, "New Cheat", 0, 0, 0, 0, false, true); + } + else { + GB_update_cheat(gb, cheats[row], cheats[row]->description, cheats[row]->address, cheats[row]->bank, cheats[row]->value, cheats[row]->old_value, cheats[row]->use_old_value, !cheats[row]->enabled); + } + } + else if (row < cheatCount) { + GB_remove_cheat(gb, cheats[row]); + } + }]; + [self.cheatsTable reloadData]; + [self tableViewSelectionDidChange:nil]; +} + +- (void)tableViewSelectionDidChange:(NSNotification *)notification +{ + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return; + + size_t cheatCount; + const GB_cheat_t *const *cheats = GB_get_cheats(gb, &cheatCount); + unsigned row = self.cheatsTable.selectedRow; + const GB_cheat_t *cheat = NULL; + if (row >= cheatCount) { + static const GB_cheat_t template = { + .address = 0, + .bank = 0, + .value = 0, + .old_value = 0, + .use_old_value = false, + .enabled = false, + .description = "New Cheat", + }; + cheat = &template; + } + else { + cheat = cheats[row]; + } + + self.addressField.stringValue = [GBCheatWindowController addressStringFromCheat:cheat]; + self.valueField.stringValue = [NSString stringWithFormat:@"$%02x", cheat->value]; + self.oldValueField.stringValue = [NSString stringWithFormat:@"$%02x", cheat->old_value]; + self.oldValueCheckbox.state = cheat->use_old_value; + self.descriptionField.stringValue = @(cheat->description); +} + +- (void)awakeFromNib +{ + [self tableViewSelectionDidChange:nil]; + ((GBCheatTextFieldCell *)self.addressField.cell).usesAddressFormat = true; +} + +- (void)controlTextDidChange:(NSNotification *)obj +{ + [self updateCheat:nil]; +} + +- (IBAction)updateCheat:(id)sender +{ + GB_gameboy_t *gb = self.document.gameboy; + if (!gb) return; + + uint16_t address = 0; + uint16_t bank = GB_CHEAT_ANY_BANK; + if ([self.addressField.stringValue rangeOfString:@":"].location != NSNotFound) { + sscanf(self.addressField.stringValue.UTF8String, "$%hx:$%hx", &bank, &address); + } + else { + sscanf(self.addressField.stringValue.UTF8String, "$%hx", &address); + } + + uint8_t value = 0; + if ([self.valueField.stringValue characterAtIndex:0] == '$') { + sscanf(self.valueField.stringValue.UTF8String, "$%02hhx", &value); + } + else { + sscanf(self.valueField.stringValue.UTF8String, "%hhd", &value); + } + + uint8_t oldValue = 0; + if ([self.oldValueField.stringValue characterAtIndex:0] == '$') { + sscanf(self.oldValueField.stringValue.UTF8String, "$%02hhx", &oldValue); + } + else { + sscanf(self.oldValueField.stringValue.UTF8String, "%hhd", &oldValue); + } + + size_t cheatCount; + const GB_cheat_t *const *cheats = GB_get_cheats(gb, &cheatCount); + unsigned row = self.cheatsTable.selectedRow; + + [self.document performAtomicBlock:^{ + if (row >= cheatCount) { + GB_add_cheat(gb, + self.descriptionField.stringValue.UTF8String, + address, + bank, + value, + oldValue, + self.oldValueCheckbox.state, + false); + } + else { + GB_update_cheat(gb, + cheats[row], + self.descriptionField.stringValue.UTF8String, + address, + bank, + value, + oldValue, + self.oldValueCheckbox.state, + cheats[row]->enabled); + } + }]; + [self.cheatsTable reloadData]; +} + +@end diff --git a/Cocoa/GBImageCell.m b/Cocoa/GBImageCell.m index 6f54ec8..de75e0e 100644 --- a/Cocoa/GBImageCell.m +++ b/Cocoa/GBImageCell.m @@ -3,7 +3,7 @@ @implementation GBImageCell - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { - CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; + CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; CGContextSetInterpolationQuality(context, kCGInterpolationNone); [super drawWithFrame:cellFrame inView:controlView]; } diff --git a/Cocoa/GBImageView.m b/Cocoa/GBImageView.m index 973625e..47efa00 100644 --- a/Cocoa/GBImageView.m +++ b/Cocoa/GBImageView.m @@ -16,7 +16,7 @@ } - (void)drawRect:(NSRect)dirtyRect { - CGContextRef context = [[NSGraphicsContext currentContext] CGContext]; + CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; CGContextSetInterpolationQuality(context, kCGInterpolationNone); [super drawRect:dirtyRect]; CGFloat y_ratio = self.frame.size.height / self.image.size.height; diff --git a/Cocoa/GBOptionalVisualEffectView.h b/Cocoa/GBOptionalVisualEffectView.h new file mode 100644 index 0000000..1355071 --- /dev/null +++ b/Cocoa/GBOptionalVisualEffectView.h @@ -0,0 +1,6 @@ +#import + +/* Fake interface so the compiler assumes it conforms to NSVisualEffectView */ +@interface GBOptionalVisualEffectView : NSVisualEffectView + +@end diff --git a/Cocoa/GBOptionalVisualEffectView.m b/Cocoa/GBOptionalVisualEffectView.m new file mode 100644 index 0000000..c28eb59 --- /dev/null +++ b/Cocoa/GBOptionalVisualEffectView.m @@ -0,0 +1,18 @@ +#import + +@interface GBOptionalVisualEffectView : NSView + +@end + +@implementation GBOptionalVisualEffectView + ++ (instancetype)allocWithZone:(struct _NSZone *)zone +{ + Class NSVisualEffectView = NSClassFromString(@"NSVisualEffectView"); + if (NSVisualEffectView) { + return (id)[NSVisualEffectView alloc]; + } + return [super allocWithZone:zone]; +} + +@end diff --git a/Cocoa/MainMenu.xib b/Cocoa/MainMenu.xib index ee989ee..e56b4a0 100644 --- a/Cocoa/MainMenu.xib +++ b/Cocoa/MainMenu.xib @@ -345,6 +345,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/Core/cheats.c b/Core/cheats.c index 36b4afb..fa9b6a7 100644 --- a/Core/cheats.c +++ b/Core/cheats.c @@ -1,6 +1,7 @@ #include "gb.h" #include "cheats.h" #include +#include static inline uint8_t hash_addr(uint16_t addr) { @@ -30,6 +31,8 @@ static uint16_t bank_for_addr(GB_gameboy_t *gb, uint16_t addr) void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value) { + if (!gb->cheat_enabled) return; + if (!gb->boot_rom_finished) return; const GB_cheat_hash_t *hash = gb->cheat_hash[hash_addr(address)]; if (hash) { for (unsigned i = 0; i < hash->size; i++) { @@ -44,6 +47,16 @@ void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value) } } +bool GB_cheats_enabled(GB_gameboy_t *gb) +{ + return gb->cheat_enabled; +} + +void GB_set_cheats_enabled(GB_gameboy_t *gb, bool enabled) +{ + gb->cheat_enabled = enabled; +} + void GB_add_cheat(GB_gameboy_t *gb, const char *description, uint16_t address, uint16_t bank, uint8_t value, uint8_t old_value, bool use_old_value, bool enabled) { GB_cheat_t *cheat = malloc(sizeof(*cheat)); @@ -66,7 +79,7 @@ void GB_add_cheat(GB_gameboy_t *gb, const char *description, uint16_t address, u } else { (*hash)->size++; - *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + *hash = realloc(*hash, sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); (*hash)->cheats[(*hash)->size - 1] = cheat; } } @@ -171,3 +184,57 @@ bool GB_import_cheat(GB_gameboy_t *gb, const char *cheat, const char *descriptio } return false; } + +void GB_update_cheat(GB_gameboy_t *gb, const GB_cheat_t *_cheat, const char *description, uint16_t address, uint16_t bank, uint8_t value, uint8_t old_value, bool use_old_value, bool enabled) +{ + GB_cheat_t *cheat = NULL; + for (unsigned i = 0; i < gb->cheat_count; i++) { + if (gb->cheats[i] == _cheat) { + cheat = gb->cheats[i]; + break; + } + } + + assert(cheat); + + if (cheat->address != address) { + /* Remove from old bucket */ + GB_cheat_hash_t **hash = &gb->cheat_hash[hash_addr(cheat->address)]; + for (unsigned i = 0; i < (*hash)->size; i++) { + if ((*hash)->cheats[i] == cheat) { + (*hash)->cheats[i] = (*hash)->cheats[(*hash)->size--]; + if ((*hash)->size == 0) { + free(*hash); + *hash = NULL; + } + else { + *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + } + break; + } + } + cheat->address = address; + + /* Add to new bucket */ + hash = &gb->cheat_hash[hash_addr(address)]; + if (!*hash) { + *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat)); + (*hash)->size = 1; + (*hash)->cheats[0] = cheat; + } + else { + (*hash)->size++; + *hash = malloc(sizeof(GB_cheat_hash_t) + sizeof(cheat) * (*hash)->size); + (*hash)->cheats[(*hash)->size - 1] = cheat; + } + } + cheat->bank = bank; + cheat->value = value; + cheat->old_value = old_value; + cheat->use_old_value = use_old_value; + cheat->enabled = enabled; + if (description != cheat->description) { + strncpy(cheat->description, description, sizeof(cheat->description)); + cheat->description[sizeof(cheat->description) - 1] = 0; + } +} diff --git a/Core/cheats.h b/Core/cheats.h index c461f22..be5b39a 100644 --- a/Core/cheats.h +++ b/Core/cheats.h @@ -7,9 +7,12 @@ typedef struct GB_cheat_s GB_cheat_t; void GB_add_cheat(GB_gameboy_t *gb, const char *description, uint16_t address, uint16_t bank, uint8_t value, uint8_t old_value, bool use_old_value, bool enabled); +void GB_update_cheat(GB_gameboy_t *gb, const GB_cheat_t *cheat, const char *description, uint16_t address, uint16_t bank, uint8_t value, uint8_t old_value, bool use_old_value, bool enabled); bool GB_import_cheat(GB_gameboy_t *gb, const char *cheat, const char *description, bool enabled); const GB_cheat_t *const *GB_get_cheats(GB_gameboy_t *gb, size_t *size); void GB_remove_cheat(GB_gameboy_t *gb, const GB_cheat_t *cheat); +bool GB_cheats_enabled(GB_gameboy_t *gb); +void GB_set_cheats_enabled(GB_gameboy_t *gb, bool enabled); #ifdef GB_INTERNAL void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value); diff --git a/Core/gb.h b/Core/gb.h index 8a60770..03abfa1 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -647,6 +647,7 @@ struct GB_gameboy_internal_s { double sgb_intro_sweep_previous_sample; /* Cheats */ + bool cheat_enabled; size_t cheat_count; GB_cheat_t **cheats; GB_cheat_hash_t *cheat_hash[256]; diff --git a/Makefile b/Makefile index 7c22375..5923b2e 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ OPEN_DIALOG = OpenDialog/cocoa.m endif -CFLAGS += -Werror -Wall -Wno-unused-result -Wno-strict-aliasing -Wno-unknown-warning -Wno-unknown-warning-option -Wno-multichar -Wno-int-in-bool-context -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES +CFLAGS += -Werror -Wall -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-unknown-warning -Wno-unknown-warning-option -Wno-multichar -Wno-int-in-bool-context -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES ifeq (,$(PKG_CONFIG)) SDL_CFLAGS := $(shell sdl2-config --cflags) SDL_LDFLAGS := $(shell sdl2-config --libs) From 2bc75caf9efe0c4f44bd2e6f9bcc154664a7402b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 18:03:21 +0300 Subject: [PATCH 082/125] Fix CRT shader on OpenGL --- Shaders/CRT.fsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shaders/CRT.fsh b/Shaders/CRT.fsh index c1ae7ef..0bc4c65 100644 --- a/Shaders/CRT.fsh +++ b/Shaders/CRT.fsh @@ -159,7 +159,7 @@ STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 ou } // Gamma correction - ret = pow(ret, 0.72); + ret = pow(ret, vec4(0.72)); return ret; } From 0c3db932b22e3ba9e033ce4391c9d8dd5b99f0d6 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 18:19:15 +0300 Subject: [PATCH 083/125] Fix Mavericks compatibility --- Cocoa/Document.m | 14 ++++++-------- Cocoa/GBSplitView.h | 2 +- Cocoa/GBSplitView.m | 10 ++++++++++ Cocoa/GBViewMetal.m | 2 ++ Cocoa/NSObject+MavericksCompat.m | 7 +++++++ Makefile | 2 +- 6 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 Cocoa/NSObject+MavericksCompat.m diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 71436d3..0114658 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -817,9 +817,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } if (![console_output_timer isValid]) { - console_output_timer = [NSTimer timerWithTimeInterval:(NSTimeInterval)0.05 repeats:NO block:^(NSTimer * _Nonnull timer) { - [self appendPendingOutput]; - }]; + console_output_timer = [NSTimer timerWithTimeInterval:(NSTimeInterval)0.05 target:self selector:@selector(appendPendingOutput) userInfo:nil repeats:NO]; [[NSRunLoop mainRunLoop] addTimer:console_output_timer forMode:NSDefaultRunLoopMode]; } @@ -1665,7 +1663,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } -- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; +- (BOOL)splitView:(GBSplitView *)splitView canCollapseSubview:(NSView *)subview; { if ([[splitView arrangedSubviews] lastObject] == subview) { return YES; @@ -1673,16 +1671,16 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) return NO; } -- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex +- (CGFloat)splitView:(GBSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex { return 600; } -- (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { +- (CGFloat)splitView:(GBSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { return splitView.frame.size.width - 321; } -- (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view { +- (BOOL)splitView:(GBSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view { if ([[splitView arrangedSubviews] lastObject] == view) { return NO; } @@ -1691,7 +1689,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) - (void)splitViewDidResizeSubviews:(NSNotification *)notification { - NSSplitView *splitview = notification.object; + GBSplitView *splitview = notification.object; if ([[[splitview arrangedSubviews] firstObject] frame].size.width < 600) { [splitview setPosition:600 ofDividerAtIndex:0]; } diff --git a/Cocoa/GBSplitView.h b/Cocoa/GBSplitView.h index 7b2faa2..6ab97cf 100644 --- a/Cocoa/GBSplitView.h +++ b/Cocoa/GBSplitView.h @@ -3,5 +3,5 @@ @interface GBSplitView : NSSplitView -(void) setDividerColor:(NSColor *)color; - +- (NSArray *)arrangedSubviews; @end diff --git a/Cocoa/GBSplitView.m b/Cocoa/GBSplitView.m index 0a30fe0..0fb3bc4 100644 --- a/Cocoa/GBSplitView.m +++ b/Cocoa/GBSplitView.m @@ -17,4 +17,14 @@ return [super dividerColor]; } +/* Mavericks comaptibility */ +- (NSArray *)arrangedSubviews +{ + if (@available(macOS 10.11, *)) { + return [super arrangedSubviews]; + } else { + return [self subviews]; + } +} + @end diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 4c8a5d5..62deadc 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -1,4 +1,6 @@ #import "GBViewMetal.h" +#pragma clang diagnostic ignored "-Wpartial-availability" + static const vector_float2 rect[] = { diff --git a/Cocoa/NSObject+MavericksCompat.m b/Cocoa/NSObject+MavericksCompat.m new file mode 100644 index 0000000..6c06514 --- /dev/null +++ b/Cocoa/NSObject+MavericksCompat.m @@ -0,0 +1,7 @@ +#import +@implementation NSObject (MavericksCompat) +- (instancetype)initWithCoder:(NSCoder *)coder +{ + return [self init]; +} +@end diff --git a/Makefile b/Makefile index 5923b2e..36a893d 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ OPEN_DIALOG = OpenDialog/cocoa.m endif -CFLAGS += -Werror -Wall -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-unknown-warning -Wno-unknown-warning-option -Wno-multichar -Wno-int-in-bool-context -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES +CFLAGS += -Werror -Wall -Wpartial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-unknown-warning -Wno-unknown-warning-option -Wno-multichar -Wno-int-in-bool-context -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES ifeq (,$(PKG_CONFIG)) SDL_CFLAGS := $(shell sdl2-config --cflags) SDL_LDFLAGS := $(shell sdl2-config --libs) From 5df45417fad1c9467d75dff40b3de7b4369af490 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 18:27:31 +0300 Subject: [PATCH 084/125] Console quirks --- Cocoa/Document.m | 3 ++- Cocoa/Document.xib | 36 ++++++++++++++++++------------------ Core/debugger.c | 5 +++-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 0114658..3c83fab 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -470,7 +470,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) - (void)windowControllerDidLoadNib:(NSWindowController *)aController { [super windowControllerDidLoadNib:aController]; - + // Interface Builder bug? + [self.consoleWindow setContentSize:self.consoleWindow.minSize]; /* Close Open Panels, if any */ for (NSWindow *window in [[NSApplication sharedApplication] windows]) { if ([window isKindOfClass:[NSOpenPanel class]]) { diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib index 338650b..f096bb3 100644 --- a/Cocoa/Document.xib +++ b/Cocoa/Document.xib @@ -107,22 +107,22 @@ - + - + - + - + - + @@ -137,29 +137,29 @@ - + - + - + - + - + - + @@ -173,27 +173,27 @@ - + - + - + - + - + - + @@ -208,7 +208,7 @@ - + diff --git a/Core/debugger.c b/Core/debugger.c index 4e3bd63..94fae80 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -1766,10 +1766,11 @@ static const debugger_command_t commands[] = { {"next", 1, next, "Run the next instruction, skipping over function calls"}, {"step", 1, step, "Run the next instruction, stepping into function calls"}, {"finish", 1, finish, "Run until the current function returns"}, - {"backtrace", 2, backtrace, "Display the current call stack"}, + {"backtrace", 2, backtrace, "Displays the current call stack"}, {"bt", 2, }, /* Alias */ {"sld", 3, stack_leak_detection, "Like finish, but stops if a stack leak is detected (Experimental)"}, - {"ticks", 2, ticks, "Display the number of CPU ticks since the last time 'ticks' was used"}, + {"ticks", 2, ticks, "Displays the number of CPU ticks since the last time 'ticks' was" HELP_NEWLINE + "used"}, {"registers", 1, registers, "Print values of processor registers and other important registers"}, {"cartridge", 2, mbc, "Displays information about the MBC and cartridge"}, {"mbc", 3, }, /* Alias */ From 0abd3b2c469dc65eb09120c4a6811af1da83b678 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 19:15:40 +0300 Subject: [PATCH 085/125] Dump and load cheats --- Cocoa/Document.h | 3 ++ Cocoa/Document.m | 4 +++ Cocoa/Document.xib | 4 ++- Core/cheats.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++ Core/cheats.h | 2 ++ 5 files changed, 88 insertions(+), 1 deletion(-) diff --git a/Cocoa/Document.h b/Cocoa/Document.h index 1117c26..9353788 100644 --- a/Cocoa/Document.h +++ b/Cocoa/Document.h @@ -3,6 +3,8 @@ #include "GBImageView.h" #include "GBSplitView.h" +@class GBCheatWindowController; + @interface Document : NSDocument @property (strong) IBOutlet GBView *view; @property (strong) IBOutlet NSTextView *consoleOutput; @@ -34,6 +36,7 @@ @property (strong) IBOutlet GBSplitView *debuggerSplitView; @property (strong) IBOutlet NSBox *debuggerVerticalLine; @property (strong) IBOutlet NSPanel *cheatsWindow; +@property (strong) IBOutlet GBCheatWindowController *cheatWindowController; -(uint8_t) readMemory:(uint16_t) addr; -(void) writeMemory:(uint16_t) addr value:(uint8_t)value; diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 3c83fab..823204c 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -7,6 +7,7 @@ #include "HexFiend/HexFiend.h" #include "GBMemoryByteArray.h" #include "GBWarningPopover.h" +#include "GBCheatWindowController.h" /* Todo: The general Objective-C coding style conflicts with SameBoy's. This file needs a cleanup. */ /* Todo: Split into category files! This is so messy!!! */ @@ -359,6 +360,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) self.audioClient = nil; self.view.mouseHidingEnabled = NO; GB_save_battery(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sav"] UTF8String]); + GB_save_cheats(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"cht"] UTF8String]); stopping = false; } @@ -643,6 +645,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSString *rom_warnings = [self captureOutputForBlock:^{ GB_load_rom(&gb, [self.fileName UTF8String]); GB_load_battery(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sav"] UTF8String]); + GB_load_cheats(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"cht"] UTF8String]); + [self.cheatWindowController.cheatsTable reloadData]; GB_debugger_clear_symbols(&gb); GB_debugger_load_symbol_file(&gb, [[[NSBundle mainBundle] pathForResource:@"registers" ofType:@"sym"] UTF8String]); GB_debugger_load_symbol_file(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sym"] UTF8String]); diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib index f096bb3..f1f2f5a 100644 --- a/Cocoa/Document.xib +++ b/Cocoa/Document.xib @@ -9,6 +9,8 @@ + + @@ -1056,7 +1058,7 @@ - + diff --git a/Core/cheats.c b/Core/cheats.c index fa9b6a7..0525816 100644 --- a/Core/cheats.c +++ b/Core/cheats.c @@ -2,6 +2,7 @@ #include "cheats.h" #include #include +#include static inline uint8_t hash_addr(uint16_t addr) { @@ -238,3 +239,78 @@ void GB_update_cheat(GB_gameboy_t *gb, const GB_cheat_t *_cheat, const char *des cheat->description[sizeof(cheat->description) - 1] = 0; } } + +#define CHEAT_MAGIC 'SBCh' + +void GB_load_cheats(GB_gameboy_t *gb, const char *path) +{ + FILE *f = fopen(path, "rb"); + if (!f) { + return; + } + + uint32_t magic = 0; + uint32_t struct_size = 0; + fread(&magic, sizeof(magic), 1, f); + fread(&struct_size, sizeof(struct_size), 1, f); + if (magic != CHEAT_MAGIC && magic != __builtin_bswap32(CHEAT_MAGIC)) { + GB_log(gb, "The file is not a SameBoy cheat database"); + return; + } + + if (struct_size != sizeof(GB_cheat_t)) { + GB_log(gb, "This cheat database is not compatible with this version of SameBoy"); + return; + } + + // Remove all cheats first + while (gb->cheats) { + GB_remove_cheat(gb, gb->cheats[0]); + } + + GB_cheat_t cheat; + while (fread(&cheat, sizeof(cheat), 1, f)) { + if (magic == __builtin_bswap32(CHEAT_MAGIC)) { + cheat.address = __builtin_bswap16(cheat.address); + cheat.bank = __builtin_bswap16(cheat.bank); + } + cheat.description[sizeof(cheat.description) - 1] = 0; + GB_add_cheat(gb, cheat.description, cheat.address, cheat.bank, cheat.value, cheat.old_value, cheat.use_old_value, cheat.enabled); + } + + return; +} + +int GB_save_cheats(GB_gameboy_t *gb, const char *path) +{ + if (!gb->cheat_count) return 0; // Nothing to save. + FILE *f = fopen(path, "wb"); + if (!f) { + GB_log(gb, "Could not dump cheat database: %s.\n", strerror(errno)); + return errno; + } + + uint32_t magic = CHEAT_MAGIC; + uint32_t struct_size = sizeof(GB_cheat_t); + + if (fwrite(&magic, sizeof(magic), 1, f) != 1) { + fclose(f); + return EIO; + } + + if (fwrite(&struct_size, sizeof(struct_size), 1, f) != 1) { + fclose(f); + return EIO; + } + + for (size_t i = 0; i cheat_count; i++) { + if (fwrite(gb->cheats[i], sizeof(*gb->cheats[i]), 1, f) != 1) { + fclose(f); + return EIO; + } + } + + errno = 0; + fclose(f); + return errno; +} diff --git a/Core/cheats.h b/Core/cheats.h index be5b39a..13b7d7b 100644 --- a/Core/cheats.h +++ b/Core/cheats.h @@ -13,6 +13,8 @@ const GB_cheat_t *const *GB_get_cheats(GB_gameboy_t *gb, size_t *size); void GB_remove_cheat(GB_gameboy_t *gb, const GB_cheat_t *cheat); bool GB_cheats_enabled(GB_gameboy_t *gb); void GB_set_cheats_enabled(GB_gameboy_t *gb, bool enabled); +void GB_load_cheats(GB_gameboy_t *gb, const char *path); +int GB_save_cheats(GB_gameboy_t *gb, const char *path); #ifdef GB_INTERNAL void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value); From 695c6ee943d661a40db8fbd3914605e7d2b29a46 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 19:21:00 +0300 Subject: [PATCH 086/125] Don't crash if a naughty frontend runs the boot ROM without a ROM --- Core/display.c | 2 +- Core/gb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index 356e742..67a9fc4 100644 --- a/Core/display.c +++ b/Core/display.c @@ -165,7 +165,7 @@ static void display_vblank(GB_gameboy_t *gb) 0x30DA, 0x69AD, 0x2B57, 0x2B5D, 0x632C, 0x1050, 0x3C84, 0x0E07, 0x0E18, 0x2964, }; - unsigned index = gb->rom[0x14e] % 5; + unsigned index = gb->rom? gb->rom[0x14e] % 5 : 0; gb->borrowed_border.palette[0] = colors[index]; gb->borrowed_border.palette[10] = colors[5 + index]; gb->borrowed_border.palette[14] = colors[10 + index]; diff --git a/Core/gb.c b/Core/gb.c index 75538e1..3b834dd 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -230,7 +230,7 @@ void GB_borrow_sgb_border(GB_gameboy_t *gb) if (gb->border_mode != GB_BORDER_ALWAYS) return; if (gb->tried_loading_sgb_border) return; gb->tried_loading_sgb_border = true; - if (gb->rom[0x146] != 3) return; // Not an SGB game, nothing to borrow + if (gb->rom && gb->rom[0x146] != 3) return; // Not an SGB game, nothing to borrow if (!gb->boot_rom_load_callback) return; // Can't borrow a border without this callback GB_gameboy_t sgb; GB_init(&sgb, GB_MODEL_SGB); From 32a0dc0e435a54bc70d2403d85a2996ced757a52 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 20:44:15 +0300 Subject: [PATCH 087/125] Rename the "Developer" menu to "Develop", like first party Mac apps --- Cocoa/MainMenu.xib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cocoa/MainMenu.xib b/Cocoa/MainMenu.xib index e56b4a0..71add1c 100644 --- a/Cocoa/MainMenu.xib +++ b/Cocoa/MainMenu.xib @@ -382,9 +382,9 @@ - + - + From db9410caa5f4a518984ba298fcb6688d5e6cef68 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 11 Apr 2020 21:48:47 +0300 Subject: [PATCH 088/125] Minor UI fix --- Cocoa/Document.m | 2 +- Cocoa/GBCheatWindowController.h | 2 +- Cocoa/GBCheatWindowController.m | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 823204c..10ba510 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -646,7 +646,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) GB_load_rom(&gb, [self.fileName UTF8String]); GB_load_battery(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sav"] UTF8String]); GB_load_cheats(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"cht"] UTF8String]); - [self.cheatWindowController.cheatsTable reloadData]; + [self.cheatWindowController cheatsUpdated]; GB_debugger_clear_symbols(&gb); GB_debugger_load_symbol_file(&gb, [[[NSBundle mainBundle] pathForResource:@"registers" ofType:@"sym"] UTF8String]); GB_debugger_load_symbol_file(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sym"] UTF8String]); diff --git a/Cocoa/GBCheatWindowController.h b/Cocoa/GBCheatWindowController.h index adb0bf8..f70553e 100644 --- a/Cocoa/GBCheatWindowController.h +++ b/Cocoa/GBCheatWindowController.h @@ -12,6 +12,6 @@ @property (weak) IBOutlet NSTextField *importCodeField; @property (weak) IBOutlet NSTextField *importDescriptionField; @property (weak) IBOutlet Document *document; - +- (void)cheatsUpdated; @end diff --git a/Cocoa/GBCheatWindowController.m b/Cocoa/GBCheatWindowController.m index 994d5e1..c10e2a9 100644 --- a/Cocoa/GBCheatWindowController.m +++ b/Cocoa/GBCheatWindowController.m @@ -231,4 +231,10 @@ [self.cheatsTable reloadData]; } +- (void)cheatsUpdated +{ + [self.cheatsTable reloadData]; + [self tableViewSelectionDidChange:nil]; +} + @end From d38fd41b0eaa2a598fd88f6d5d37fcb52f257598 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Apr 2020 20:18:56 +0300 Subject: [PATCH 089/125] Reorder flags so -Wpartial-availablility is affected by -Wno-unknown-warning -Wno-unknown-warning-option, fixes #249, fixes #251 --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 36a893d..ba568ff 100644 --- a/Makefile +++ b/Makefile @@ -87,8 +87,13 @@ ifeq ($(PLATFORM),Darwin) OPEN_DIALOG = OpenDialog/cocoa.m endif +# These myst come before the -Wno- flags +CFLAGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option + +CFLAGS += -Wpartial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context + +CFLAGS += -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES -CFLAGS += -Werror -Wall -Wpartial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-unknown-warning -Wno-unknown-warning-option -Wno-multichar -Wno-int-in-bool-context -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES ifeq (,$(PKG_CONFIG)) SDL_CFLAGS := $(shell sdl2-config --cflags) SDL_LDFLAGS := $(shell sdl2-config --libs) From 0cf168f32beb6c98dcfb8d6cd17659f1bbf53c45 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Apr 2020 20:37:57 +0300 Subject: [PATCH 090/125] Fixing inconsistent style --- BootROMs/pb8.c | 33 ++++-- Cocoa/Document.m | 27 +++-- Cocoa/GBAudioClient.m | 6 +- Cocoa/GBGLShader.m | 2 +- Cocoa/GBImageView.m | 2 +- Cocoa/GBOpenGLView.m | 3 +- Cocoa/GBSplitView.m | 9 +- Cocoa/GBTerminalTextFieldCell.m | 3 +- Cocoa/GBView.m | 6 +- Cocoa/GBViewMetal.m | 3 +- Cocoa/joypad.m | 12 ++- Cocoa/main.m | 3 +- Core/apu.c | 4 +- Core/debugger.c | 22 ++-- Core/display.c | 2 +- Core/gb.c | 6 +- Core/gb.h | 6 +- Core/memory.c | 2 +- Core/save_state.c | 2 +- Core/sgb.c | 4 +- Core/sm83_cpu.c | 10 +- Core/sm83_disassembler.c | 3 +- Core/timing.c | 15 +-- OpenDialog/gtk.c | 3 +- OpenDialog/windows.c | 3 +- QuickLook/generator.m | 2 +- QuickLook/main.c | 30 +++--- SDL/gui.c | 8 +- SDL/main.c | 5 +- SDL/opengl_compat.h | 2 +- Tester/main.c | 4 +- Windows/stdio.h | 3 +- libretro/libretro.c | 175 ++++++++++++-------------------- 33 files changed, 197 insertions(+), 223 deletions(-) diff --git a/BootROMs/pb8.c b/BootROMs/pb8.c index 03a196e..4ee4524 100644 --- a/BootROMs/pb8.c +++ b/BootROMs/pb8.c @@ -97,7 +97,8 @@ LoadTileset: * @param blocklength size of an independent input block in bytes * @return 0 for reaching infp end of file, or EOF for error */ -int pb8(FILE *infp, FILE *outfp, size_t blocklength) { +int pb8(FILE *infp, FILE *outfp, size_t blocklength) +{ blocklength >>= 3; // convert bytes to blocks assert(blocklength > 0); while (1) { @@ -113,7 +114,8 @@ int pb8(FILE *infp, FILE *outfp, size_t blocklength) { control_byte <<= 1; if (c == last_byte) { control_byte |= 0x01; - } else { + } + else { literals[nliterals++] = last_byte = c; } } @@ -143,7 +145,8 @@ int pb8(FILE *infp, FILE *outfp, size_t blocklength) { * @param outfp output stream * @return 0 for reaching infp end of file, or EOF for error */ -int unpb8(FILE *infp, FILE *outfp) { +int unpb8(FILE *infp, FILE *outfp) +{ int last_byte = 0; while (1) { int control_byte = fgetc(infp); @@ -165,7 +168,8 @@ int unpb8(FILE *infp, FILE *outfp) { /* CLI frontend ****************************************************/ -static inline void set_fd_binary(unsigned int fd) { +static inline void set_fd_binary(unsigned int fd) +{ #ifdef _WIN32 _setmode(fd, _O_BINARY); #else @@ -197,7 +201,8 @@ static const char *version_msg = static const char *toomanyfilenames_msg = "pb8: too many filenames; try pb8 --help\n"; -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ const char *infilename = NULL; const char *outfilename = NULL; bool decompress = false; @@ -248,11 +253,14 @@ int main(int argc, char **argv) { fprintf(stderr, "pb8: unknown option -%c\n", argtype); return EXIT_FAILURE; } - } else if (!infilename) { + } + else if (!infilename) { infilename = argv[i]; - } else if (!outfilename) { + } + else if (!outfilename) { outfilename = argv[i]; - } else { + } + else { fputs(toomanyfilenames_msg, stderr); return EXIT_FAILURE; } @@ -282,7 +290,8 @@ int main(int argc, char **argv) { perror("for reading"); return EXIT_FAILURE; } - } else { + } + else { infp = stdin; set_fd_binary(0); } @@ -296,7 +305,8 @@ int main(int argc, char **argv) { fclose(infp); return EXIT_FAILURE; } - } else { + } + else { outfp = stdout; set_fd_binary(1); } @@ -305,7 +315,8 @@ int main(int argc, char **argv) { int has_ferror = 0; if (decompress) { compfailed = unpb8(infp, outfp); - } else { + } + else { compfailed = pb8(infp, outfp, blocklength); } fflush(outfp); diff --git a/Cocoa/Document.m b/Cocoa/Document.m index 10ba510..ed3eaaf 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -150,7 +150,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSMutableArray *debugger_input_queue; } -- (instancetype)init { +- (instancetype)init +{ self = [super init]; if (self) { has_debugger_input = [[NSConditionLock alloc] initWithCondition:0]; @@ -470,7 +471,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) } } -- (void)windowControllerDidLoadNib:(NSWindowController *)aController { +- (void)windowControllerDidLoadNib:(NSWindowController *)aController +{ [super windowControllerDidLoadNib:aController]; // Interface Builder bug? [self.consoleWindow setContentSize:self.consoleWindow.minSize]; @@ -625,11 +627,13 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) self.memoryBankItem.enabled = false; } -+ (BOOL)autosavesInPlace { ++ (BOOL)autosavesInPlace +{ return YES; } -- (NSString *)windowNibName { +- (NSString *)windowNibName +{ // Override returning the nib file name of the document // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. return @"Document"; @@ -690,7 +694,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) - (BOOL)validateUserInterfaceItem:(id)anItem { - if([anItem action] == @selector(mute:)) { + if ([anItem action] == @selector(mute:)) { [(NSMenuItem*)anItem setState:!self.audioClient.isPlaying]; } else if ([anItem action] == @selector(togglePause:)) { @@ -837,7 +841,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [self.consoleWindow orderBack:nil]; } -- (IBAction)consoleInput:(NSTextField *)sender { +- (IBAction)consoleInput:(NSTextField *)sender +{ NSString *line = [sender stringValue]; if ([line isEqualToString:@""] && lastConsoleInput) { line = lastConsoleInput; @@ -1475,7 +1480,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) NSUInteger columnIndex = [[tableView tableColumns] indexOfObject:tableColumn]; if (tableView == self.paletteTableView) { if (columnIndex == 0) { - return [NSString stringWithFormat:@"%s %u", row >=8 ? "Object" : "Background", (unsigned)(row & 7)]; + return [NSString stringWithFormat:@"%s %u", row >= 8 ? "Object" : "Background", (unsigned)(row & 7)]; } uint8_t *palette_data = GB_get_direct_access(&gb, row >= 8? GB_DIRECT_ACCESS_OBP : GB_DIRECT_ACCESS_BGP, NULL, NULL); @@ -1572,7 +1577,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) [self stop]; NSSavePanel * savePanel = [NSSavePanel savePanel]; [savePanel setAllowedFileTypes:@[@"png"]]; - [savePanel beginSheetModalForWindow:self.printerFeedWindow completionHandler:^(NSInteger result){ + [savePanel beginSheetModalForWindow:self.printerFeedWindow completionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { [savePanel orderOut:self]; CGImageRef cgRef = [self.feedImageView.image CGImageForProposedRect:NULL @@ -1681,11 +1686,13 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) return 600; } -- (CGFloat)splitView:(GBSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { +- (CGFloat)splitView:(GBSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex +{ return splitView.frame.size.width - 321; } -- (BOOL)splitView:(GBSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view { +- (BOOL)splitView:(GBSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)view +{ if ([[splitView arrangedSubviews] lastObject] == view) { return NO; } diff --git a/Cocoa/GBAudioClient.m b/Cocoa/GBAudioClient.m index 81ddec4..7f2115d 100644 --- a/Cocoa/GBAudioClient.m +++ b/Cocoa/GBAudioClient.m @@ -26,8 +26,7 @@ static OSStatus render( -(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block andSampleRate:(UInt32) rate { - if(!(self = [super init])) - { + if (!(self = [super init])) { return nil; } @@ -102,7 +101,8 @@ static OSStatus render( _playing = NO; } --(void) dealloc { +-(void) dealloc +{ [self stop]; AudioUnitUninitialize(audioUnit); AudioComponentInstanceDispose(audioUnit); diff --git a/Cocoa/GBGLShader.m b/Cocoa/GBGLShader.m index d57f43d..920226b 100644 --- a/Cocoa/GBGLShader.m +++ b/Cocoa/GBGLShader.m @@ -169,7 +169,7 @@ void main(void) {\n\ + (GLuint)shaderWithContents:(NSString*)contents type:(GLenum)type { - const GLchar* source = [contents UTF8String]; + const GLchar *source = [contents UTF8String]; // Create the shader object GLuint shader = glCreateShader(type); // Load the shader source diff --git a/Cocoa/GBImageView.m b/Cocoa/GBImageView.m index 47efa00..3525e72 100644 --- a/Cocoa/GBImageView.m +++ b/Cocoa/GBImageView.m @@ -93,7 +93,7 @@ - (void)updateTrackingAreas { - if(trackingArea != nil) { + if (trackingArea != nil) { [self removeTrackingArea:trackingArea]; } diff --git a/Cocoa/GBOpenGLView.m b/Cocoa/GBOpenGLView.m index 8831b62..90ebf8d 100644 --- a/Cocoa/GBOpenGLView.m +++ b/Cocoa/GBOpenGLView.m @@ -4,7 +4,8 @@ @implementation GBOpenGLView -- (void)drawRect:(NSRect)dirtyRect { +- (void)drawRect:(NSRect)dirtyRect +{ if (!self.shader) { self.shader = [[GBGLShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]]; } diff --git a/Cocoa/GBSplitView.m b/Cocoa/GBSplitView.m index 0fb3bc4..a56c24e 100644 --- a/Cocoa/GBSplitView.m +++ b/Cocoa/GBSplitView.m @@ -5,12 +5,14 @@ NSColor *_dividerColor; } -- (void)setDividerColor:(NSColor *)color { +- (void)setDividerColor:(NSColor *)color +{ _dividerColor = color; [self setNeedsDisplay:YES]; } -- (NSColor *)dividerColor { +- (NSColor *)dividerColor +{ if (_dividerColor) { return _dividerColor; } @@ -22,7 +24,8 @@ { if (@available(macOS 10.11, *)) { return [super arrangedSubviews]; - } else { + } + else { return [self subviews]; } } diff --git a/Cocoa/GBTerminalTextFieldCell.m b/Cocoa/GBTerminalTextFieldCell.m index 47a3a35..e95e785 100644 --- a/Cocoa/GBTerminalTextFieldCell.m +++ b/Cocoa/GBTerminalTextFieldCell.m @@ -173,7 +173,8 @@ [super setSelectedRanges:ranges affinity:affinity stillSelecting:stillSelectingFlag]; } -- (BOOL)resignFirstResponder { +- (BOOL)resignFirstResponder +{ reverse_search_mode = false; return [super resignFirstResponder]; } diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index 0e52811..6f26a03 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -114,8 +114,7 @@ } - (instancetype)initWithCoder:(NSCoder *)coder { - if (!(self = [super initWithCoder:coder])) - { + if (!(self = [super initWithCoder:coder])) { return self; } [self _init]; @@ -124,8 +123,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect { - if (!(self = [super initWithFrame:frameRect])) - { + if (!(self = [super initWithFrame:frameRect])) { return self; } [self _init]; diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 62deadc..9a1c78b 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -159,8 +159,7 @@ static const vector_float2 rect[] = MTLRenderPassDescriptor *render_pass_descriptor = view.currentRenderPassDescriptor; id command_buffer = [command_queue commandBuffer]; - if (render_pass_descriptor != nil) - { + if (render_pass_descriptor != nil) { *(GB_frame_blending_mode_t *)[frame_blending_mode_buffer contents] = [self frameBlendingMode]; *(vector_float2 *)[output_resolution_buffer contents] = output_resolution; diff --git a/Cocoa/joypad.m b/Cocoa/joypad.m index 2ffe56b..fd9fe70 100755 --- a/Cocoa/joypad.m +++ b/Cocoa/joypad.m @@ -295,7 +295,8 @@ AddHIDElements(CFArrayRef array, recDevice *pDevice) } static bool -ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) { +ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) +{ while (listitem) { if (listitem->cookie == cookie) { return true; @@ -431,7 +432,8 @@ AddHIDElement(const void *value, void *parameter) } if (elementPrevious) { elementPrevious->pNext = element; - } else { + } + else { *headElement = element; } @@ -519,7 +521,8 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice) *guid16++ = 0; *guid16++ = version; *guid16++ = 0; - } else { + } + else { *guid16++ = BUS_BLUETOOTH; *guid16++ = 0; strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4); @@ -582,7 +585,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) value = GetHIDElementState(device, element) - element->min; if (range == 4) { /* 4 position hatswitch - scale up value */ value *= 2; - } else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */ + } + else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */ value = -1; } if ((unsigned)value >= 8) { diff --git a/Cocoa/main.m b/Cocoa/main.m index 8a6799b..662469a 100644 --- a/Cocoa/main.m +++ b/Cocoa/main.m @@ -1,5 +1,6 @@ #import -int main(int argc, const char * argv[]) { +int main(int argc, const char * argv[]) +{ return NSApplicationMain(argc, argv); } diff --git a/Core/apu.c b/Core/apu.c index feda3c8..e63d89f 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -139,7 +139,7 @@ static double smooth(double x) static void render(GB_gameboy_t *gb) { - GB_sample_t output = {0,0}; + GB_sample_t output = {0, 0}; UNROLL for (unsigned i = 0; i < GB_N_CHANNELS; i++) { @@ -907,7 +907,7 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) gb->apu.is_active[GB_NOISE] = false; update_sample(gb, GB_NOISE, 0, 0); } - else if (gb->apu.is_active[GB_NOISE]){ + else if (gb->apu.is_active[GB_NOISE]) { nrx2_glitch(&gb->apu.noise_channel.current_volume, value, gb->io_registers[reg]); update_sample(gb, GB_NOISE, gb->apu.current_lfsr_sample ? diff --git a/Core/debugger.c b/Core/debugger.c index 94fae80..ee27e88 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -298,13 +298,15 @@ static void write_lvalue(GB_gameboy_t *gb, lvalue_t lvalue, uint16_t value) static value_t add(value_t a, value_t b) {return FIX_BANK(a.value + b.value);} static value_t sub(value_t a, value_t b) {return FIX_BANK(a.value - b.value);} static value_t mul(value_t a, value_t b) {return FIX_BANK(a.value * b.value);} -static value_t _div(value_t a, value_t b) { +static value_t _div(value_t a, value_t b) +{ if (b.value == 0) { return FIX_BANK(0); } return FIX_BANK(a.value / b.value); }; -static value_t mod(value_t a, value_t b) { +static value_t mod(value_t a, value_t b) +{ if (b.value == 0) { return FIX_BANK(0); } @@ -380,8 +382,7 @@ static lvalue_t debugger_evaluate_lvalue(GB_gameboy_t *gb, const char *string, while (length && (string[length-1] == ' ' || string[length-1] == '\n' || string[length-1] == '\r' || string[length-1] == '\t')) { length--; } - if (length == 0) - { + if (length == 0) { GB_log(gb, "Expected expression.\n"); *error = true; return (lvalue_t){0,}; @@ -487,8 +488,7 @@ value_t debugger_evaluate(GB_gameboy_t *gb, const char *string, while (length && (string[length-1] == ' ' || string[length-1] == '\n' || string[length-1] == '\r' || string[length-1] == '\t')) { length--; } - if (length == 0) - { + if (length == 0) { GB_log(gb, "Expected expression.\n"); *error = true; goto exit; @@ -1167,7 +1167,7 @@ static bool unwatch(GB_gameboy_t *gb, char *arguments, char *modifiers, const de memmove(&gb->watchpoints[index], &gb->watchpoints[index + 1], (gb->n_watchpoints - index - 1) * sizeof(gb->watchpoints[0])); gb->n_watchpoints--; - gb->watchpoints = realloc(gb->watchpoints, gb->n_watchpoints* sizeof(gb->watchpoints[0])); + gb->watchpoints = realloc(gb->watchpoints, gb->n_watchpoints *sizeof(gb->watchpoints[0])); GB_log(gb, "Watchpoint removed from %s\n", debugger_value_to_string(gb, result, true)); return true; @@ -1216,7 +1216,7 @@ static bool list(GB_gameboy_t *gb, char *arguments, char *modifiers, const debug gb->watchpoints[i].condition); } else { - GB_log(gb, " %d. %s (%c%c)\n", i + 1, debugger_value_to_string(gb,addr, addr.has_bank), + GB_log(gb, " %d. %s (%c%c)\n", i + 1, debugger_value_to_string(gb, addr, addr.has_bank), (gb->watchpoints[i].flags & GB_WATCHPOINT_R)? 'r' : '-', (gb->watchpoints[i].flags & GB_WATCHPOINT_W)? 'w' : '-'); } @@ -1581,7 +1581,7 @@ static bool lcd(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg } GB_log(gb, "LY: %d\n", gb->io_registers[GB_IO_LY]); GB_log(gb, "LYC: %d\n", gb->io_registers[GB_IO_LYC]); - GB_log(gb, "Window position: %d, %d\n", (signed) gb->io_registers[GB_IO_WX] - 7 , gb->io_registers[GB_IO_WY]); + GB_log(gb, "Window position: %d, %d\n", (signed) gb->io_registers[GB_IO_WX] - 7, gb->io_registers[GB_IO_WY]); GB_log(gb, "Interrupt line: %s\n", gb->stat_interrupt_line? "On" : "Off"); return true; @@ -1730,7 +1730,7 @@ static bool wave(GB_gameboy_t *gb, char *arguments, char *modifiers, const debug uint8_t shift_amount = 1, mask; if (modifiers) { - switch(modifiers[0]) { + switch (modifiers[0]) { case 'c': shift_amount = 2; break; @@ -1826,7 +1826,7 @@ static const debugger_command_t *find_command(const char *string) static void print_command_shortcut(GB_gameboy_t *gb, const debugger_command_t *command) { GB_attributed_log(gb, GB_LOG_BOLD | GB_LOG_UNDERLINE, "%.*s", command->min_length, command->command); - GB_attributed_log(gb, GB_LOG_BOLD , "%s", command->command + command->min_length); + GB_attributed_log(gb, GB_LOG_BOLD, "%s", command->command + command->min_length); } static void print_command_description(GB_gameboy_t *gb, const debugger_command_t *command) diff --git a/Core/display.c b/Core/display.c index 67a9fc4..b5c0a0a 100644 --- a/Core/display.c +++ b/Core/display.c @@ -530,7 +530,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) *dest = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel]; } } - + if (gb->model & GB_MODEL_NO_SFC_BIT) { if (gb->icd_pixel_callback) { gb->icd_pixel_callback(gb, icd_pixel); diff --git a/Core/gb.c b/Core/gb.c index 3b834dd..f6174b9 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -119,7 +119,7 @@ static void load_default_border(GB_gameboy_t *gb) }\ }\ }\ - } while(false); + } while (false); if (gb->model == GB_MODEL_AGB) { #include "graphics/agb_border.inc" @@ -658,8 +658,8 @@ void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) #endif } -const GB_palette_t GB_PALETTE_GREY = {{{0x00, 0x00, 0x00}, {0x55, 0x55, 0x55}, {0xaa, 0xaa, 0xaa}, {0xff ,0xff, 0xff}, {0xff ,0xff, 0xff}}}; -const GB_palette_t GB_PALETTE_DMG = {{{0x08, 0x18, 0x10}, {0x39, 0x61, 0x39}, {0x84, 0xa5, 0x63}, {0xc6, 0xde, 0x8c}, {0xd2 ,0xe6 ,0xa6}}}; +const GB_palette_t GB_PALETTE_GREY = {{{0x00, 0x00, 0x00}, {0x55, 0x55, 0x55}, {0xaa, 0xaa, 0xaa}, {0xff, 0xff, 0xff}, {0xff, 0xff, 0xff}}}; +const GB_palette_t GB_PALETTE_DMG = {{{0x08, 0x18, 0x10}, {0x39, 0x61, 0x39}, {0x84, 0xa5, 0x63}, {0xc6, 0xde, 0x8c}, {0xd2, 0xe6, 0xa6}}}; const GB_palette_t GB_PALETTE_MGB = {{{0x07, 0x10, 0x0e}, {0x3a, 0x4c, 0x3a}, {0x81, 0x8d, 0x66}, {0xc2, 0xce, 0x93}, {0xcf, 0xda, 0xac}}}; const GB_palette_t GB_PALETTE_GBL = {{{0x0a, 0x1c, 0x15}, {0x35, 0x78, 0x62}, {0x56, 0xb4, 0x95}, {0x7f, 0xe2, 0xc3}, {0x91, 0xea, 0xd0}}}; diff --git a/Core/gb.h b/Core/gb.h index 03abfa1..01b79e8 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -53,7 +53,7 @@ typedef struct { struct { - uint8_t r,g,b; + uint8_t r, g, b; } colors[5]; } GB_palette_t; @@ -254,11 +254,11 @@ typedef enum { #define INTERNAL_DIV_CYCLES (0x40000) #if !defined(MIN) -#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) +#define MIN(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) #endif #if !defined(MAX) -#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) +#define MAX(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) #endif #endif diff --git a/Core/memory.c b/Core/memory.c index 58b96bb..ca9c179 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -277,7 +277,7 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) case GB_MODEL_SGB_PAL_NO_SFC: case GB_MODEL_SGB2: case GB_MODEL_SGB2_NO_SFC: - ; + break; } } diff --git a/Core/save_state.c b/Core/save_state.c index a53ccba..11024df 100644 --- a/Core/save_state.c +++ b/Core/save_state.c @@ -361,7 +361,7 @@ int GB_load_state_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t le return -1; } - if (buffer_read(gb->vram,gb->vram_size, &buffer, &length) != gb->vram_size) { + if (buffer_read(gb->vram, gb->vram_size, &buffer, &length) != gb->vram_size) { return -1; } diff --git a/Core/sgb.c b/Core/sgb.c index 271b681..c77b0db 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -151,7 +151,7 @@ static void command_ready(GB_gameboy_t *gb) 0xE content bytes. The last command, FB, is padded with zeros, so information past the header is not sent. */ if ((gb->sgb->command[0] & 0xF1) == 0xF1) { - if(gb->boot_rom_finished) return; + if (gb->boot_rom_finished) return; uint8_t checksum = 0; for (unsigned i = 2; i < 0x10; i++) { @@ -247,7 +247,7 @@ static void command_ready(GB_gameboy_t *gb) gb->sgb->attribute_map[x + 20 * y] = inside_palette; } } - else if(middle) { + else if (middle) { gb->sgb->attribute_map[x + 20 * y] = middle_palette; } } diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 2b7b1dd..13f05df 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -452,7 +452,7 @@ static void ld_da16_sp(GB_gameboy_t *gb, uint8_t opcode) addr = cycle_read_inc_oam_bug(gb, gb->pc++); addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8; cycle_write(gb, addr, gb->registers[GB_REGISTER_SP] & 0xFF); - cycle_write(gb, addr+1, gb->registers[GB_REGISTER_SP] >> 8); + cycle_write(gb, addr + 1, gb->registers[GB_REGISTER_SP] >> 8); } static void add_hl_rr(GB_gameboy_t *gb, uint8_t opcode) @@ -1222,7 +1222,7 @@ static void ld_a_da16(GB_gameboy_t *gb, uint8_t opcode) uint16_t addr; gb->registers[GB_REGISTER_AF] &= 0xFF; addr = cycle_read_inc_oam_bug(gb, gb->pc++); - addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8 ; + addr |= cycle_read_inc_oam_bug(gb, gb->pc++) << 8; gb->registers[GB_REGISTER_AF] |= cycle_read(gb, addr) << 8; } @@ -1410,10 +1410,10 @@ static void bit_r(GB_gameboy_t *gb, uint8_t opcode) } } else if ((opcode & 0xC0) == 0x80) { /* res */ - set_src_value(gb, opcode, value & ~bit) ; + set_src_value(gb, opcode, value & ~bit); } else if ((opcode & 0xC0) == 0xC0) { /* set */ - set_src_value(gb, opcode, value | bit) ; + set_src_value(gb, opcode, value | bit); } } @@ -1567,7 +1567,7 @@ void GB_cpu_run(GB_gameboy_t *gb) GB_debugger_call_hook(gb, call_addr); } /* Run mode */ - else if(!gb->halted) { + else if (!gb->halted) { gb->last_opcode_read = cycle_read_inc_oam_bug(gb, gb->pc++); if (gb->halt_bug) { gb->pc--; diff --git a/Core/sm83_disassembler.c b/Core/sm83_disassembler.c index 96aec00..7dacd9e 100644 --- a/Core/sm83_disassembler.c +++ b/Core/sm83_disassembler.c @@ -97,7 +97,8 @@ static void rla(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc) GB_log(gb, "RLA\n"); } -static void ld_da16_sp(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc){ +static void ld_da16_sp(GB_gameboy_t *gb, uint8_t opcode, uint16_t *pc) +{ uint16_t addr; (*pc)++; addr = GB_read_memory(gb, (*pc)++); diff --git a/Core/timing.c b/Core/timing.c index 1f3f654..9eb9c91 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -274,19 +274,14 @@ void GB_rtc_run(GB_gameboy_t *gb) time_t current_time = time(NULL); while (gb->last_rtc_second < current_time) { gb->last_rtc_second++; - if (++gb->rtc_real.seconds == 60) - { + if (++gb->rtc_real.seconds == 60) { gb->rtc_real.seconds = 0; - if (++gb->rtc_real.minutes == 60) - { + if (++gb->rtc_real.minutes == 60) { gb->rtc_real.minutes = 0; - if (++gb->rtc_real.hours == 24) - { + if (++gb->rtc_real.hours == 24) { gb->rtc_real.hours = 0; - if (++gb->rtc_real.days == 0) - { - if (gb->rtc_real.high & 1) /* Bit 8 of days*/ - { + if (++gb->rtc_real.days == 0) { + if (gb->rtc_real.high & 1) { /* Bit 8 of days*/ gb->rtc_real.high |= 0x80; /* Overflow bit */ } gb->rtc_real.high ^= 1; diff --git a/OpenDialog/gtk.c b/OpenDialog/gtk.c index 7947ea2..d9163fc 100644 --- a/OpenDialog/gtk.c +++ b/OpenDialog/gtk.c @@ -88,8 +88,7 @@ char *do_open_rom_dialog(void) int res = gtk_dialog_run (dialog); char *ret = NULL; - if (res == GTK_RESPONSE_ACCEPT) - { + if (res == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename(dialog); ret = strdup(filename); diff --git a/OpenDialog/windows.c b/OpenDialog/windows.c index 75fe767..6bf9b89 100644 --- a/OpenDialog/windows.c +++ b/OpenDialog/windows.c @@ -17,8 +17,7 @@ char *do_open_rom_dialog(void) dialog.lpstrInitialDir = NULL; dialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - if (GetOpenFileNameW(&dialog) == TRUE) - { + if (GetOpenFileNameW(&dialog) == TRUE) { char *ret = malloc(MAX_PATH * 4); WideCharToMultiByte(CP_UTF8, 0, filename, sizeof(filename), ret, MAX_PATH * 4, NULL, NULL); return ret; diff --git a/QuickLook/generator.m b/QuickLook/generator.m index 1aa0087..c3c13dc 100644 --- a/QuickLook/generator.m +++ b/QuickLook/generator.m @@ -79,7 +79,7 @@ static OSStatus render(CGContextRef cgContext, CFURLRef url, bool showBorder) } /* Mask it with the template (The middle part of the template image is transparent) */ - [effectiveTemplate drawInRect:(NSRect){{0,0},template.size}]; + [effectiveTemplate drawInRect:(NSRect){{0, 0}, template.size}]; } CGColorSpaceRelease(colorSpaceRef); diff --git a/QuickLook/main.c b/QuickLook/main.c index 8566e32..1d1676a 100644 --- a/QuickLook/main.c +++ b/QuickLook/main.c @@ -43,8 +43,8 @@ typedef struct __QuickLookGeneratorPluginType QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID); void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance); -HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv); -void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID); +HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv); +void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID); ULONG QuickLookGeneratorPluginAddRef(void *thisInstance); ULONG QuickLookGeneratorPluginRelease(void *thisInstance); @@ -77,11 +77,11 @@ QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFact QuickLookGeneratorPluginType *theNewInstance; theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType)); - memset(theNewInstance,0,sizeof(QuickLookGeneratorPluginType)); + memset(theNewInstance, 0, sizeof(QuickLookGeneratorPluginType)); /* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */ theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct)); - memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl,sizeof(QLGeneratorInterfaceStruct)); + memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl, sizeof(QLGeneratorInterfaceStruct)); /* Retain and keep an open instance refcount for each factory. */ theNewInstance->factoryID = CFRetain(inFactoryID); @@ -110,7 +110,7 @@ void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInsta /* Free the instance structure */ free(thisInstance); - if (theFactoryID){ + if (theFactoryID) { CFPlugInRemoveInstanceForFactory(theFactoryID); CFRelease(theFactoryID); } @@ -121,13 +121,13 @@ void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInsta // ----------------------------------------------------------------------------- // Implementation of the IUnknown QueryInterface function. // -HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv) +HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv) { CFUUIDRef interfaceID; - interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid); + interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, iid); - if (CFEqual(interfaceID,kQLGeneratorCallbacksInterfaceID)){ + if (CFEqual(interfaceID, kQLGeneratorCallbacksInterfaceID)) { /* If the Right interface was requested, bump the ref count, * set the ppv parameter equal to the instance, and * return good status. @@ -138,7 +138,8 @@ HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *p *ppv = thisInstance; CFRelease(interfaceID); return S_OK; - }else{ + } + else { /* Requested interface unknown, bail with error. */ *ppv = NULL; CFRelease(interfaceID); @@ -168,10 +169,11 @@ ULONG QuickLookGeneratorPluginAddRef(void *thisInstance) ULONG QuickLookGeneratorPluginRelease(void *thisInstance) { ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1; - if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0){ + if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0) { DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance ); return 0; - }else{ + } + else { return ((QuickLookGeneratorPluginType*) thisInstance )->refCount; } } @@ -179,7 +181,7 @@ ULONG QuickLookGeneratorPluginRelease(void *thisInstance) // ----------------------------------------------------------------------------- // QuickLookGeneratorPluginFactory // ----------------------------------------------------------------------------- -void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) +void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID) { QuickLookGeneratorPluginType *result; CFUUIDRef uuid; @@ -187,8 +189,8 @@ void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) /* If correct type is being requested, allocate an * instance of kQLGeneratorTypeID and return the IUnknown interface. */ - if (CFEqual(typeID,kQLGeneratorTypeID)){ - uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); + if (CFEqual(typeID, kQLGeneratorTypeID)) { + uuid = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR(PLUGIN_ID)); result = AllocQuickLookGeneratorPluginType(uuid); CFRelease(uuid); return result; diff --git a/SDL/gui.c b/SDL/gui.c index 201452a..5650d9b 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -338,7 +338,7 @@ static void cycle_model_backwards(unsigned index) const char *current_model_string(unsigned index) { - return (const char *[]){"Game Boy", "Game Boy Color", "Game Boy Advance" , "Super Game Boy"} + return (const char *[]){"Game Boy", "Game Boy Color", "Game Boy Advance", "Super Game Boy"} [configuration.model]; } @@ -800,7 +800,7 @@ static void cycle_joypads(unsigned index) SDL_JoystickClose(joystick); joystick = NULL; } - if ((controller = SDL_GameControllerOpen(joypad_index))){ + if ((controller = SDL_GameControllerOpen(joypad_index))) { joystick = SDL_GameControllerGetJoystick(controller); } else { @@ -822,7 +822,7 @@ static void cycle_joypads_backwards(unsigned index) SDL_JoystickClose(joystick); joystick = NULL; } - if ((controller = SDL_GameControllerOpen(joypad_index))){ + if ((controller = SDL_GameControllerOpen(joypad_index))) { joystick = SDL_GameControllerGetJoystick(controller); } else { @@ -886,7 +886,7 @@ void connect_joypad(void) } } else if (!joystick && SDL_NumJoysticks()) { - if ((controller = SDL_GameControllerOpen(0))){ + if ((controller = SDL_GameControllerOpen(0))) { joystick = SDL_GameControllerGetJoystick(controller); } else { diff --git a/SDL/main.c b/SDL/main.c index 4b6afea..4ce2e59 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -149,8 +149,7 @@ static void open_menu(void) static void handle_events(GB_gameboy_t *gb) { SDL_Event event; - while (SDL_PollEvent(&event)) - { + while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: pending_command = GB_SDL_QUIT_COMMAND; @@ -603,7 +602,7 @@ static bool get_arg_flag(const char *flag, int *argc, char **argv) int main(int argc, char **argv) { #ifdef _WIN32 - SetProcessDPIAware(); + SetProcessDPIAware(); #endif #define str(x) #x #define xstr(x) str(x) diff --git a/SDL/opengl_compat.h b/SDL/opengl_compat.h index 15b2a17..4b79b0c 100644 --- a/SDL/opengl_compat.h +++ b/SDL/opengl_compat.h @@ -10,7 +10,7 @@ #define GL_COMPAT_WRAPPER(func) \ ({ extern typeof(func) *GL_COMPAT_NAME(func); \ -if(!GL_COMPAT_NAME(func)) GL_COMPAT_NAME(func) = SDL_GL_GetProcAddress(#func); \ +if (!GL_COMPAT_NAME(func)) GL_COMPAT_NAME(func) = SDL_GL_GetProcAddress(#func); \ GL_COMPAT_NAME(func); \ }) diff --git a/Tester/main.c b/Tester/main.c index e3b662c..27250a6 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -300,7 +300,7 @@ int main(int argc, char **argv) if (max_forks > 1) { while (current_forks >= max_forks) { int wait_out; - while(wait(&wait_out) == -1); + while (wait(&wait_out) == -1); current_forks--; } @@ -433,7 +433,7 @@ int main(int argc, char **argv) } #ifndef _WIN32 int wait_out; - while(wait(&wait_out) != -1); + while (wait(&wait_out) != -1); #endif return 0; } diff --git a/Windows/stdio.h b/Windows/stdio.h index 0595b01..ef21ea4 100755 --- a/Windows/stdio.h +++ b/Windows/stdio.h @@ -24,7 +24,8 @@ static inline int vasprintf(char **str, const char *fmt, va_list args) #endif /* This code is public domain -- Will Hartung 4/9/09 */ -static inline size_t getline(char **lineptr, size_t *n, FILE *stream) { +static inline size_t getline(char **lineptr, size_t *n, FILE *stream) +{ char *bufptr = NULL; char *p = bufptr; size_t size; diff --git a/libretro/libretro.c b/libretro/libretro.c index 8cd1324..2cb3ef7 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -195,7 +195,7 @@ static bool serial_end2(GB_gameboy_t *gb) static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b) { - return r<<16|g<<8|b; + return r <<16 | g <<8 | b; } static retro_environment_t environ_cb; @@ -323,15 +323,13 @@ static struct retro_input_descriptor descriptors_4p[] = { static void set_link_cable_state(bool state) { - if (state && emulated_devices == 2) - { + if (state && emulated_devices == 2) { GB_set_serial_transfer_bit_start_callback(&gameboy[0], serial_start1); GB_set_serial_transfer_bit_end_callback(&gameboy[0], serial_end1); GB_set_serial_transfer_bit_start_callback(&gameboy[1], serial_start2); GB_set_serial_transfer_bit_end_callback(&gameboy[1], serial_end2); } - else if (!state) - { + else if (!state) { GB_set_serial_transfer_bit_start_callback(&gameboy[0], NULL); GB_set_serial_transfer_bit_end_callback(&gameboy[0], NULL); GB_set_serial_transfer_bit_start_callback(&gameboy[1], NULL); @@ -375,8 +373,7 @@ static void init_for_current_model(unsigned id) /* todo: attempt to make these more generic */ GB_set_vblank_callback(&gameboy[0], (GB_vblank_callback_t) vblank1); - if (emulated_devices == 2) - { + if (emulated_devices == 2) { GB_set_vblank_callback(&gameboy[1], (GB_vblank_callback_t) vblank2); if (link_cable_emulation) set_link_cable_state(true); @@ -428,17 +425,17 @@ static void init_for_current_model(unsigned id) descs[8].ptr = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_OAM, &size, &bank); descs[8].start = 0xFE00; descs[8].len = 0x00A0; - descs[8].select= 0xFFFFFF00; + descs[8].select = 0xFFFFFF00; descs[9].ptr = descs[2].ptr + 0x2000; /* GBC RAM bank 2 */ descs[9].start = 0x10000; descs[9].len = GB_is_cgb(&gameboy[i]) ? 0x6000 : 0; /* 0x1000 per bank (2-7), unmapped on GB */ - descs[9].select= 0xFFFF0000; + descs[9].select = 0xFFFF0000; descs[10].ptr = GB_get_direct_access(&gameboy[i], GB_DIRECT_ACCESS_IO, &size, &bank); descs[10].start = 0xFF00; descs[10].len = 0x0080; - descs[10].select= 0xFFFFFF00; + descs[10].select = 0xFFFFFF00; struct retro_memory_map mmaps; mmaps.descriptors = descs; @@ -446,8 +443,7 @@ static void init_for_current_model(unsigned id) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps); /* Let's be extremely nitpicky about how devices and descriptors are set */ - if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) - { + if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) { static const struct retro_controller_info ports[] = { { controllers_sgb, 1 }, { controllers_sgb, 1 }, @@ -458,8 +454,7 @@ static void init_for_current_model(unsigned id) environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_4p); } - else if (emulated_devices == 1) - { + else if (emulated_devices == 1) { static const struct retro_controller_info ports[] = { { controllers, 1 }, { NULL, 0 }, @@ -467,8 +462,7 @@ static void init_for_current_model(unsigned id) environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, descriptors_1p); } - else - { + else { static const struct retro_controller_info ports[] = { { controllers, 1 }, { controllers, 1 }, @@ -483,12 +477,10 @@ static void init_for_current_model(unsigned id) static void check_variables() { struct retro_variable var = {0}; - if (emulated_devices == 1) - { + if (emulated_devices == 1) { var.key = "sameboy_color_correction_mode"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED); else if (strcmp(var.value, "correct curves") == 0) @@ -503,8 +495,7 @@ static void check_variables() var.key = "sameboy_high_pass_filter_mode"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF); else if (strcmp(var.value, "accurate") == 0) @@ -515,8 +506,7 @@ static void check_variables() var.key = "sameboy_model"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { enum model new_model = model[0]; if (strcmp(var.value, "Game Boy") == 0) new_model = MODEL_DMG; @@ -531,8 +521,7 @@ static void check_variables() else new_model = MODEL_AUTO; - if (new_model != model[0]) - { + if (new_model != model[0]) { geometry_updated = true; model[0] = new_model; init_for_current_model(0); @@ -541,20 +530,17 @@ static void check_variables() var.key = "sameboy_border"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "enabled") == 0) sgb_border = 1; else if (strcmp(var.value, "disabled") == 0) sgb_border = 0; } } - else - { + else { var.key = "sameboy_color_correction_mode_1"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_color_correction_mode(&gameboy[0], GB_COLOR_CORRECTION_DISABLED); else if (strcmp(var.value, "correct curves") == 0) @@ -569,8 +555,7 @@ static void check_variables() var.key = "sameboy_color_correction_mode_2"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_color_correction_mode(&gameboy[1], GB_COLOR_CORRECTION_DISABLED); else if (strcmp(var.value, "correct curves") == 0) @@ -586,8 +571,7 @@ static void check_variables() var.key = "sameboy_high_pass_filter_mode_1"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_highpass_filter_mode(&gameboy[0], GB_HIGHPASS_OFF); else if (strcmp(var.value, "accurate") == 0) @@ -598,8 +582,7 @@ static void check_variables() var.key = "sameboy_high_pass_filter_mode_2"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "off") == 0) GB_set_highpass_filter_mode(&gameboy[1], GB_HIGHPASS_OFF); else if (strcmp(var.value, "accurate") == 0) @@ -610,8 +593,7 @@ static void check_variables() var.key = "sameboy_model_1"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { enum model new_model = model[0]; if (strcmp(var.value, "Game Boy") == 0) new_model = MODEL_DMG; @@ -626,8 +608,7 @@ static void check_variables() else new_model = MODEL_AUTO; - if (model[0] != new_model) - { + if (model[0] != new_model) { model[0] = new_model; init_for_current_model(0); } @@ -635,8 +616,7 @@ static void check_variables() var.key = "sameboy_model_2"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { enum model new_model = model[1]; if (strcmp(var.value, "Game Boy") == 0) new_model = MODEL_DMG; @@ -651,8 +631,7 @@ static void check_variables() else new_model = MODEL_AUTO; - if (model[1] != new_model) - { + if (model[1] != new_model) { model[1] = new_model; init_for_current_model(1); } @@ -660,8 +639,7 @@ static void check_variables() var.key = "sameboy_screen_layout"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "top-down") == 0) screen_layout = LAYOUT_TOP_DOWN; else @@ -672,8 +650,7 @@ static void check_variables() var.key = "sameboy_link"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { bool tmp = link_cable_emulation; if (strcmp(var.value, "enabled") == 0) link_cable_emulation = true; @@ -687,8 +664,7 @@ static void check_variables() var.key = "sameboy_audio_output"; var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - { + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "Game Boy #1") == 0) audio_out = GB_1; else @@ -753,28 +729,25 @@ void retro_get_system_av_info(struct retro_system_av_info *info) struct retro_game_geometry geom; struct retro_system_timing timing = { GB_get_usual_frame_rate(&gameboy[0]), AUDIO_FREQUENCY }; - if (emulated_devices == 2) - { + if (emulated_devices == 2) { if (screen_layout == LAYOUT_TOP_DOWN) { geom.base_width = VIDEO_WIDTH; geom.base_height = VIDEO_HEIGHT * emulated_devices; geom.aspect_ratio = (double)VIDEO_WIDTH / (emulated_devices * VIDEO_HEIGHT); - }else if (screen_layout == LAYOUT_LEFT_RIGHT) { + } + else if (screen_layout == LAYOUT_LEFT_RIGHT) { geom.base_width = VIDEO_WIDTH * emulated_devices; geom.base_height = VIDEO_HEIGHT; geom.aspect_ratio = ((double)VIDEO_WIDTH * emulated_devices) / VIDEO_HEIGHT; } } - else - { - if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) - { + else { + if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) { geom.base_width = SGB_VIDEO_WIDTH; geom.base_height = SGB_VIDEO_HEIGHT; geom.aspect_ratio = (double)SGB_VIDEO_WIDTH / SGB_VIDEO_HEIGHT; } - else - { + else { geom.base_width = VIDEO_WIDTH; geom.base_height = VIDEO_HEIGHT; geom.aspect_ratio = (double)VIDEO_WIDTH / VIDEO_HEIGHT; @@ -848,13 +821,11 @@ void retro_run(void) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) check_variables(); - if (emulated_devices == 2) - { + if (emulated_devices == 2) { GB_update_keys_status(&gameboy[0], 0); GB_update_keys_status(&gameboy[1], 1); } - else if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) - { + else if (emulated_devices == 1 && (model[0] == MODEL_SGB || model[0] == MODEL_SGB2)) { for (unsigned i = 0; i < 4; i++) GB_update_keys_status(&gameboy[0], i); } @@ -863,8 +834,7 @@ void retro_run(void) vblank1_occurred = vblank2_occurred = false; signed delta = 0; - if (emulated_devices == 2) - { + if (emulated_devices == 2) { while (!vblank1_occurred || !vblank2_occurred) { if (delta >= 0) { delta -= GB_run(&gameboy[0]); @@ -874,16 +844,15 @@ void retro_run(void) } } } - else - { + else { GB_run_frame(&gameboy[0]); } - if (emulated_devices == 2) - { + if (emulated_devices == 2) { if (screen_layout == LAYOUT_TOP_DOWN) { video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT * emulated_devices, VIDEO_WIDTH * sizeof(uint32_t)); - }else if (screen_layout == LAYOUT_LEFT_RIGHT) { + } + else if (screen_layout == LAYOUT_LEFT_RIGHT) { /* use slow memcpy method for now */ for (int index = 0; index < emulated_devices; index++) { for (int y = 0; y < VIDEO_HEIGHT; y++) { @@ -896,8 +865,7 @@ void retro_run(void) video_cb(frame_buf_copy, VIDEO_WIDTH * emulated_devices, VIDEO_HEIGHT, VIDEO_WIDTH * emulated_devices * sizeof(uint32_t)); } } - else - { + else { if (model[0] == MODEL_SGB || model[0] == MODEL_SGB2) { if (sgb_border == 1) video_cb(frame_buf, SGB_VIDEO_WIDTH, SGB_VIDEO_HEIGHT, SGB_VIDEO_WIDTH * sizeof(uint32_t)); @@ -920,12 +888,11 @@ bool retro_load_game(const struct retro_game_info *info) environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars_single); check_variables(); - frame_buf = (uint32_t*)malloc(SGB_VIDEO_PIXELS* emulated_devices * sizeof(uint32_t)); + frame_buf = (uint32_t*)malloc(SGB_VIDEO_PIXELS *emulated_devices * sizeof(uint32_t)); memset(frame_buf, 0, SGB_VIDEO_PIXELS * emulated_devices * sizeof(uint32_t)); enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - { + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported\n"); return false; } @@ -933,11 +900,9 @@ bool retro_load_game(const struct retro_game_info *info) auto_model = (info->path[strlen(info->path) - 1] & ~0x20) == 'C' ? MODEL_CGB : MODEL_DMG; snprintf(retro_game_path, sizeof(retro_game_path), "%s", info->path); - for (int i = 0; i < emulated_devices; i++) - { + for (int i = 0; i < emulated_devices; i++) { init_for_current_model(i); - if (GB_load_rom(&gameboy[i],info->path)) - { + if (GB_load_rom(&gameboy[i], info->path)) { log_cb(RETRO_LOG_INFO, "Failed to load ROM at %s\n", info->path); return false; } @@ -984,8 +949,7 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info *info, memset(frame_buf_copy, 0, emulated_devices * SGB_VIDEO_PIXELS * sizeof(uint32_t)); enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - { + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported\n"); return false; } @@ -993,11 +957,9 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info *info, auto_model = (info->path[strlen(info->path) - 1] & ~0x20) == 'C' ? MODEL_CGB : MODEL_DMG; snprintf(retro_game_path, sizeof(retro_game_path), "%s", info->path); - for (int i = 0; i < emulated_devices; i++) - { + for (int i = 0; i < emulated_devices; i++) { init_for_current_model(i); - if (GB_load_rom(&gameboy[i], info[i].path)) - { + if (GB_load_rom(&gameboy[i], info[i].path)) { log_cb(RETRO_LOG_INFO, "Failed to load ROM\n"); return false; } @@ -1063,8 +1025,7 @@ bool retro_serialize(void *data, size_t size) bool retro_unserialize(const void *data, size_t size) { - for (int i = 0; i < emulated_devices; i++) - { + for (int i = 0; i < emulated_devices; i++) { size_t state_size = GB_get_save_state_size(&gameboy[i]); if (state_size > size) { return false; @@ -1085,10 +1046,8 @@ bool retro_unserialize(const void *data, size_t size) void *retro_get_memory_data(unsigned type) { void *data = NULL; - if (emulated_devices == 1) - { - switch(type) - { + if (emulated_devices == 1) { + switch (type) { case RETRO_MEMORY_SYSTEM_RAM: data = gameboy[0].ram; break; @@ -1102,7 +1061,7 @@ void *retro_get_memory_data(unsigned type) data = gameboy[0].vram; break; case RETRO_MEMORY_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) data = GB_GET_SECTION(&gameboy[0], rtc); else data = NULL; @@ -1111,10 +1070,8 @@ void *retro_get_memory_data(unsigned type) break; } } - else - { - switch (type) - { + else { + switch (type) { case RETRO_MEMORY_GAMEBOY_1_SRAM: if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0) data = gameboy[0].mbc_ram; @@ -1128,13 +1085,13 @@ void *retro_get_memory_data(unsigned type) data = NULL; break; case RETRO_MEMORY_GAMEBOY_1_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) data = GB_GET_SECTION(&gameboy[0], rtc); else data = NULL; break; case RETRO_MEMORY_GAMEBOY_2_RTC: - if(gameboy[1].cartridge_type->has_battery) + if (gameboy[1].cartridge_type->has_battery) data = GB_GET_SECTION(&gameboy[1], rtc); else data = NULL; @@ -1150,10 +1107,8 @@ void *retro_get_memory_data(unsigned type) size_t retro_get_memory_size(unsigned type) { size_t size = 0; - if (emulated_devices == 1) - { - switch(type) - { + if (emulated_devices == 1) { + switch (type) { case RETRO_MEMORY_SYSTEM_RAM: size = gameboy[0].ram_size; break; @@ -1167,7 +1122,7 @@ size_t retro_get_memory_size(unsigned type) size = gameboy[0].vram_size; break; case RETRO_MEMORY_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) size = GB_SECTION_SIZE(rtc); else size = 0; @@ -1176,10 +1131,8 @@ size_t retro_get_memory_size(unsigned type) break; } } - else - { - switch (type) - { + else { + switch (type) { case RETRO_MEMORY_GAMEBOY_1_SRAM: if (gameboy[0].cartridge_type->has_battery && gameboy[0].mbc_ram_size != 0) size = gameboy[0].mbc_ram_size; @@ -1193,11 +1146,11 @@ size_t retro_get_memory_size(unsigned type) size = 0; break; case RETRO_MEMORY_GAMEBOY_1_RTC: - if(gameboy[0].cartridge_type->has_battery) + if (gameboy[0].cartridge_type->has_battery) size = GB_SECTION_SIZE(rtc); break; case RETRO_MEMORY_GAMEBOY_2_RTC: - if(gameboy[1].cartridge_type->has_battery) + if (gameboy[1].cartridge_type->has_battery) size = GB_SECTION_SIZE(rtc); break; default: From 634dcefd01f67577830755c5344cc118ee6708b9 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Apr 2020 20:44:25 +0300 Subject: [PATCH 091/125] Typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ba568ff..5a2df1d 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ ifeq ($(PLATFORM),Darwin) OPEN_DIALOG = OpenDialog/cocoa.m endif -# These myst come before the -Wno- flags +# These must come before the -Wno- flags CFLAGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option CFLAGS += -Wpartial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context From 198942b2734eaa8463fadab376fa19b55e025be3 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Apr 2020 21:00:30 +0300 Subject: [PATCH 092/125] Truly fix #249, fix #251 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5a2df1d..8792f78 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ endif # These must come before the -Wno- flags CFLAGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option -CFLAGS += -Wpartial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context +CFLAGS += -Werror=partial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context CFLAGS += -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES From 8ac029d3feab5923fed75e8897f30065f6ad7806 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Apr 2020 21:06:44 +0300 Subject: [PATCH 093/125] Truly truly fix #249, fix #251 --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8792f78..e30b3f6 100644 --- a/Makefile +++ b/Makefile @@ -87,11 +87,11 @@ ifeq ($(PLATFORM),Darwin) OPEN_DIALOG = OpenDialog/cocoa.m endif +# This must come first because GCC is special +CFLAGS += -Werror=partial-availability # These must come before the -Wno- flags CFLAGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option - -CFLAGS += -Werror=partial-availability -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context - +CFLAGS += -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context CFLAGS += -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES ifeq (,$(PKG_CONFIG)) From ddad913e06fb51e80957177d404fef3d1d3b5d6c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 24 Apr 2020 21:59:51 +0300 Subject: [PATCH 094/125] OK this time it will work. --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e30b3f6..33b8990 100644 --- a/Makefile +++ b/Makefile @@ -87,11 +87,15 @@ ifeq ($(PLATFORM),Darwin) OPEN_DIALOG = OpenDialog/cocoa.m endif -# This must come first because GCC is special -CFLAGS += -Werror=partial-availability # These must come before the -Wno- flags CFLAGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option CFLAGS += -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context + +# Only add this flag if the compiler supports it +ifeq ($(shell $(CC) -x c -c $(NULL) -o $(NULL) -Werror -Wpartial-availability 2> $(NULL); echo $$?),0) +CFLAGS += -Wpartial-availability +endif + CFLAGS += -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES ifeq (,$(PKG_CONFIG)) From 2df6d266bd6fc993f540f230c4c0ffa7b04ee364 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 13:50:35 +0300 Subject: [PATCH 095/125] Add a GitHub action to avoid breaking builds --- .github/actions/install_deps.sh | 23 +++++++++++++++++++++++ .github/workflows/buildability.yml | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/actions/install_deps.sh create mode 100644 .github/workflows/buildability.yml diff --git a/.github/actions/install_deps.sh b/.github/actions/install_deps.sh new file mode 100644 index 0000000..1c9749e --- /dev/null +++ b/.github/actions/install_deps.sh @@ -0,0 +1,23 @@ +case `echo $1 | cut -d '-' -f 1` in + ubuntu) + sudo apt-get -qq update + sudo apt-get install -yq bison libpng-dev pkg-config libsdl2-dev + ( + cd `mktemp -d` + curl -L https://github.com/rednex/rgbds/archive/v0.4.0.zip > rgbds.zip + unzip rgbds.zip + cd rgbds-* + make -sj + sudo make install + cd .. + rm -rf * + ) + ;; + macos) + brew install rgbds sdl2 + ;; + *) + echo "Unsupported OS" + exit 1 + ;; +esac \ No newline at end of file diff --git a/.github/workflows/buildability.yml b/.github/workflows/buildability.yml new file mode 100644 index 0000000..e5f4a30 --- /dev/null +++ b/.github/workflows/buildability.yml @@ -0,0 +1,28 @@ +name: "Bulidability" +on: push + +jobs: + buildability: + strategy: + matrix: + os: [ubuntu-latest, ubuntu-16.04, macos-latest] + cc: [gcc, clang] + include: + - os: macos-latest + cc: clang + extra_target: cocoa + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Install deps + shell: bash + run: | + ./.github/actions/install_deps.sh ${{ matrix.os }} + - name: Build + run: | + make sdl ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} + - name: Upload binaries + uses: actions/upload-artifact@v1 + with: + name: sameboy-canary-${{ matrix.os }}-${{ matrix.cc }} + path: build/bin \ No newline at end of file From 385cd1b8c722a89c43fdf332aa48d64a412d1e6e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 13:52:18 +0300 Subject: [PATCH 096/125] Fix chmod --- .github/actions/install_deps.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .github/actions/install_deps.sh diff --git a/.github/actions/install_deps.sh b/.github/actions/install_deps.sh old mode 100644 new mode 100755 From 17c97c3c2b140554a50844eeb8b3e5d268608832 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 13:59:31 +0300 Subject: [PATCH 097/125] Use brew's SDL2 on macOS --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 33b8990..d8a1a3c 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,6 @@ SYSROOT := $(shell xcodebuild -sdk macosx -version Path 2> $(NULL)) CFLAGS += -F/Library/Frameworks -mmacosx-version-min=10.9 OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT) LDFLAGS += -framework AppKit -framework PreferencePanes -framework Carbon -framework QuartzCore -weak_framework Metal -weak_framework MetalKit -mmacosx-version-min=10.9 -SDL_LDFLAGS := -F/Library/Frameworks -framework SDL2 GL_LDFLAGS := -framework OpenGL endif CFLAGS += -Wno-deprecated-declarations From 7e908fef0ee5c3cb1c410a178744d74caa55d458 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 14:04:51 +0300 Subject: [PATCH 098/125] The macOS environment doesn't come with GCC, it'll just test Clang again --- .github/workflows/buildability.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/buildability.yml b/.github/workflows/buildability.yml index e5f4a30..78df953 100644 --- a/.github/workflows/buildability.yml +++ b/.github/workflows/buildability.yml @@ -11,6 +11,9 @@ jobs: - os: macos-latest cc: clang extra_target: cocoa + exclude: + - os: macos-latest + cc: gcc runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From 097705456c95e107a906fbbc0ffc5f61dacf5a38 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 14:05:35 +0300 Subject: [PATCH 099/125] Show compiler version --- .github/workflows/buildability.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildability.yml b/.github/workflows/buildability.yml index 78df953..639a250 100644 --- a/.github/workflows/buildability.yml +++ b/.github/workflows/buildability.yml @@ -23,7 +23,7 @@ jobs: ./.github/actions/install_deps.sh ${{ matrix.os }} - name: Build run: | - make sdl ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} + ${{ matrix.cc }} -v; make sdl ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} - name: Upload binaries uses: actions/upload-artifact@v1 with: From c2a395006ea2421ee574ba1d63ec21f48411a35e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 14:45:52 +0300 Subject: [PATCH 100/125] Update docs --- README.md | 2 +- build-faq.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 91e0bf6..d626bbe 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ SameBoy requires the following tools and libraries to build: * clang * make * Cocoa port: OS X SDK and Xcode command line tools - * SDL port: SDL2.framework (OS X) or libsdl2 (Other platforms) + * SDL port: libsdl2 * [rgbds](https://github.com/bentley/rgbds/releases/), for boot ROM compilation On Windows, SameBoy also requires: diff --git a/build-faq.md b/build-faq.md index e2192f5..2b056dd 100644 --- a/build-faq.md +++ b/build-faq.md @@ -4,4 +4,4 @@ When building on macOS, the build system will make a native Cocoa app by default # Attempting to build the SDL frontend on macOS fails on linking -SameBoy on macOS expects you to have the SDL2 framework installed as a framework. You can find the SDL2 binaries on the [SDL homepage](https://www.libsdl.org/download-2.0.php). Mount the DMG and copy SDL2.framework to `/Library/Frameworks/`. +SameBoy on macOS expects you to have SDL2 installed via Brew, and not as a framework. Older versions expected it to be installed as a framework, but this is no longer the case. \ No newline at end of file From 1e7737a23943a2076ee4ab50268055696a28ba86 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 14:46:01 +0300 Subject: [PATCH 101/125] Limit unroll to GCC 8 --- Core/gb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/gb.h b/Core/gb.h index 01b79e8..703a489 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -35,7 +35,7 @@ #ifdef GB_INTERNAL #if __clang__ #define UNROLL _Pragma("unroll") -#elif __GNUC__ +#elif __GNUC__ >= 8 #define UNROLL _Pragma("GCC unroll 8") #else #define UNROLL From c62704e26b3d34144cf86f2f0eddd7d3404b5655 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 14:51:17 +0300 Subject: [PATCH 102/125] Minor fix for GCC's LTO --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index d8a1a3c..1ec1fd9 100644 --- a/Makefile +++ b/Makefile @@ -145,6 +145,7 @@ endif ifneq ($(PLATFORM),windows32) LDFLAGS += -flto CFLAGS += -flto +LDFLAGS += -DGB_INTERNAL # For GCC's LTO endif else From 66112f493038f87cc6b96bb419cf7891ab96b562 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 14:55:51 +0300 Subject: [PATCH 103/125] That wasn't enough to fix it, I'll just disable this warning --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1ec1fd9..8f8ea81 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,7 @@ endif ifneq ($(PLATFORM),windows32) LDFLAGS += -flto CFLAGS += -flto -LDFLAGS += -DGB_INTERNAL # For GCC's LTO +LDFLAGS += -Wno-lto-type-mismatch # For GCC's LTO endif else From bb5c9f7fc64bb816f213f0e73a9c6e3ba51ae647 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 15:12:10 +0300 Subject: [PATCH 104/125] Fix libretro build --- Core/cheats.h | 4 ++++ Core/debugger.h | 4 ++-- Core/gb.c | 14 ++++++++------ Core/timing.c | 2 +- libretro/Makefile | 4 ++-- libretro/Makefile.common | 2 +- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Core/cheats.h b/Core/cheats.h index 13b7d7b..cf8aa20 100644 --- a/Core/cheats.h +++ b/Core/cheats.h @@ -17,8 +17,12 @@ void GB_load_cheats(GB_gameboy_t *gb, const char *path); int GB_save_cheats(GB_gameboy_t *gb, const char *path); #ifdef GB_INTERNAL +#ifdef GB_DISABLE_CHEATS +#define GB_apply_cheat(...) +#else void GB_apply_cheat(GB_gameboy_t *gb, uint16_t address, uint8_t *value); #endif +#endif typedef struct { size_t size; diff --git a/Core/debugger.h b/Core/debugger.h index 2906ad9..4868df3 100644 --- a/Core/debugger.h +++ b/Core/debugger.h @@ -7,7 +7,7 @@ #ifdef GB_INTERNAL -#ifdef DISABLE_DEBUGGER +#ifdef GB_DISABLE_DEBUGGER #define GB_debugger_run(gb) (void)0 #define GB_debugger_handle_async_commands(gb) (void)0 #define GB_debugger_ret_hook(gb) (void)0 @@ -22,7 +22,7 @@ void GB_debugger_ret_hook(GB_gameboy_t *gb); void GB_debugger_test_write_watchpoint(GB_gameboy_t *gb, uint16_t addr, uint8_t value); void GB_debugger_test_read_watchpoint(GB_gameboy_t *gb, uint16_t addr); const GB_bank_symbol_t *GB_debugger_find_symbol(GB_gameboy_t *gb, uint16_t addr); -#endif /* DISABLE_DEBUGGER */ +#endif /* GB_DISABLE_DEBUGGER */ #endif #ifdef GB_INTERNAL diff --git a/Core/gb.c b/Core/gb.c index f6174b9..2b22f9d 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -13,7 +13,7 @@ #include "gb.h" -#ifdef DISABLE_REWIND +#ifdef GB_DISABLE_REWIND #define GB_rewind_free(...) #define GB_rewind_push(...) #endif @@ -57,7 +57,7 @@ void GB_log(GB_gameboy_t *gb, const char *fmt, ...) va_end(args); } -#ifndef DISABLE_DEBUGGER +#ifndef GB_DISABLE_DEBUGGER static char *default_input_callback(GB_gameboy_t *gb) { char *expression = NULL; @@ -148,7 +148,7 @@ void GB_init(GB_gameboy_t *gb, GB_model_t model) gb->vram = malloc(gb->vram_size = 0x2000); } -#ifndef DISABLE_DEBUGGER +#ifndef GB_DISABLE_DEBUGGER gb->input_callback = default_input_callback; gb->async_input_callback = default_async_input_callback; #endif @@ -193,13 +193,15 @@ void GB_free(GB_gameboy_t *gb) if (gb->nontrivial_jump_state) { free(gb->nontrivial_jump_state); } -#ifndef DISABLE_DEBUGGER +#ifndef GB_DISABLE_DEBUGGER GB_debugger_clear_symbols(gb); #endif GB_rewind_free(gb); +#ifndef GB_DISABLE_CHEATS while (gb->cheats) { GB_remove_cheat(gb, gb->cheats[0]); } +#endif memset(gb, 0, sizeof(*gb)); } @@ -643,7 +645,7 @@ void GB_set_log_callback(GB_gameboy_t *gb, GB_log_callback_t callback) void GB_set_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) { -#ifndef DISABLE_DEBUGGER +#ifndef GB_DISABLE_DEBUGGER if (gb->input_callback == default_input_callback) { gb->async_input_callback = NULL; } @@ -653,7 +655,7 @@ void GB_set_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) { -#ifndef DISABLE_DEBUGGER +#ifndef GB_DISABLE_DEBUGGER gb->async_input_callback = callback; #endif } diff --git a/Core/timing.c b/Core/timing.c index 9eb9c91..8fee590 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -10,7 +10,7 @@ static const unsigned GB_TAC_TRIGGER_BITS[] = {512, 8, 32, 128}; -#ifndef DISABLE_TIMEKEEPING +#ifndef GB_DISABLE_TIMEKEEPING static int64_t get_nanoseconds(void) { #ifndef _WIN32 diff --git a/libretro/Makefile b/libretro/Makefile index 75ddfc6..7e19893 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -260,7 +260,7 @@ endif include Makefile.common -OBJECTS := $(patsubst %.c,$(CORE_DIR)/build/obj/%_libretro.c.o,$(SOURCES_C)) +OBJECTS := $(patsubst $(CORE_DIR)/%.c,$(CORE_DIR)/build/obj/%_libretro.c.o,$(SOURCES_C)) OBJOUT = -o LINKOUT = -o @@ -306,7 +306,7 @@ else $(LD) $(fpic) $(SHARED) $(INCFLAGS) $(LINKOUT)$@ $(OBJECTS) $(LDFLAGS) endif -$(CORE_DIR)/build/obj/%_libretro.c.o: %.c +$(CORE_DIR)/build/obj/%_libretro.c.o: $(CORE_DIR)/%.c -@$(MKDIR) -p $(dir $@) $(CC) -c $(OBJOUT)$@ $< $(CFLAGS) $(fpic) -DGB_INTERNAL diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 3bf1783..947b14c 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -20,7 +20,7 @@ SOURCES_C := $(CORE_DIR)/Core/gb.c \ $(CORE_DIR)/libretro/sgb2_boot.c \ $(CORE_DIR)/libretro/libretro.c -CFLAGS += -DDISABLE_TIMEKEEPING -DDISABLE_REWIND -DDISABLE_DEBUGGER +CFLAGS += -DGB_DISABLE_TIMEKEEPING -DGB_DISABLE_REWIND -DGB_DISABLE_DEBUGGER -DGB_DISABLE_CHEATS SOURCES_CXX := From 8e702f14526cdc392c3ac6f720b3880b35d04747 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 15:13:04 +0300 Subject: [PATCH 105/125] Also test libretro's buildability --- .github/workflows/buildability.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildability.yml b/.github/workflows/buildability.yml index 639a250..7cd5298 100644 --- a/.github/workflows/buildability.yml +++ b/.github/workflows/buildability.yml @@ -23,7 +23,7 @@ jobs: ./.github/actions/install_deps.sh ${{ matrix.os }} - name: Build run: | - ${{ matrix.cc }} -v; make sdl ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} + ${{ matrix.cc }} -v; make sdl libretro ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} - name: Upload binaries uses: actions/upload-artifact@v1 with: From bf678113923194303320be9297872737a038fb6d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 16:59:47 +0300 Subject: [PATCH 106/125] Sanity test against a few test ROMs --- .github/actions/LICENSE | 25 +++++++++++++++ .github/actions/cgb-acid2.gbc | Bin 0 -> 32768 bytes .github/actions/cgb_sound.gb | Bin 0 -> 65536 bytes .github/actions/dmg-acid2.gb | Bin 0 -> 32768 bytes .github/actions/dmg_sound-2.gb | Bin 0 -> 65536 bytes .github/actions/oam_bug-2.gb | Bin 0 -> 65536 bytes .github/actions/sanity_tests.sh | 29 ++++++++++++++++++ .../{buildability.yml => sanity.yml} | 8 +++-- 8 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 .github/actions/LICENSE create mode 100644 .github/actions/cgb-acid2.gbc create mode 100644 .github/actions/cgb_sound.gb create mode 100644 .github/actions/dmg-acid2.gb create mode 100755 .github/actions/dmg_sound-2.gb create mode 100755 .github/actions/oam_bug-2.gb create mode 100755 .github/actions/sanity_tests.sh rename .github/workflows/{buildability.yml => sanity.yml} (73%) diff --git a/.github/actions/LICENSE b/.github/actions/LICENSE new file mode 100644 index 0000000..8c295a2 --- /dev/null +++ b/.github/actions/LICENSE @@ -0,0 +1,25 @@ +Blargg's Test ROMs by Shay Green + +Acid2 tests by Matt Currie under MIT: + +MIT License + +Copyright (c) 2020 Matt Currie + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/.github/actions/cgb-acid2.gbc b/.github/actions/cgb-acid2.gbc new file mode 100644 index 0000000000000000000000000000000000000000..5f71bd36060b46eefcf7785f81ce16a5a6c5fc67 GIT binary patch literal 32768 zcmeI4e`s6R702(B6iIIULvq*Rfw3ebr>2mSWRz%~_VVn=jpBvQHdA8u&xD&fT4z$% zrkOUxlcJ2yHpOuhmfGMZ#(%8TEA{qA3nLKHn%NPK?f*u@njw-bW^7%x1yW}b@9x}t z-_w&Nx!$1J#yI!!{OVbFZHNdXJDVr~T>63G<(ivd|^1e%jxEy@u?x4wEya zn$!@d+cPpsYCpMt^6t%>H>NIMKJnto+P_@C`N`C!%fI=WeDF~F?zV%6L;FOvR|`e| z`NF901Q`c+ zJ;?`h3T})F`yZBnA)f|0Ddc<0_vN!7-xl)X@?CiX(c8rR#w0s~f;0%!PTtE=~z)fI(nY{=>wgnRMhR#!@b!FCc;>`E*Q zXBV8k4kZ?aGY03NgYr~3rBO@Pw{LVY3wn1B4 zGqnp^FlcJ4m3f#tl~NS9+tjSLcdx0PPC_OpP0f1Q>}FlASPq-boJV)J+uhxL_N*k; z)-vxdm?TepOM_Sue(mX;@;IB`Pg{{Bd$zdr;`=v})a zk)uZ=k(L&rhll;Vf6{oH0>NeG~uPHbQxBg zpQ;KkcCwxEH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?d00001 diff --git a/.github/actions/oam_bug-2.gb b/.github/actions/oam_bug-2.gb new file mode 100755 index 0000000000000000000000000000000000000000..a3f55af1049fff765424216fed8c6553c2262ecd GIT binary patch literal 65536 zcmeI54|EjOy~k(sX9-IZ5&<0p%7kQ-6^I0=Az(W4CjzA)AO+8>N7+EK7+iNTe@M_I z1_-HbPy6V3wgs(}@{Z5b_s*-Rt(J#RGjn&NYrIwzdFxYro7(U+PdHiaD2cfHe)rDK z{z*2`!+{>``R!pcb7$`F{`tmbmI!6C+%>MYD$5h zE4;`5wrXN+r~oQ}3ZMe004jhApaQ4>Du4>00;m8gfC``jr~oQ}3ZMe004jhApaQ4> zDu4>00;m8ga5)rMkt=k~ylR^C#pEpM^JXG+$wHvWC$|TR_+Jfyo0!XH3$N&kHTe%PyVy=ggk_ZG(!>Ybwq8 zb7s2q1v|`6SLb3yVHA2 zR%y^(6gCSzJ8datyojPu+N(dE0TSfN7XnkEU)Mv6rb27dq@l9KWkMR%BYn1@xmWRV zVJ_&MXPtyhDbi5(;w)QVBqtbsBEB^w_|N3LGO%Xc8=@t8?EiEitUVP72PVp;0YNqe z*5nAmK-lM{`}3jJ$xvV}*8`4ChrUeZdJM`!PqSpIP<*7ZXfC^5{T*;a`uBwg_EiM- z_1w~POGUpR4eaY#aHjOL#dlmU+Ov$ z$x&77tf`h7YU&&6EkZ9lUF)i@-C0}RSmku?k{s^3$m#psbv06TO#>Lz-w5YuRX%m( zgIc+A5bm82n3SC^{~$0~lT&GDp&Vudf->Q=qz?x=`rG~F6YF`QwO@FlrQh_z+xaOk zn0_VX3VxbfXfg}A?O{0R&CVg~^6wZDUT_bYUf4GHfR@X%0(0}?*R{C!?A8Y+0q4#+yn;p6Dl_Y2;oY$b&QaaPAgJnKF>jBv4Mq7~C-EL!< zjjZHb#i!CsFHA2LUN^n*ionOv|LDW#GoIl6iVi5Pg*Fwovg5o#7Z4jy2DC$ zTH!AHG}>Y{Y~V2H)f9TWRq<)fVxP84?A0C+Piqf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YI_y)k=$uAk~1}cCGpaQ4>Du4>00;m8gfC``jr~oQ} z3ZMe004jhApaQ4>Du4>00;m8gfC``jr~oQ}3ZMe004jhApaQ4>Du4>00;m8gfC``j zr~oQ}3ZMe004jhApaQ4>Du4>00;m8gfC``jr~oQ}3ZMe004jhApaQ4>Du4>00;oV# Gf&T}g$kes~ literal 0 HcmV?d00001 diff --git a/.github/actions/sanity_tests.sh b/.github/actions/sanity_tests.sh new file mode 100755 index 0000000..26fb398 --- /dev/null +++ b/.github/actions/sanity_tests.sh @@ -0,0 +1,29 @@ +./build/bin/tester/sameboy_tester --jobs 5 \ + --length 40 .github/actions/cgb_sound.gb \ + --length 10 .github/actions/cgb-acid2.gbc \ + --length 10 .github/actions/dmg-acid2.gb \ +--dmg --length 40 .github/actions/dmg_sound-2.gb \ +--dmg --length 20 .github/actions/oam_bug-2.gb + +mv .github/actions/dmg{,-mode}-acid2.bmp + +./build/bin/tester/sameboy_tester \ +--dmg --length 10 .github/actions/dmg-acid2.gb + +FAILED_TESTS=` +shasum .github/actions/*.bmp | grep -E -v \(\ +44ce0c7d49254df0637849c9155080ac7dc3ef3d\ \ .github/actions/cgb-acid2.bmp\|\ +dbcc438dcea13b5d1b80c5cd06bda2592cc5d9e0\ \ .github/actions/cgb_sound.bmp\|\ +0caadf9634e40247ae9c15ff71992e8f77bbf89e\ \ .github/actions/dmg-acid2.bmp\|\ +c50daed36c57a8170ff362042694786676350997\ \ .github/actions/dmg-mode-acid2.bmp\|\ +c9e944b7e01078bdeba1819bc2fa9372b111f52d\ \ .github/actions/dmg_sound-2.bmp\|\ +f0172cc91867d3343fbd113a2bb98100074be0de\ \ .github/actions/oam_bug-2.bmp\ +\)` + +if [ -n "$FAILED_TESTS" ] ; then + echo "Failed the following tests:" + echo $FAILED_TESTS | tr " " "\n" | grep -o -E "[^/]+\.bmp" | sed s/.bmp// | sort + exit 1 +fi + +echo Passed all tests \ No newline at end of file diff --git a/.github/workflows/buildability.yml b/.github/workflows/sanity.yml similarity index 73% rename from .github/workflows/buildability.yml rename to .github/workflows/sanity.yml index 7cd5298..e0ac132 100644 --- a/.github/workflows/buildability.yml +++ b/.github/workflows/sanity.yml @@ -1,4 +1,4 @@ -name: "Bulidability" +name: "Bulidability and Sanity" on: push jobs: @@ -23,7 +23,11 @@ jobs: ./.github/actions/install_deps.sh ${{ matrix.os }} - name: Build run: | - ${{ matrix.cc }} -v; make sdl libretro ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} + ${{ matrix.cc }} -v; make sdl tester libretro ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} + - name: Sanity tests + shell: bash + run: | + ./.github/actions/sanity_tests.sh - name: Upload binaries uses: actions/upload-artifact@v1 with: From e819b91a97834e8af12a7ce378cb9db1e0d441e6 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 17:03:45 +0300 Subject: [PATCH 107/125] Rename job, temporarily disable -j --- .github/workflows/sanity.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index e0ac132..41404a0 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -2,7 +2,7 @@ name: "Bulidability and Sanity" on: push jobs: - buildability: + sanity: strategy: matrix: os: [ubuntu-latest, ubuntu-16.04, macos-latest] @@ -23,7 +23,7 @@ jobs: ./.github/actions/install_deps.sh ${{ matrix.os }} - name: Build run: | - ${{ matrix.cc }} -v; make sdl tester libretro ${{ matrix.extra_target }} -j CONF=release CC=${{ matrix.cc }} + ${{ matrix.cc }} -v; make sdl tester libretro ${{ matrix.extra_target }} CONF=release CC=${{ matrix.cc }} - name: Sanity tests shell: bash run: | From a35164dc0a0ccb4b9dad372fa704abac430ab03b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 17:06:24 +0300 Subject: [PATCH 108/125] Fixed unused variable on Linux --- Tester/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tester/main.c b/Tester/main.c index 27250a6..f399f3f 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -178,8 +178,7 @@ static const char *executable_folder(void) _NSGetExecutablePath(&path[0], &length); #else #ifdef __linux__ - ssize_t length = readlink("/proc/self/exe", &path[0], sizeof(path) - 1); - assert (length != -1); + assert (readlink("/proc/self/exe", &path[0], sizeof(path) - 1) != -1); #else #ifdef _WIN32 HMODULE hModule = GetModuleHandle(NULL); From 7760e11544627da2970b0bfe84e6304a5bd89736 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 17:12:53 +0300 Subject: [PATCH 109/125] Better error handling --- .github/actions/sanity_tests.sh | 2 ++ Tester/main.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/actions/sanity_tests.sh b/.github/actions/sanity_tests.sh index 26fb398..8d37b68 100755 --- a/.github/actions/sanity_tests.sh +++ b/.github/actions/sanity_tests.sh @@ -1,3 +1,5 @@ +set -e + ./build/bin/tester/sameboy_tester --jobs 5 \ --length 40 .github/actions/cgb_sound.gb \ --length 10 .github/actions/cgb-acid2.gbc \ diff --git a/Tester/main.c b/Tester/main.c index f399f3f..e2e1aa8 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -322,15 +322,15 @@ int main(int argc, char **argv) if (dmg) { GB_init(&gb, GB_MODEL_DMG_B); - if (GB_load_boot_rom(&gb, boot_rom_path? boot_rom_path : executable_relative_path("dmg_boot.bin"))) { - perror("Failed to load boot ROM"); + if (GB_load_boot_rom(&gb, boot_rom_path ?: executable_relative_path("dmg_boot.bin"))) { + fprintf(stderr, "Failed to load boot ROM from '%s'\n", boot_rom_path ?: executable_relative_path("dmg_boot.bin")); exit(1); } } else { GB_init(&gb, GB_MODEL_CGB_E); - if (GB_load_boot_rom(&gb, boot_rom_path? boot_rom_path : executable_relative_path("cgb_boot.bin"))) { - perror("Failed to load boot ROM"); + if (GB_load_boot_rom(&gb, boot_rom_path ?: executable_relative_path("cgb_boot.bin"))) { + fprintf(stderr, "Failed to load boot ROM from '%s'\n", boot_rom_path ?: executable_relative_path("cgb_boot.bin")); exit(1); } } From aa9ccc724fb9de220b87a96888bb3db02438aec9 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 17:20:06 +0300 Subject: [PATCH 110/125] Fixing a duh --- Tester/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tester/main.c b/Tester/main.c index e2e1aa8..6c175c6 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -174,11 +174,12 @@ static const char *executable_folder(void) } /* Ugly unportable code! :( */ #ifdef __APPLE__ - unsigned int length = sizeof(path) - 1; + size_t length = sizeof(path) - 1; _NSGetExecutablePath(&path[0], &length); #else #ifdef __linux__ - assert (readlink("/proc/self/exe", &path[0], sizeof(path) - 1) != -1); + size_t __attribute__((unused)) length = readlink("/proc/self/exe", &path[0], sizeof(path) - 1); + assert(length != -1); #else #ifdef _WIN32 HMODULE hModule = GetModuleHandle(NULL); From 09e706865835b85bd34b2462225214e1308aa532 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 17:22:43 +0300 Subject: [PATCH 111/125] Fixing another duh --- Tester/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tester/main.c b/Tester/main.c index 6c175c6..16dbf7b 100755 --- a/Tester/main.c +++ b/Tester/main.c @@ -174,7 +174,7 @@ static const char *executable_folder(void) } /* Ugly unportable code! :( */ #ifdef __APPLE__ - size_t length = sizeof(path) - 1; + uint32_t length = sizeof(path) - 1; _NSGetExecutablePath(&path[0], &length); #else #ifdef __linux__ From 65fb6afd60bc2fe5f7b2190ab2bcd8975f2f322a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 17:57:19 +0300 Subject: [PATCH 112/125] Make fixes --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8f8ea81..49e24b5 100644 --- a/Makefile +++ b/Makefile @@ -342,7 +342,11 @@ $(BIN)/tester/sameboy_tester.exe: $(CORE_OBJECTS) $(SDL_OBJECTS) -@$(MKDIR) -p $(dir $@) $(CC) $^ -o $@ $(LDFLAGS) -Wl,/subsystem:console -$(BIN)/SDL/%.bin $(BIN)/tester/%.bin: $(BOOTROMS_DIR)/%.bin +$(BIN)/SDL/%.bin: $(BOOTROMS_DIR)/%.bin + -@$(MKDIR) -p $(dir $@) + cp -f $^ $@ + +$(BIN)/tester/%.bin: $(BOOTROMS_DIR)/%.bin -@$(MKDIR) -p $(dir $@) cp -f $^ $@ @@ -397,4 +401,4 @@ libretro: clean: rm -rf build -.PHONY: libretro +.PHONY: libretro tester From 9fbafab67f9d38726763d5a29bf446aaca00fc87 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 18:04:27 +0300 Subject: [PATCH 113/125] Use grep -q, put macOS first, restore -j --- .github/actions/sanity_tests.sh | 4 ++-- .github/workflows/sanity.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/sanity_tests.sh b/.github/actions/sanity_tests.sh index 8d37b68..38302d7 100755 --- a/.github/actions/sanity_tests.sh +++ b/.github/actions/sanity_tests.sh @@ -13,7 +13,7 @@ mv .github/actions/dmg{,-mode}-acid2.bmp --dmg --length 10 .github/actions/dmg-acid2.gb FAILED_TESTS=` -shasum .github/actions/*.bmp | grep -E -v \(\ +shasum .github/actions/*.bmp | grep -q -E -v \(\ 44ce0c7d49254df0637849c9155080ac7dc3ef3d\ \ .github/actions/cgb-acid2.bmp\|\ dbcc438dcea13b5d1b80c5cd06bda2592cc5d9e0\ \ .github/actions/cgb_sound.bmp\|\ 0caadf9634e40247ae9c15ff71992e8f77bbf89e\ \ .github/actions/dmg-acid2.bmp\|\ @@ -24,7 +24,7 @@ f0172cc91867d3343fbd113a2bb98100074be0de\ \ .github/actions/oam_bug-2.bmp\ if [ -n "$FAILED_TESTS" ] ; then echo "Failed the following tests:" - echo $FAILED_TESTS | tr " " "\n" | grep -o -E "[^/]+\.bmp" | sed s/.bmp// | sort + echo $FAILED_TESTS | tr " " "\n" | grep -q -o -E "[^/]+\.bmp" | sed s/.bmp// | sort exit 1 fi diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index 41404a0..ade68d0 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -5,7 +5,7 @@ jobs: sanity: strategy: matrix: - os: [ubuntu-latest, ubuntu-16.04, macos-latest] + os: [macos-latest, ubuntu-latest, ubuntu-16.04] cc: [gcc, clang] include: - os: macos-latest From f65dc736321cb51232ee69d3d0be51917221c59e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 18:09:04 +0300 Subject: [PATCH 114/125] -q was not enough --- .github/workflows/sanity.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index ade68d0..653e05d 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -23,7 +23,7 @@ jobs: ./.github/actions/install_deps.sh ${{ matrix.os }} - name: Build run: | - ${{ matrix.cc }} -v; make sdl tester libretro ${{ matrix.extra_target }} CONF=release CC=${{ matrix.cc }} + ${{ matrix.cc }} -v; make -j sdl tester libretro ${{ matrix.extra_target }} CONF=release CC=${{ matrix.cc }} - name: Sanity tests shell: bash run: | From 36aa3f31b947ca00d2682df7f8a01aa66ccde562 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 18:11:01 +0300 Subject: [PATCH 115/125] -q was not enough --- .github/actions/sanity_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/sanity_tests.sh b/.github/actions/sanity_tests.sh index 38302d7..8984b26 100755 --- a/.github/actions/sanity_tests.sh +++ b/.github/actions/sanity_tests.sh @@ -12,6 +12,8 @@ mv .github/actions/dmg{,-mode}-acid2.bmp ./build/bin/tester/sameboy_tester \ --dmg --length 10 .github/actions/dmg-acid2.gb +set +e + FAILED_TESTS=` shasum .github/actions/*.bmp | grep -q -E -v \(\ 44ce0c7d49254df0637849c9155080ac7dc3ef3d\ \ .github/actions/cgb-acid2.bmp\|\ From 152924e13fe851c0824579989b8f59d4dbd5358f Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 22:48:48 +0300 Subject: [PATCH 116/125] Add support to the ISX format, including symbols --- Cocoa/Document.m | 9 +- Cocoa/Info.plist | 47 +++++++- Core/debugger.c | 22 ++-- Core/debugger.h | 3 + Core/gb.c | 213 ++++++++++++++++++++++++++++++++++ Core/gb.h | 3 +- OpenDialog/cocoa.m | 2 +- OpenDialog/gtk.c | 1 + OpenDialog/windows.c | 2 +- QuickLook/Info.plist | 1 + QuickLook/get_image_for_rom.c | 18 ++- SDL/main.c | 18 ++- 12 files changed, 320 insertions(+), 19 deletions(-) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index ed3eaaf..ed52efb 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -647,11 +647,16 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) - (void) loadROM { NSString *rom_warnings = [self captureOutputForBlock:^{ - GB_load_rom(&gb, [self.fileName UTF8String]); + GB_debugger_clear_symbols(&gb); + if ([[self.fileType pathExtension] isEqualToString:@"isx"]) { + GB_load_isx(&gb, [self.fileName UTF8String]); + } + else { + GB_load_rom(&gb, [self.fileName UTF8String]); + } GB_load_battery(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sav"] UTF8String]); GB_load_cheats(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"cht"] UTF8String]); [self.cheatWindowController cheatsUpdated]; - GB_debugger_clear_symbols(&gb); GB_debugger_load_symbol_file(&gb, [[[NSBundle mainBundle] pathForResource:@"registers" ofType:@"sym"] UTF8String]); GB_debugger_load_symbol_file(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"sym"] UTF8String]); }]; diff --git a/Cocoa/Info.plist b/Cocoa/Info.plist index 1c7bdb5..44a21f0 100644 --- a/Cocoa/Info.plist +++ b/Cocoa/Info.plist @@ -16,7 +16,7 @@ CFBundleTypeIconFile Cartridge CFBundleTypeName - GameBoy Game + Game Boy Game CFBundleTypeRole Viewer LSItemContentTypes @@ -36,7 +36,7 @@ CFBundleTypeIconFile ColorCartridge CFBundleTypeName - GameBoy Color Game + Game Boy Color Game CFBundleTypeRole Viewer LSItemContentTypes @@ -48,6 +48,26 @@ NSDocumentClass Document + + CFBundleTypeExtensions + + gbc + + CFBundleTypeIconFile + ColorCartridge + CFBundleTypeName + Game Boy ISX File + CFBundleTypeRole + Viewer + LSItemContentTypes + + com.github.liji32.sameboy.isx + + LSTypeIsPackage + 0 + NSDocumentClass + Document + CFBundleExecutable SameBoy @@ -85,7 +105,7 @@ public.data UTTypeDescription - GameBoy Game + Game Boy Game UTTypeIconFile Cartridge UTTypeIdentifier @@ -104,7 +124,7 @@ public.data UTTypeDescription - GameBoy Color Game + Game Boy Color Game UTTypeIconFile ColorCartridge UTTypeIdentifier @@ -117,6 +137,25 @@ + + UTTypeConformsTo + + public.data + + UTTypeDescription + Game Boy ISX File + UTTypeIconFile + ColorCartridge + UTTypeIdentifier + com.github.liji32.sameboy.isx + UTTypeTagSpecification + + public.filename-extension + + isx + + + NSCameraUsageDescription SameBoy needs to access your camera to emulate the Game Boy Camera diff --git a/Core/debugger.c b/Core/debugger.c index ee27e88..caf0af1 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -2160,6 +2160,19 @@ void GB_debugger_handle_async_commands(GB_gameboy_t *gb) } } +void GB_debugger_add_symbol(GB_gameboy_t *gb, uint16_t bank, uint16_t address, const char *symbol) +{ + bank &= 0x1FF; + + if (!gb->bank_symbols[bank]) { + gb->bank_symbols[bank] = GB_map_alloc(); + } + GB_bank_symbol_t *allocated_symbol = GB_map_add_symbol(gb->bank_symbols[bank], address, symbol); + if (allocated_symbol) { + GB_reversed_map_add_symbol(&gb->reversed_symbol_map, bank, allocated_symbol); + } +} + void GB_debugger_load_symbol_file(GB_gameboy_t *gb, const char *path) { FILE *f = fopen(path, "r"); @@ -2182,14 +2195,7 @@ void GB_debugger_load_symbol_file(GB_gameboy_t *gb, const char *path) char symbol[length]; if (sscanf(line, "%x:%x %s", &bank, &address, symbol) == 3) { - bank &= 0x1FF; - if (!gb->bank_symbols[bank]) { - gb->bank_symbols[bank] = GB_map_alloc(); - } - GB_bank_symbol_t *allocated_symbol = GB_map_add_symbol(gb->bank_symbols[bank], address, symbol); - if (allocated_symbol) { - GB_reversed_map_add_symbol(&gb->reversed_symbol_map, bank, allocated_symbol); - } + GB_debugger_add_symbol(gb, bank, address, symbol); } } free(line); diff --git a/Core/debugger.h b/Core/debugger.h index 4868df3..b6a12d9 100644 --- a/Core/debugger.h +++ b/Core/debugger.h @@ -14,6 +14,8 @@ #define GB_debugger_call_hook(gb, addr) (void)addr #define GB_debugger_test_write_watchpoint(gb, addr, value) ((void)addr, (void)value) #define GB_debugger_test_read_watchpoint(gb, addr) (void)addr +#define GB_debugger_add_symbol(gb, bank, address, symbol) ((void)bank, (void)address, (void)symbol) + #else void GB_debugger_run(GB_gameboy_t *gb); void GB_debugger_handle_async_commands(GB_gameboy_t *gb); @@ -22,6 +24,7 @@ void GB_debugger_ret_hook(GB_gameboy_t *gb); void GB_debugger_test_write_watchpoint(GB_gameboy_t *gb, uint16_t addr, uint8_t value); void GB_debugger_test_read_watchpoint(GB_gameboy_t *gb, uint16_t addr); const GB_bank_symbol_t *GB_debugger_find_symbol(GB_gameboy_t *gb, uint16_t addr); +void GB_debugger_add_symbol(GB_gameboy_t *gb, uint16_t bank, uint16_t address, const char *symbol); #endif /* GB_DISABLE_DEBUGGER */ #endif diff --git a/Core/gb.c b/Core/gb.c index 2b22f9d..f1eae90 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -296,6 +296,219 @@ int GB_load_rom(GB_gameboy_t *gb, const char *path) return 0; } +int GB_load_isx(GB_gameboy_t *gb, const char *path) +{ + FILE *f = fopen(path, "rb"); + if (!f) { + GB_log(gb, "Could not open ISX file: %s.\n", strerror(errno)); + return errno; + } + char magic[4]; +#define READ(x) if (fread(&x, sizeof(x), 1, f) != 1) goto error + fread(magic, 1, sizeof(magic), f); + + bool extended = *(uint32_t *)&magic == htonl('ISX '); + + fseek(f, extended? 0x20 : 0, SEEK_SET); + + + uint8_t *old_rom = gb->rom; + uint32_t old_size = gb->rom_size; + gb->rom = NULL; + gb->rom_size = 0; + + while (true) { + uint8_t record_type = 0; + if (fread(&record_type, sizeof(record_type), 1, f) != 1) break; + switch (record_type) { + case 0x01: { // Binary + uint16_t bank; + uint16_t address; + uint16_t length; + uint8_t byte; + READ(byte); + bank = byte; + if (byte >= 0x80) { + READ(byte); + bank |= byte << 8; + } + + READ(address); +#ifdef GB_BIG_ENDIAN + address = __builtin_bswap16(address); +#endif + address &= 0x3FFF; + + READ(length); +#ifdef GB_BIG_ENDIAN + length = __builtin_bswap16(length); +#endif + + size_t needed_size = bank * 0x4000 + address + length; + if (needed_size > 1024 * 1024 * 32) + goto error; + + if (gb->rom_size < needed_size) { + gb->rom = realloc(gb->rom, needed_size); + memset(gb->rom + gb->rom_size, 0, needed_size - gb->rom_size); + gb->rom_size = needed_size; + } + + if (fread(gb->rom + (bank * 0x4000 + address), length, 1, f) != 1) + goto error; + + break; + } + + case 0x11: { // Extended Binary + uint32_t address; + uint32_t length; + + READ(address); +#ifdef GB_BIG_ENDIAN + address = __builtin_bswap32(address); +#endif + + READ(length); +#ifdef GB_BIG_ENDIAN + length = __builtin_bswap32(length); +#endif + size_t needed_size = address + length; + if (needed_size > 1024 * 1024 * 32) + goto error; + if (gb->rom_size < needed_size) { + gb->rom = realloc(gb->rom, needed_size); + memset(gb->rom + gb->rom_size, 0, needed_size - gb->rom_size); + gb->rom_size = needed_size; + } + + if (fread(gb->rom + address, length, 1, f) != 1) + goto error; + + break; + } + + case 0x04: { // Symbol + uint16_t count; + uint8_t length; + char name[257]; + uint8_t flag; + uint16_t bank; + uint16_t address; + uint8_t byte; + READ(count); +#ifdef GB_BIG_ENDIAN + count = __builtin_bswap16(count); +#endif + while (count--) { + READ(length); + if (fread(name, length, 1, f) != 1) + goto error; + name[length] = 0; + READ(flag); // unused + + READ(byte); + bank = byte; + if (byte >= 0x80) { + READ(byte); + bank |= byte << 8; + } + + READ(address); +#ifdef GB_BIG_ENDIAN + address = __builtin_bswap16(address); +#endif + GB_debugger_add_symbol(gb, bank, address, name); + } + break; + } + + case 0x14: { // Extended Binary + uint16_t count; + uint8_t length; + char name[257]; + uint8_t flag; + uint32_t address; + READ(count); +#ifdef GB_BIG_ENDIAN + count = __builtin_bswap16(count); +#endif + while (count--) { + READ(length); + if (fread(name, length + 1, 1, f) != 1) + goto error; + name[length] = 0; + READ(flag); // unused + + READ(address); +#ifdef GB_BIG_ENDIAN + address = __builtin_bswap32(address); +#endif + // TODO: How to convert 32-bit addresses to Bank:Address? Needs to tell RAM and ROM apart + } + break; + } + + default: + goto done; + } + } +done:; +#undef READ + if (gb->rom_size == 0) goto error; + + size_t needed_size = (gb->rom_size + 0x3FFF) & ~0x3FFF; /* Round to bank */ + + /* And then round to a power of two */ + while (needed_size & (needed_size - 1)) { + /* I promise this works. */ + needed_size |= needed_size >> 1; + needed_size++; + } + + if (needed_size < 0x8000) { + needed_size = 0x8000; + } + + if (gb->rom_size < needed_size) { + gb->rom = realloc(gb->rom, needed_size); + memset(gb->rom + gb->rom_size, 0, needed_size - gb->rom_size); + gb->rom_size = needed_size; + } + + GB_configure_cart(gb); + + // Fix a common wrong MBC error + if (gb->rom[0x147] == 3) { // MBC1 + RAM + Battery + if (gb->rom_size == 64 * 0x4000) { + for (unsigned i = 63 * 0x4000; i < 64 * 0x4000; i++) { + if (gb->rom[i]) { + gb->rom[0x147] = 0x10; // MBC3 + RTC + RAM + Battery + GB_configure_cart(gb); + gb->rom[0x147] = 0x3; + GB_log(gb, "ROM uses MBC1 but appears to use all 64 banks, assuming MBC3\n"); + break; + } + } + } + } + + if (old_rom) { + free(old_rom); + } + + return 0; +error: + GB_log(gb, "Invalid or unsupported ISX file.\n"); + if (gb->rom) { + free(gb->rom); + gb->rom = old_rom; + gb->rom_size = old_size; + } + fclose(f); + return -1; +} + void GB_load_rom_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t size) { gb->rom_size = (size + 0x3fff) & ~0x3fff; diff --git a/Core/gb.h b/Core/gb.h index 703a489..a83bb09 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -721,7 +721,8 @@ int GB_load_boot_rom(GB_gameboy_t *gb, const char *path); void GB_load_boot_rom_from_buffer(GB_gameboy_t *gb, const unsigned char *buffer, size_t size); int GB_load_rom(GB_gameboy_t *gb, const char *path); void GB_load_rom_from_buffer(GB_gameboy_t *gb, const uint8_t *buffer, size_t size); - +int GB_load_isx(GB_gameboy_t *gb, const char *path); + int GB_save_battery_size(GB_gameboy_t *gb); int GB_save_battery_to_buffer(GB_gameboy_t *gb, uint8_t *buffer, size_t size); int GB_save_battery(GB_gameboy_t *gb, const char *path); diff --git a/OpenDialog/cocoa.m b/OpenDialog/cocoa.m index 29a722c..76b9606 100644 --- a/OpenDialog/cocoa.m +++ b/OpenDialog/cocoa.m @@ -8,7 +8,7 @@ char *do_open_rom_dialog(void) NSWindow *key = [NSApp keyWindow]; NSOpenPanel *dialog = [NSOpenPanel openPanel]; dialog.title = @"Open ROM"; - dialog.allowedFileTypes = @[@"gb", @"gbc", @"sgb"]; + dialog.allowedFileTypes = @[@"gb", @"gbc", @"sgb", @"isx"]; [dialog runModal]; [key makeKeyAndOrderFront:nil]; NSString *ret = [[[dialog URLs] firstObject] path]; diff --git a/OpenDialog/gtk.c b/OpenDialog/gtk.c index d9163fc..5b1caa3 100644 --- a/OpenDialog/gtk.c +++ b/OpenDialog/gtk.c @@ -82,6 +82,7 @@ char *do_open_rom_dialog(void) gtk_file_filter_add_pattern(filter, "*.gb"); gtk_file_filter_add_pattern(filter, "*.gbc"); gtk_file_filter_add_pattern(filter, "*.sgb"); + gtk_file_filter_add_pattern(filter, "*.isx"); gtk_file_filter_set_name(filter, "Game Boy ROMs"); gtk_file_chooser_add_filter(dialog, filter); diff --git a/OpenDialog/windows.c b/OpenDialog/windows.c index 6bf9b89..52e281d 100644 --- a/OpenDialog/windows.c +++ b/OpenDialog/windows.c @@ -10,7 +10,7 @@ char *do_open_rom_dialog(void) dialog.lStructSize = sizeof(dialog); dialog.lpstrFile = filename; dialog.nMaxFile = sizeof(filename); - dialog.lpstrFilter = L"Game Boy ROMs\0*.gb;*.gbc;*.sgb\0All files\0*.*\0\0"; + dialog.lpstrFilter = L"Game Boy ROMs\0*.gb;*.gbc;*.sgb;*.isx\0All files\0*.*\0\0"; dialog.nFilterIndex = 1; dialog.lpstrFileTitle = NULL; dialog.nMaxFileTitle = 0; diff --git a/QuickLook/Info.plist b/QuickLook/Info.plist index 2cff196..b01aae1 100644 --- a/QuickLook/Info.plist +++ b/QuickLook/Info.plist @@ -13,6 +13,7 @@ com.github.liji32.sameboy.gb com.github.liji32.sameboy.gbc + com.github.liji32.sameboy.isx diff --git a/QuickLook/get_image_for_rom.c b/QuickLook/get_image_for_rom.c index 3950dac..b9f87ed 100755 --- a/QuickLook/get_image_for_rom.c +++ b/QuickLook/get_image_for_rom.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "get_image_for_rom.h" @@ -60,7 +61,22 @@ int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *out GB_set_log_callback(&gb, log_callback); GB_set_color_correction_mode(&gb, GB_COLOR_CORRECTION_EMULATE_HARDWARE); - if (GB_load_rom(&gb, filename)) { + size_t length = strlen(filename); + char extension[4] = {0,}; + if (length > 4) { + if (filename[length - 4] == '.') { + extension[0] = tolower(filename[length - 3]); + extension[1] = tolower(filename[length - 2]); + extension[2] = tolower(filename[length - 1]); + } + } + if (strcmp(extension, "isx") == 0) { + if (GB_load_isx(&gb, filename)) { + GB_free(&gb); + return 1; + } + } + else if (GB_load_rom(&gb, filename)) { GB_free(&gb); return 1; } diff --git a/SDL/main.c b/SDL/main.c index 4ce2e59..e09630b 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -526,8 +527,23 @@ restart: } bool error = false; + GB_debugger_clear_symbols(&gb); start_capturing_logs(); - error = GB_load_rom(&gb, filename); + size_t length = strlen(filename); + char extension[4] = {0,}; + if (length > 4) { + if (filename[length - 4] == '.') { + extension[0] = tolower(filename[length - 3]); + extension[1] = tolower(filename[length - 2]); + extension[2] = tolower(filename[length - 1]); + } + } + if (strcmp(extension, "isx") == 0) { + error = GB_load_isx(&gb, filename); + } + else { + GB_load_rom(&gb, filename); + } end_capturing_logs(true, error); size_t path_length = strlen(filename); From ca567bee7913bb588cadd5b6f41a250e89b0389c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 22:54:50 +0300 Subject: [PATCH 117/125] Fix Linux build break --- Core/gb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Core/gb.c b/Core/gb.c index f1eae90..701a48a 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -307,7 +307,11 @@ int GB_load_isx(GB_gameboy_t *gb, const char *path) #define READ(x) if (fread(&x, sizeof(x), 1, f) != 1) goto error fread(magic, 1, sizeof(magic), f); - bool extended = *(uint32_t *)&magic == htonl('ISX '); +#ifdef GB_BIG_ENDIAN + bool extended = *(uint32_t *)&magic == 'ISX '; +#else + bool extended = *(uint32_t *)&magic == __builtin_bswap32('ISX '); +#endif fseek(f, extended? 0x20 : 0, SEEK_SET); From 9e99ce434e9903d7c1db0747a344059768505814 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 23:09:08 +0300 Subject: [PATCH 118/125] Allow loading .RAM files --- Cocoa/Document.m | 2 ++ SDL/main.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index ed52efb..6eb9c2f 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -650,6 +650,8 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) GB_debugger_clear_symbols(&gb); if ([[self.fileType pathExtension] isEqualToString:@"isx"]) { GB_load_isx(&gb, [self.fileName UTF8String]); + GB_load_battery(&gb, [[[self.fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"ram"] UTF8String]); + } else { GB_load_rom(&gb, [self.fileName UTF8String]); diff --git a/SDL/main.c b/SDL/main.c index e09630b..9a358d0 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -540,6 +540,11 @@ restart: } if (strcmp(extension, "isx") == 0) { error = GB_load_isx(&gb, filename); + /* Try loading .ram file if available */ + char battery_save_path[path_length + 5]; /* At the worst case, size is strlen(path) + 4 bytes for .sav + NULL */ + replace_extension(filename, path_length, battery_save_path, ".ram"); + battery_save_path_ptr = battery_save_path; + GB_load_battery(&gb, battery_save_path); } else { GB_load_rom(&gb, filename); From 0534b091a576312f5d5ea2be4ad48ee4b53d01cb Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 23:11:29 +0300 Subject: [PATCH 119/125] Fix SDL --- SDL/main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/SDL/main.c b/SDL/main.c index 9a358d0..e27c0f2 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -529,18 +529,18 @@ restart: bool error = false; GB_debugger_clear_symbols(&gb); start_capturing_logs(); - size_t length = strlen(filename); + size_t path_length = strlen(filename); char extension[4] = {0,}; - if (length > 4) { - if (filename[length - 4] == '.') { - extension[0] = tolower(filename[length - 3]); - extension[1] = tolower(filename[length - 2]); - extension[2] = tolower(filename[length - 1]); + if (path_length > 4) { + if (filename[path_length - 4] == '.') { + extension[0] = tolower(filename[path_length - 3]); + extension[1] = tolower(filename[path_length - 2]); + extension[2] = tolower(filename[path_length - 1]); } } if (strcmp(extension, "isx") == 0) { error = GB_load_isx(&gb, filename); - /* Try loading .ram file if available */ + /* Configure battery */ char battery_save_path[path_length + 5]; /* At the worst case, size is strlen(path) + 4 bytes for .sav + NULL */ replace_extension(filename, path_length, battery_save_path, ".ram"); battery_save_path_ptr = battery_save_path; @@ -551,7 +551,6 @@ restart: } end_capturing_logs(true, error); - size_t path_length = strlen(filename); /* Configure battery */ char battery_save_path[path_length + 5]; /* At the worst case, size is strlen(path) + 4 bytes for .sav + NULL */ From d1e3ad7790879330845b2bbcb63260cbc5505de4 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 23:18:03 +0300 Subject: [PATCH 120/125] Better hueristics for wrong MBC type --- Core/gb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/gb.c b/Core/gb.c index 701a48a..966022b 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -484,13 +484,13 @@ done:; // Fix a common wrong MBC error if (gb->rom[0x147] == 3) { // MBC1 + RAM + Battery - if (gb->rom_size == 64 * 0x4000) { - for (unsigned i = 63 * 0x4000; i < 64 * 0x4000; i++) { + if (gb->rom_size >= 33 * 0x4000) { + for (unsigned i = 32 * 0x4000; i < 33 * 0x4000; i++) { if (gb->rom[i]) { gb->rom[0x147] = 0x10; // MBC3 + RTC + RAM + Battery GB_configure_cart(gb); gb->rom[0x147] = 0x3; - GB_log(gb, "ROM uses MBC1 but appears to use all 64 banks, assuming MBC3\n"); + GB_log(gb, "ROM claims to use MBC1 but appears to require MBC3 or 5, assuming MBC3.\n"); break; } } From 110cedeaac3918170263377792e63f5addf436df Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 25 Apr 2020 23:26:17 +0300 Subject: [PATCH 121/125] Even better hueristics --- Core/gb.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Core/gb.c b/Core/gb.c index 966022b..a17a5a7 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -484,17 +484,37 @@ done:; // Fix a common wrong MBC error if (gb->rom[0x147] == 3) { // MBC1 + RAM + Battery - if (gb->rom_size >= 33 * 0x4000) { - for (unsigned i = 32 * 0x4000; i < 33 * 0x4000; i++) { + bool needs_fix = false; + if (gb->rom_size >= 0x21 * 0x4000) { + for (unsigned i = 0x20 * 0x4000; i < 0x21 * 0x4000; i++) { if (gb->rom[i]) { - gb->rom[0x147] = 0x10; // MBC3 + RTC + RAM + Battery - GB_configure_cart(gb); - gb->rom[0x147] = 0x3; - GB_log(gb, "ROM claims to use MBC1 but appears to require MBC3 or 5, assuming MBC3.\n"); + needs_fix = true; break; } } } + if (!needs_fix && gb->rom_size >= 0x41 * 0x4000) { + for (unsigned i = 0x40 * 0x4000; i < 0x41 * 0x4000; i++) { + if (gb->rom[i]) { + needs_fix = true; + break; + } + } + } + if (!needs_fix && gb->rom_size >= 0x61 * 0x4000) { + for (unsigned i = 0x60 * 0x4000; i < 0x61 * 0x4000; i++) { + if (gb->rom[i]) { + needs_fix = true; + break; + } + } + } + if (needs_fix) { + gb->rom[0x147] = 0x10; // MBC3 + RTC + RAM + Battery + GB_configure_cart(gb); + gb->rom[0x147] = 0x3; + GB_log(gb, "ROM claims to use MBC1 but appears to require MBC3 or 5, assuming MBC3.\n"); + } } if (old_rom) { From 8d016f19d22c87aa11ead516a0c579a1a040544c Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 27 Apr 2020 21:12:30 +0300 Subject: [PATCH 122/125] Move the audio code to a different file --- Makefile | 3 +- SDL/audio/audio.h | 16 +++++++++ SDL/audio/sdl.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ SDL/main.c | 81 ++++++++----------------------------------- 4 files changed, 119 insertions(+), 68 deletions(-) create mode 100644 SDL/audio/audio.h create mode 100644 SDL/audio/sdl.c diff --git a/Makefile b/Makefile index 49e24b5..9df7eb8 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ endif VERSION := 0.12.3 export VERSION CONF ?= debug +SDL_AUDIO_DRIVER ?= sdl BIN := build/bin OBJ := build/obj @@ -172,7 +173,7 @@ all: cocoa sdl tester libretro # Get a list of our source files and their respective object file targets CORE_SOURCES := $(shell ls Core/*.c) -SDL_SOURCES := $(shell ls SDL/*.c) $(OPEN_DIALOG) +SDL_SOURCES := $(shell ls SDL/*.c) $(OPEN_DIALOG) SDL/audio/$(SDL_AUDIO_DRIVER).c TESTER_SOURCES := $(shell ls Tester/*.c) ifeq ($(PLATFORM),Darwin) diff --git a/SDL/audio/audio.h b/SDL/audio/audio.h new file mode 100644 index 0000000..acaa011 --- /dev/null +++ b/SDL/audio/audio.h @@ -0,0 +1,16 @@ +#ifndef sdl_audio_h +#define sdl_audio_h + +#include +#include +#include + +bool GB_audio_is_playing(void); +void GB_audio_set_paused(bool paused); +void GB_audio_clear_queue(void); +unsigned GB_audio_get_frequency(void); +size_t GB_audio_get_queue_length(void); +void GB_audio_queue_sample(GB_sample_t *sample); +void GB_audio_init(void); + +#endif /* sdl_audio_h */ diff --git a/SDL/audio/sdl.c b/SDL/audio/sdl.c new file mode 100644 index 0000000..1f8a529 --- /dev/null +++ b/SDL/audio/sdl.c @@ -0,0 +1,87 @@ +#include "audio.h" +#include + +#ifndef _WIN32 +#define AUDIO_FREQUENCY 96000 +#include +#else +#include +/* Windows (well, at least my VM) can't handle 96KHz sound well :( */ + +/* felsqualle says: For SDL 2.0.6+ using the WASAPI driver, the highest freq. + we can get is 48000. 96000 also works, but always has some faint crackling in + the audio, no matter how high or low I set the buffer length... + Not quite satisfied with that solution, because acc. to SDL2 docs, + 96k + WASAPI *should* work. */ + +#define AUDIO_FREQUENCY 48000 +#endif + +/* Compatibility with older SDL versions */ +#ifndef SDL_AUDIO_ALLOW_SAMPLES_CHANGE +#define SDL_AUDIO_ALLOW_SAMPLES_CHANGE 0 +#endif + +static SDL_AudioDeviceID device_id; +static SDL_AudioSpec want_aspec, have_aspec; + +bool GB_audio_is_playing(void) +{ + return SDL_GetAudioDeviceStatus(device_id) == SDL_AUDIO_PLAYING; +} + +void GB_audio_set_paused(bool paused) +{ + GB_audio_clear_queue(); + SDL_PauseAudioDevice(device_id, paused); +} + +void GB_audio_clear_queue(void) +{ + SDL_ClearQueuedAudio(device_id); +} + +unsigned GB_audio_get_frequency(void) +{ + return have_aspec.freq; +} + +size_t GB_audio_get_queue_length(void) +{ + return SDL_GetQueuedAudioSize(device_id); +} + +void GB_audio_queue_sample(GB_sample_t *sample) +{ + SDL_QueueAudio(device_id, sample, sizeof(*sample)); +} + +void GB_audio_init(void) +{ + /* Configure Audio */ + memset(&want_aspec, 0, sizeof(want_aspec)); + want_aspec.freq = AUDIO_FREQUENCY; + want_aspec.format = AUDIO_S16SYS; + want_aspec.channels = 2; + want_aspec.samples = 512; + + SDL_version _sdl_version; + SDL_GetVersion(&_sdl_version); + unsigned sdl_version = _sdl_version.major * 1000 + _sdl_version.minor * 100 + _sdl_version.patch; + +#ifndef _WIN32 + /* SDL 2.0.5 on macOS and Linux introduced a bug where certain combinations of buffer lengths and frequencies + fail to produce audio correctly. */ + if (sdl_version >= 2005) { + want_aspec.samples = 2048; + } +#else + if (sdl_version < 2006) { + /* Since WASAPI audio was introduced in SDL 2.0.6, we have to lower the audio frequency + to 44100 because otherwise we would get garbled audio output.*/ + want_aspec.freq = 44100; + } +#endif + + device_id = SDL_OpenAudioDevice(0, 0, &want_aspec, &have_aspec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_SAMPLES_CHANGE); +} diff --git a/SDL/main.c b/SDL/main.c index e27c0f2..c4a4d0f 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -8,27 +8,12 @@ #include "utils.h" #include "gui.h" #include "shader.h" - +#include "audio/audio.h" #ifndef _WIN32 -#define AUDIO_FREQUENCY 96000 #include #else #include -/* Windows (well, at least my VM) can't handle 96KHz sound well :( */ - -/* felsqualle says: For SDL 2.0.6+ using the WASAPI driver, the highest freq. - we can get is 48000. 96000 also works, but always has some faint crackling in - the audio, no matter how high or low I set the buffer length... - Not quite satisfied with that solution, because acc. to SDL2 docs, - 96k + WASAPI *should* work. */ - -#define AUDIO_FREQUENCY 48000 -#endif - -/* Compatibility with older SDL versions */ -#ifndef SDL_AUDIO_ALLOW_SAMPLES_CHANGE -#define SDL_AUDIO_ALLOW_SAMPLES_CHANGE 0 #endif GB_gameboy_t gb; @@ -42,7 +27,6 @@ static char *filename = NULL; static typeof(free) *free_function = NULL; static char *battery_save_path_ptr; -SDL_AudioDeviceID device_id; void set_filename(const char *new_filename, typeof(free) *new_free_function) { @@ -53,8 +37,6 @@ void set_filename(const char *new_filename, typeof(free) *new_free_function) free_function = new_free_function; } -static SDL_AudioSpec want_aspec, have_aspec; - static char *captured_log = NULL; static void log_capture_callback(GB_gameboy_t *gb, const char *string, GB_log_attributes attributes) @@ -127,16 +109,15 @@ static void screen_size_changed(void) static void open_menu(void) { - bool audio_playing = SDL_GetAudioDeviceStatus(device_id) == SDL_AUDIO_PLAYING; + bool audio_playing = GB_audio_is_playing(); if (audio_playing) { - SDL_PauseAudioDevice(device_id, 1); + GB_audio_set_paused(true); } size_t previous_width = GB_get_screen_width(&gb); run_gui(true); SDL_ShowCursor(SDL_DISABLE); if (audio_playing) { - SDL_ClearQueuedAudio(device_id); - SDL_PauseAudioDevice(device_id, 0); + GB_audio_set_paused(false); } GB_set_color_correction_mode(&gb, configuration.color_correction_mode); GB_set_border_mode(&gb, configuration.border_mode); @@ -176,7 +157,7 @@ static void handle_events(GB_gameboy_t *gb) GB_set_key_state(gb, (GB_key_t) button, event.type == SDL_JOYBUTTONDOWN); } else if (button == JOYPAD_BUTTON_TURBO) { - SDL_ClearQueuedAudio(device_id); + GB_audio_clear_queue(); turbo_down = event.type == SDL_JOYBUTTONDOWN; GB_set_turbo_mode(gb, turbo_down, turbo_down && rewind_down); } @@ -294,14 +275,7 @@ static void handle_events(GB_gameboy_t *gb) break; } #endif - bool audio_playing = SDL_GetAudioDeviceStatus(device_id) == SDL_AUDIO_PLAYING; - if (audio_playing) { - SDL_PauseAudioDevice(device_id, 1); - } - else if (!audio_playing) { - SDL_ClearQueuedAudio(device_id); - SDL_PauseAudioDevice(device_id, 0); - } + GB_audio_set_paused(GB_audio_is_playing()); } break; @@ -336,7 +310,7 @@ static void handle_events(GB_gameboy_t *gb) case SDL_KEYUP: // Fallthrough if (event.key.keysym.scancode == configuration.keys[8]) { turbo_down = event.type == SDL_KEYDOWN; - SDL_ClearQueuedAudio(device_id); + GB_audio_clear_queue(); GB_set_turbo_mode(gb, turbo_down, turbo_down && rewind_down); } else if (event.key.keysym.scancode == configuration.keys_2[0]) { @@ -409,15 +383,15 @@ static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) if (turbo_down) { static unsigned skip = 0; skip++; - if (skip == have_aspec.freq / 8) { + if (skip == GB_audio_get_frequency() / 8) { skip = 0; } - if (skip > have_aspec.freq / 16) { + if (skip > GB_audio_get_frequency() / 16) { return; } } - if (SDL_GetQueuedAudioSize(device_id) / sizeof(*sample) > have_aspec.freq / 4) { + if (GB_audio_get_queue_length() / sizeof(*sample) > GB_audio_get_frequency() / 4) { return; } @@ -426,7 +400,7 @@ static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) sample->right = sample->right * configuration.volume / 100; } - SDL_QueueAudio(device_id, sample, sizeof(*sample)); + GB_audio_queue_sample(sample); } @@ -514,7 +488,7 @@ restart: GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank); GB_set_pixels_output(&gb, active_pixel_buffer); GB_set_rgb_encode_callback(&gb, rgb_encode); - GB_set_sample_rate(&gb, have_aspec.freq); + GB_set_sample_rate(&gb, GB_audio_get_frequency()); GB_set_color_correction_mode(&gb, configuration.color_correction_mode); update_palette(); if ((unsigned)configuration.border_mode <= GB_BORDER_ALWAYS) { @@ -675,34 +649,7 @@ int main(int argc, char **argv) pixel_format = SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888); } - - /* Configure Audio */ - memset(&want_aspec, 0, sizeof(want_aspec)); - want_aspec.freq = AUDIO_FREQUENCY; - want_aspec.format = AUDIO_S16SYS; - want_aspec.channels = 2; - want_aspec.samples = 512; - - SDL_version _sdl_version; - SDL_GetVersion(&_sdl_version); - unsigned sdl_version = _sdl_version.major * 1000 + _sdl_version.minor * 100 + _sdl_version.patch; - -#ifndef _WIN32 - /* SDL 2.0.5 on macOS and Linux introduced a bug where certain combinations of buffer lengths and frequencies - fail to produce audio correctly. */ - if (sdl_version >= 2005) { - want_aspec.samples = 2048; - } -#else - if (sdl_version < 2006) { - /* Since WASAPI audio was introduced in SDL 2.0.6, we have to lower the audio frequency - to 44100 because otherwise we would get garbled audio output.*/ - want_aspec.freq = 44100; - } -#endif - - device_id = SDL_OpenAudioDevice(0, 0, &want_aspec, &have_aspec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_SAMPLES_CHANGE); - /* Start Audio */ + GB_audio_init(); SDL_EventState(SDL_DROPFILE, SDL_ENABLE); @@ -735,7 +682,7 @@ int main(int argc, char **argv) else { connect_joypad(); } - SDL_PauseAudioDevice(device_id, 0); + GB_audio_set_paused(false); run(); // Never returns return 0; } From c64d5b58b6a8f09877e8dc115a5ba657fca63895 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 27 Apr 2020 23:29:26 +0300 Subject: [PATCH 123/125] Make failed builds easier to read --- .github/workflows/sanity.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index 653e05d..d25a180 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -23,7 +23,7 @@ jobs: ./.github/actions/install_deps.sh ${{ matrix.os }} - name: Build run: | - ${{ matrix.cc }} -v; make -j sdl tester libretro ${{ matrix.extra_target }} CONF=release CC=${{ matrix.cc }} + ${{ matrix.cc }} -v; (make -j sdl tester libretro ${{ matrix.extra_target }} CONF=release CC=${{ matrix.cc }} || (echo "==== Build Failed ==="; make sdl tester libretro ${{ matrix.extra_target }} CONF=release CC=${{ matrix.cc }})) - name: Sanity tests shell: bash run: | From 1e54c55c117f1141699d53647e2348460e96440a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 28 Apr 2020 21:44:29 +0300 Subject: [PATCH 124/125] Making libretro compile without warnings with GCC --- Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9df7eb8..94e8a83 100644 --- a/Makefile +++ b/Makefile @@ -89,14 +89,16 @@ OPEN_DIALOG = OpenDialog/cocoa.m endif # These must come before the -Wno- flags -CFLAGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option -CFLAGS += -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context +WARNINGS += -Werror -Wall -Wno-unknown-warning -Wno-unknown-warning-option +WARNINGS += -Wno-nonnull -Wno-unused-result -Wno-strict-aliasing -Wno-multichar -Wno-int-in-bool-context # Only add this flag if the compiler supports it ifeq ($(shell $(CC) -x c -c $(NULL) -o $(NULL) -Werror -Wpartial-availability 2> $(NULL); echo $$?),0) -CFLAGS += -Wpartial-availability +WARNINGS += -Wpartial-availability endif +CFLAGS += $(WARNINGS) + CFLAGS += -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES ifeq (,$(PKG_CONFIG)) @@ -396,7 +398,7 @@ $(BIN)/BootROMs/%.bin: BootROMs/%.asm $(OBJ)/BootROMs/SameBoyLogo.pb8 # Libretro Core (uses its own build system) libretro: - $(MAKE) -C libretro + CFLAGS="$(WARNINGS)" $(MAKE) -C libretro # Clean clean: From 8f6047fdca3f909b0b1809f4d76c5b6684f7b679 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 28 Apr 2020 21:53:37 +0300 Subject: [PATCH 125/125] Prevent -Wall from overriding -Wno flags --- libretro/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libretro/Makefile b/libretro/Makefile index 7e19893..b327628 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -1,6 +1,8 @@ STATIC_LINKING := 0 AR := ar +CFLAGS := -Wall $(CFLAGS) + GIT_VERSION ?= " $(shell git rev-parse --short HEAD || echo unknown)" ifneq ($(GIT_VERSION)," unknown") CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" @@ -93,7 +95,7 @@ else ifeq ($(platform), linux-portable) else ifeq ($(platform), switch) TARGET := $(TARGET_NAME)_libretro_$(platform).a include $(LIBTRANSISTOR_HOME)/libtransistor.mk - CFLAGS += -Wl,-q -Wall -O3 -fno-short-enums -fno-optimize-sibling-calls + CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls STATIC_LINKING=1 # Nintendo WiiU else ifeq ($(platform), wiiu) @@ -141,7 +143,7 @@ else ifeq ($(platform), vita) TARGET := $(TARGET_NAME)_vita.a CC = arm-vita-eabi-gcc AR = arm-vita-eabi-ar - CFLAGS += -Wl,-q -Wall -O3 -fno-short-enums -fno-optimize-sibling-calls + CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls STATIC_LINKING = 1 # Windows MSVC 2017 all architectures @@ -278,7 +280,7 @@ else LD = $(CC) endif -CFLAGS += -Wall -D__LIBRETRO__ $(fpic) $(INCFLAGS) -std=gnu11 -D_GNU_SOURCE -D_USE_MATH_DEFINES +CFLAGS += -D__LIBRETRO__ $(fpic) $(INCFLAGS) -std=gnu11 -D_GNU_SOURCE -D_USE_MATH_DEFINES all: $(TARGET)