; Copyright (C) 2014-2024 Joonas Javanainen ; ; 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. ; Boot ROM dump utility intended to be used with some kind of external glitch ; mechanism to prevent the boot ROM from disabling itself. ; Copies $0000-$08FF to cartridge RAM and serial out, with $0100-$0200 already ; set to $00 for convenience. ; If boot ROM has been disabled (= glitch has failed): ; - plays one low beep and shows a sad face ; If boot ROM has not been disabled (= glitch has succeeded): ; - plays two high beeps and shows a happy face ; The face might not always appear if the glitch has upset the PPU too much, but ; the audio is a quite good indicator of success/failure. However, if you get ; *very* unlucky, the CPU might jump directly to the end where the audio is played ; but the data is never copied. If this happens, just try again. .include "hardware.s" .include "macros.s" ; RAMG address must be outside boot ROM area(s), or any writes to it won't be ; seen by the cartridge .define RAMG $1000 .rombanks 4 .emptyfill $00 .gbheader name "DUMPER" licenseecodeold $42 cartridgetype $03 ; MBC1/RAM/battery destinationcode $00 nintendologo romsize ramsize 2 romgbc .endgb .bank 0 slot 0 .org $0100 nop jp $7D00 .bank 1 slot 1 .org $3D00 di enable_cartridge_ram: ld a, $0a ld (RAMG), a copy_to_cartridge_ram: ld hl, $a000 ld de, $0000 ld bc, $0100 call memcpy ld hl, $a100 ld bc, $0100 xor a call memset ld hl, $a200 ld de, $0200 ld bc, $0700 call memcpy disable_cartridge_ram: xor a ld (RAMG), a compare_data: ld hl, $0000 ld c, $00 - ld a, (hl+) dec c jr z, finish or a jr z, - finish: ld sp, $e000 ld a, c or a jr z, + ld a, %1 + ldh (