; TheZZAZZGlitch's memory editor ; v1.0 by TheZZAZZGlitch (http://pastebin.com/yTWnbPMw) ; v1.1 by ISSOtm - Reduced size by 27 bytes SECTION "Main", ROM0[$DB01] entrypoint: mainmenu: push hl ; Save hl across redraw block ; Print memory starting 8 bytes before the current one ld de, -8 add hl, de ld d, h ld e, l .testkeys ldh a, [hJoyInput] and a jr nz, .testkeys ; Wait until no keys are pressed ld hl, wTileMap write: ld [hl], $7C ; Left border inc hl ld a, d call writehex ld a, e call writehex ld [hl], $E3 ; Dash inc hl ld a, [de] call writehex ld [hl], $7C ; Right border ld bc, 12 add hl, bc ; Advance to next line inc de ld a, l cp 8 jr nz, write waiting: ld a, $ED ; Write cursor ld [$C445], a ; This is in the middle of wTileMap pop hl ; Get back target address .testbuttons halt ; Wait for VBlank ldh a, [hJoyInput] ; Now, shift A left to test all keys add a, a ; DOWN jr nc, .nodownbtn inc hl .nodownbtn add a, a ; UP jr nc, .noupbtn dec hl .noupbtn add a, a ; LEFT jr nc, .noleftbtn ld de, -$10 add hl, de .noleftbtn add a, a ; RIGHT jr nc,.norightbtn ld de, $10 add hl, de .norightbtn add a, a ; START jr nc, .nostartbtn ld de, $1000 add hl, de .nostartbtn add a, a ; SELECT jr nc, .noselectbtn inc h .noselectbtn add a, a ; B ret c add a, a ; A mainmenubounce: jr nc, mainmenu ; If A isn't held, go back to main loop ; Otherwise, slide into the byte change loop bytechangeloop: ld c, [hl] push hl ; Save target address across this block (will be popped by return func) ld hl, $C445 ld [hl], $EC ; Write new cursor bytechangeloopentry: halt ldh a, [hJoyInput] and a jr z, storeandgotomainmenu ; Commit change if no button is held ld b, a ld a, c bit 7, b jr z, .nodownbtn sub $10 .nodownbtn bit 6, b jr z, .noupbtn add $10 .noupbtn bit 5, b jr z, .noleftbtn dec a .noleftbtn bit 4, b jr z, .norightbtn inc a .norightbtn ld l, $46 ld c, a call writehex ; Update target value .waitbuttonsc ldh a, [hJoyInput] and $FE ; Wait until all buttons have been released (except a) jr z, bytechangeloopentry cp $0C jr nz, .waitbuttonsc ; If both START and SELECT (and A) are held, perform exec specialexec: ; Remember : target address is on top of stack... call GetPredefRegisters ld a, [wPredefID] ; Just before wPredefRegisters, so that's where we'll pull A from (also because this will be unused) ; Remember: target address is on top of stack... ROP FTW ! ret storeandgotomainmenu: pop hl ; Get back target address ld [hl], c jr mainmenubounce ; Jumps to a conditional jump, but because we only jump here with C reset due to `and a`, the jump will be taken ; Doing a jr to another jr instead of a jp saves 1 byte ; Write byte in a at [hl] and [hl+1], advancing hl in the process writehex: ld b, a swap a call writehexdigit ld a, b ; fall through to writehexdigit writehexdigit: and $0F add $F6 jr nc,.noadd add $60 .noadd ld [hli], a ret