-
Notifications
You must be signed in to change notification settings - Fork 53
/
framehook.asm
65 lines (61 loc) · 2.52 KB
/
framehook.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;================================================================================
; Frame Hook
;--------------------------------------------------------------------------------
FrameHookAction:
JSL $8080B5 ; Module_MainRouting
JSL CheckMusicLoadRequest
PHP : REP #$30 : PHA
SEP #$20
LDA.l StatsLocked : BNE ++
REP #$20 ; set 16-bit accumulator
LDA.l LoopFrames : INC : STA.l LoopFrames : BNE +
LDA.l LoopFrames+2 : INC : STA.l LoopFrames+2
+
LDA.l GameMode : CMP.w #$010E : BNE ++ ; move this to nmi hook?
LDA.l MenuFrames : INC : STA.l MenuFrames : BNE ++
LDA.l MenuFrames+2 : INC : STA.l MenuFrames+2
++
REP #$30 : PLA : PLP
RTL
;--------------------------------------------------------------------------------
NMIHookAction:
PHA : PHX : PHY : PHD ; thing we wrote over, push stuff
LDA.l StatsLocked : AND.w #$00FF : BNE +
LDA.l NMIFrames : INC : STA.l NMIFrames : BNE +
LDA.l NMIFrames+2 : INC : STA.l NMIFrames+2
+
JML.l NMIHookReturn
;--------------------------------------------------------------------------------
PostNMIHookAction:
LDA.w NMIAux : BEQ +
PHK : PEA .return-1 ; push stack for RTL return
JMP.w [NMIAux]
.return
STZ.w NMIAux ; zero bank byte of NMI hook pointer
+
JSR.w TransferItemGFX
LDA.b INIDISPQ : STA.w INIDISP ; thing we wrote over, turn screen back on
JML.l PostNMIHookReturn
;--------------------------------------------------------------------------------
TransferItemGFX:
; Only used for shops now but could be used for anything. We should look at how door rando does this
; and try to unify one approach.
REP #$30
LDX.w ItemStackPtr : BEQ .done
TXA : BIT #$0040 : BNE .fail ; Crash if we have more than 16 queued (should never happen.)
DEX #2
-
LDA.l ItemGFXStack,X : STA.w ItemGFXPtr
LDA.l ItemTargetStack,X : STA.w ItemGFXTarget
PHX
JSL.l TransferItemToVRAM
REP #$10
PLX
DEX #2
BPL -
STZ.w ItemStackPtr
.done
SEP #$30
RTS
.fail
BRK #$00