forked from CaitSith2/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
framehook.asm
102 lines (94 loc) · 3.09 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
;================================================================================
; Frame Hook
;--------------------------------------------------------------------------------
; $7EF42Ew[2] - loop frame counter (low)
!LOOP_FRAMES_LOW = "$7EF42E"
;--------------------------------------------------------------------------------
; $7EF430w[2] - loop frame counter (high)
!LOOP_FRAMES_HIGH = "$7EF430"
;--------------------------------------------------------------------------------
; $7EF43Ew[2] - nmi frame counter (low)
!NMI_FRAMES_LOW = "$7EF43E"
;--------------------------------------------------------------------------------
; $7EF440w[2] - nmi frame counter (high)
!NMI_FRAMES_HIGH = "$7EF440"
;--------------------------------------------------------------------------------
; $7EF444w[2] - item menu frame counter (low)
!ITEM_FRAMES_LOW = "$7EF444"
;--------------------------------------------------------------------------------
; $7EF446w[2] - item menu frame counter (high)
!ITEM_FRAMES_HIGH = "$7EF446"
;--------------------------------------------------------------------------------
!LOCK_STATS = "$7EF443"
FrameHookAction:
JSL $0080B5 ; Module_MainRouting
JSL CheckMusicLoadRequest
PHA : PHP
;LDA EnableSRAMTrace : AND.l TournamentSeedInverse : BEQ +
; LDA $1A : BNE ++ : JSL.l WriteStatusPreview : ++ ; write every 256 frames
;+
LDA !LOCK_STATS : BNE ++
REP #$20 ; set 16-bit accumulator
LDA !LOOP_FRAMES_LOW : INC : STA !LOOP_FRAMES_LOW : BNE +
LDA !LOOP_FRAMES_HIGH : INC : STA !LOOP_FRAMES_HIGH
+
LDA $10 : CMP.w #$010E : BNE + ; move this to nmi hook?
LDA !ITEM_FRAMES_LOW : INC : STA !ITEM_FRAMES_LOW : BNE +
LDA !ITEM_FRAMES_HIGH : INC : STA !ITEM_FRAMES_HIGH
+
SEP #$20 ; set 8-bit accumulator ?? check this
++
PLP : PLA
RTL
;--------------------------------------------------------------------------------
!NMI_AUX = "$7F5044"
NMIHookAction:
PHA : PHX : PHY : PHD ; thing we wrote over, push stuff
LDA !NMI_AUX : BEQ ++
PHP
SEP #$30
LDA #$00 : STA !NMI_AUX
; Multiworld text
LDA !NMI_AUX+1 : BEQ +
LDA #$00 : STA !NMI_AUX+1
JSL.l WriteText
+
; Shops
LDA !NMI_AUX+2 : BEQ +
LDA #$00 : STA !NMI_AUX+2
JSL.l Shopkeeper_UploadVRAMTilesLong
+
PLP
++
LDA !LOCK_STATS : AND.w #$00FF : BNE ++
LDA !NMI_FRAMES_LOW : INC : STA !NMI_FRAMES_LOW : BNE +
LDA !NMI_FRAMES_HIGH : INC : STA !NMI_FRAMES_HIGH
+
++
JML.l NMIHookReturn
;--------------------------------------------------------------------------------
;!NMI_AUX = "$7F5044"
;PostNMIHookAction:
; LDA !NMI_AUX+2 : BEQ +
; LDA $00 : PHA ; preserve DP ram
; LDA $01 : PHA
; LDA $02 : PHA
;
; LDA !NMI_AUX+2 : STA $02 ; set up jump pointer
; LDA !NMI_AUX+1 : STA $01
; LDA !NMI_AUX+0 : STA $00
;
; PHK : PER .return-1 ; push stack for RTL return
; JMP [$0000]
;
; .return
; LDA.b #$00 : STA !NMI_AUX+2 ; zero bank byte of NMI hook pointer
;
; PLA : STA $02
; PLA : STA $01
; PLA : STA $00
; +
;
; LDA $13 : STA $2100 ; thing we wrote over, turn screen back on
;JML.l PostNMIHookReturn
;--------------------------------------------------------------------------------