diff --git a/BootROMs/agb_boot.asm b/BootROMs/agb_boot.asm
new file mode 100644
index 00000000..95a2c783
--- /dev/null
+++ b/BootROMs/agb_boot.asm
@@ -0,0 +1,2 @@
+AGB EQU 1
+include "cgb_boot.asm"
\ No newline at end of file
diff --git a/BootROMs/cgb_boot.asm b/BootROMs/cgb_boot.asm
index 92f06713..6b0d6011 100644
--- a/BootROMs/cgb_boot.asm
+++ b/BootROMs/cgb_boot.asm
@@ -732,7 +732,28 @@ Preboot:
ld a, [InputPalette]
and a
jr nz, .emulateDMGForCGBGame
- ld a, $11
+IF DEF(AGB)
+ ; Set registers to match the original AGB-CGB boot
+ ld bc, $1100
+ push bc
+ pop af
+ ld h, c
+ ld b, 1
+ ld c, c
+ ld e, $08
+ ld l, $7c
+ELSE
+ ; Set registers to match the original CGB boot
+ ld bc, $1180
+ push bc
+ pop af
+ ld c, 0
+ ld h, c
+ ld b, c
+ ld c, c
+ ld e, $08
+ ld l, $7c
+ENDC
ret
.emulateDMGForCGBGame
diff --git a/Cocoa/Document.m b/Cocoa/Document.m
index e5fb9ae1..6ec45c89 100644
--- a/Cocoa/Document.m
+++ b/Cocoa/Document.m
@@ -11,6 +11,13 @@
/* 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!!! */
+enum model {
+ MODEL_NONE,
+ MODEL_DMG,
+ MODEL_CGB,
+ MODEL_AGB,
+};
+
@interface Document ()
{
/* NSTextViews freeze the entire app if they're modified too often and too quickly.
@@ -43,6 +50,7 @@
NSMutableString *capturedOutput;
bool logToSideView;
bool shouldClearSideView;
+ enum model current_model;
}
@property GBAudioClient *audioClient;
@@ -126,6 +134,7 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
- (void) initDMG
{
+ current_model = MODEL_DMG;
GB_init(&gb);
[self initCommon];
GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"dmg_boot" ofType:@"bin"] UTF8String]);
@@ -135,7 +144,14 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
{
GB_init_cgb(&gb);
[self initCommon];
- GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"cgb_boot" ofType:@"bin"] UTF8String]);
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateAGB"]) {
+ current_model = MODEL_AGB;
+ GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"agb_boot" ofType:@"bin"] UTF8String]);
+ }
+ else {
+ current_model = MODEL_CGB;
+ GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"cgb_boot" ofType:@"bin"] UTF8String]);
+ }
}
- (void) initCommon
@@ -214,17 +230,20 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
{
[self stop];
- if ([sender tag] == 0) {
+ if ([sender tag] == MODEL_NONE) {
GB_reset(&gb);
}
else {
- GB_switch_model_and_reset(&gb, [sender tag] == 2);
- GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:[sender tag] == 2? @"cgb_boot" : @"dmg_boot" ofType:@"bin"] UTF8String]);
+ current_model = (enum model)[sender tag];
+ GB_switch_model_and_reset(&gb, current_model != MODEL_DMG);
+ static NSString * const boot_names[] = {@"dmg_boot", @"cgb_boot", @"agb_boot"};
+ GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:boot_names[current_model - 1] ofType:@"bin"] UTF8String]);
}
if ([sender tag] != 0) {
/* User explictly selected a model, save the preference */
- [[NSUserDefaults standardUserDefaults] setBool:[sender tag] == 1 forKey:@"EmulateDMG"];
+ [[NSUserDefaults standardUserDefaults] setBool:current_model == MODEL_DMG forKey:@"EmulateDMG"];
+ [[NSUserDefaults standardUserDefaults] setBool:current_model== MODEL_AGB forKey:@"EmulateAGB"];
}
/* Reload the ROM, SAV and SYM files */
@@ -441,8 +460,8 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
[(NSMenuItem*)anItem setState:(!running) || (GB_debugger_is_stopped(&gb))];
return !GB_debugger_is_stopped(&gb);
}
- else if ([anItem action] == @selector(reset:) && anItem.tag != 0) {
- [(NSMenuItem*)anItem setState:(anItem.tag == 1 && !GB_is_cgb(&gb)) || (anItem.tag == 2 && GB_is_cgb(&gb))];
+ 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];
diff --git a/Cocoa/MainMenu.xib b/Cocoa/MainMenu.xib
index d43f1071..18af33e9 100644
--- a/Cocoa/MainMenu.xib
+++ b/Cocoa/MainMenu.xib
@@ -311,18 +311,24 @@
-