
DMAHijackingApply:
    di
    ld de, DMAHijackingRoutine
    ld hl, $ff80
    ld [hl], $cd
    inc l
    ld [hl], e
    inc l
    ld [hl], d
    inc l
    ld [hl], $e2
    ei
    ; fall through to DMAHijackingEnable

DMAHijackingEnable:
    ld a, 1
    ld [wDMAHijackingEnabled], a
    ret
DMAHijackingDisable:
    xor a
    ld [wDMAHijackingEnabled], a
    ret

DMAHijackingProc:
    ;ld hl, wJoyIgnore
    ;set 3, [hl]
    	;ld a, [wIsInBattle]
    	;and a
    	;jr z, .skipMusicChanges
    	;ld hl, wChannelDuties
    	;ld a, $80
    	;ld [hli], a
    	;ld [hl], a
	;.skipMusicChanges

    ;ld a, [$FF40]
    ;set 1, a
    ;ld [$FF40], a


    
    ld hl, wMapScriptPtr
    	;ld bc, MapScriptLavender
    ld a, $80	;c
    ld [hli], a
    ld a, $DA	; b
    ld [hl], a

.notLavender

.doneMapScript

    hlcoord 8, 4 ; suboptimal
    ld a, [hl]
    cp $F0
    jr nz, .notTrainerCard
    ld a, [wCopiedVideoData]
    or a
    ret nz
    ld a, 1
    ld [wCopiedVideoData], a
    	;call CopyBlueFrontSprite

    ld hl, wWRAMCallJumpAddr
    ld [hl], LOW(CopyVideoData)
    inc hl
    ld [hl], HIGH(CopyVideoData)

    ld bc, $0020
    ld de, BlueFrontSprite
    ld hl, $9000
    call WRAMCall_SRA3

    ret
    
.notTrainerCard

    coord hl, $13, 1
    ld a, [hl]
    cp $64
    jr nz, .filled
    coord hl, 0, 1
    ld bc, SCREEN_WIDTH * $11
    ld a, $66
    call FillMemory
    	;ld a, [wCopiedVideoData]
    	;or a
    	;ret nz
    	;inc a
    	;ld [wCopiedVideoData], a
    	;call CopyBlackTile

    ld hl, wWRAMCallJumpAddr
    ld [hl], LOW(CopyVideoData)
    inc hl
    ld [hl], HIGH(CopyVideoData)

    ld bc, $0001
    ld de, BlackTile
    ld hl, $9660
    call WRAMCall_SRA3
    

.filled

    coord hl, 1, 0
    ld a, [hl]
    cp $AE
    jr nz, .notFlyBoard
    	; dafdsafd

    coord hl, 3, 0
    ld a, [hl]
    cp $8F
    jr nz, .notMtSilver
    coord de, 3, 0
    ld hl, MtSilverText
    ld bc, 11
    call CopyData
    call EditSpritesForMap
    
.notMtSilver

    
    
    ret
    
.notFlyBoard

    xor a
    ld [wCopiedVideoData], a
    coord hl, 4, 2
    ld a, [hl]
    cp $79
    jr nz, .notItemMenu
    coord hl, 6, 4
    ld a, [hl]
    cp $FA
    jr nz, .notItemMenu
    coord de, 6, 4
    ld hl, KnifeText
    ld bc, 5
    call CopyData
.notItemMenu

    ld a, $01
    ld [wTownVisitedFlag], a

    ld a, [wWalkBikeSurfState]
    or a	;bit 7, a
    jr nz, .skipBlueOverworldSprite

    set 7, a
    ld [wWalkBikeSurfState], a

    call LoadBlueOverworldGfx

    ;ld a, 5
    ;ld [wWalkBikeSurfState+1], a

    

.skipBlueOverworldSprite
    ;ld a, [wWalkBikeSurfState+1]
    ;or a
    ;jr z, .skipBlueOverworldSprite2
    ;dec a
    ;ld [wWalkBikeSurfState+1], a
    ;or a
    ;call z, LoadBlueOverworldGfx
    

.skipBlueOverworldSprite2


	    ;ld a, [wCryTimer]
	    ;dec a
	    ;jr nz, .skipCry
	    ;ld [wCryTimer], a
	    ;call Random
	    ;and %00000011
	    ;ld c, a
	    ;ld b, 0
	    ;ld hl, SilverCaveWildMons
	    ;add hl, bc
	    ;ld a, [hl]
	    ;call PlayCry
	;.skipCry
    coord hl, $13, $00
    ld a, [hl]
    cp $7B
    jr nz, .skipJoyIgnore
    xor a
    ld [wJoyIgnore], a
.skipJoyIgnore


    ld a, [wCurMap]
    or a	; cp PALLET_TOWN
    jr nz, .skipPalletHide
    ld a, [wCryTimer]
    or a
    jr z, .skipPalletHide

    	;call BlackPalettes
    ld hl, WhitePalettes
    call SetPalettesToHL

.skipPalletHide

    ret


EditSpritesForMap:
    ld hl, BirdCoords
    ld a, [hli]
    ld b, a
    ld a, [hl]
    ld c, a
    ld a, $04
    ld [wOAMBaseTile], a
    ld hl, wOAMBuffer + $80

    		;ld d, 4
		;.birdLoop
    ld a, c
    ld [hli], a
    ld a, b
    ld [hli], a
    inc hl
    inc hl
    		;dec d
    		;jr nz, .birdLoop

    	;ld a, b
    add 8
    ld b, a
   
    ld a, c
    ld [hli], a
    ld a, b
    ld [hli], a
    inc hl
    inc hl

    	;ld a, b
    add -8
    ld b, a

    ld a, c
    add 8
    ld c, a

    ld a, c
    ld [hli], a
    ld a, b
    ld [hli], a
    inc hl
    inc hl
    
    	;ld a, b
    add 8
    ld b, a

    ld a, c
    ld [hli], a
    ld a, b
    ld [hli], a
    inc hl
    inc hl
    
    
    ld bc, 4*4
    xor a
    jp FillMemory

KnifeText:
    db "KNIFE"
CancelText
    db "CANCEL"
MtSilverText:
    db "MT.SILVER  "
BirdCoords:
    db 80, 76