Skip to content

Commit

Permalink
added support for MBC2 games, fixing Wave Race and more
Browse files Browse the repository at this point in the history
  • Loading branch information
marcrobledo committed Jun 8, 2024
1 parent 8946530 commit 96dd6b8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h1 class="hide">Super Game Boy Border Injector</h1>


<footer>
Super Game Boy Border Injector v1.2.1b<br/>
Super Game Boy Border Injector v1.3<br/>
made with <span class="love" title="Super love">Super <img src="web-injector/assets/octicon_heart_color.svg" alt="love" class="octicon" /></span> by <a href="https://www.marcrobledo.com" target="_blank">Marc Robledo</a>
<img src="web-injector/assets/octicon_github.svg" alt="GitHub logo" class="octicon" /> <a href="https://github.com/marcrobledo/super-game-boy-border-injector/" target="_blank">See sourcecode in GitHub</a>
</footer>
Expand Down
12 changes: 10 additions & 2 deletions src/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ boot_hook:
push af

ld a, BANK(sgb_init)
ld [rROMB0], a
IF MBC == 2
ld [$2100], a
ELSE
ld [rROMB0], a
ENDC

IF MBC == 1 && SGB_CODE_BANK>=$20
ld a, ((BANK(sgb_init) & %01100000) >> 5)
Expand All @@ -49,7 +53,11 @@ boot_hook:

call sgb_init

ld [rROMB0], a
IF MBC == 2
ld [$2100], a
ELSE
ld [rROMB0], a
ENDC
IF MBC == 1 && SGB_CODE_BANK>=$20
xor a
ld [rRAMB], a
Expand Down
1 change: 1 addition & 0 deletions src/settings.asm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DEF BANK0_FREE_SPACE EQU $3ff0
; (see more here: https://gbdev.io/pandocs/MBCs.html)
; MBC needs to be here specified in these special cases:
; - MBC1 + expanded ROM to 1Mb or bigger (Zelda Link's Awakening [non-DX])
; - MBC2 (bank to switch has to be written to $2100 instead of $2000: https://gbdev.io/pandocs/MBC2.html#registers)
; - (to-do!) MBC5 + expanded ROM to 8Mb
; other cases will just ignore this value
; keep in mind that, in these special cases, the hook subroutine will grow
Expand Down
14 changes: 14 additions & 0 deletions web-injector/app/assembled-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ export const ASSEMBLED_HOOK_INFO=[
0xf1, //pop af
0xc3, 'entry_point_low', 'entry_point_high' //jp original_entry_point
]
},
//MBC2
//rom bank must be written to 0x2100
{
id:'mbc2',
code:[
0xf5, //push af
0x3e, 'rom_bank_number', //ld a, sgb_init_bank
0xea, 0x00, 0x21, //ld [0x2100], a
0xcd, 0x00, 0x40, //call 0x4000
0xea, 0x00, 0x21, //ld [0x2100], a
0xf1, //pop af
0xc3, 'entry_point_low', 'entry_point_high' //jp original_entry_point
]
}
];
ASSEMBLED_HOOK_INFO.forEach(function(assembledInfo){
Expand Down
2 changes: 2 additions & 0 deletions web-injector/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ function buildROM(){
}

assembledHookInfo=getAssembledHookInfo('mbc1_extra');
}else if(currentRomType.mbc===2){
assembledHookInfo=getAssembledHookInfo('mbc2');
}else{
assembledHookInfo=getAssembledHookInfo('default');
}
Expand Down

0 comments on commit 96dd6b8

Please sign in to comment.