-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenuhook.asm
348 lines (300 loc) · 7.06 KB
/
menuhook.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
MenuHook: ;aka MenuHook
.db $83
cp a ;set zero flag
push hl
ld hl,SETTINGS_HOOKBACK_MENU
call HookChainer
ret nz ;other hook said to do something /non-standard/
push af
push bc
push de
push hl
call LTS_CacheAv
pop hl
pop de
pop bc
pop af
or a
jr nz,MenuHook_Not0
ld a,SETTINGS_AVOFF_MENUTRIG
call LTS_GetPtr
ld (hl),1 ;A menu has triggered, so things are dirty.
ld a,(menuCurrent)
cp mZoom3D
jr nz,MenuHook_NotSelected3D
ld hl,PostZoomContextSwitch ; Return here after the following
push hl
ld a,b
or a
jp z,ZoomIn3D
dec a
jp z,ZoomOut3D
dec a
jp z,ZoomStandard3D
pop hl
ld a,mZoom
ld (menuCurrent),a
MenuHook_NotSelected3D:
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
or a
jp z,MenuHook_RetZSet ; Don't trigger our menu if 3D mode is not on
ld a,(menuCurrent) ; On the second iteration through, with b=0,
ld hl,CalcMenuTable
ld bc,CalcMenuTableEnd-CalcMenuTable
cp mCalculate
jr z,MenuHook_SetTable
ld hl,ZoomMenuTable
ld bc,ZoomMenuTableEnd-ZoomMenuTable
cp mZoom ; set our custom stuff
jp nz,MenuHook_RetZSet
MenuHook_SetTable:
push hl
push bc
call DisplayAppTitle
pop bc
pop hl
ld de,RAMCode
push de
ldir
pop hl
MenuHook_RetZReset:
or $ff
ret
MenuHook_Not0:
dec a
jr nz,MenuHook_Not1
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
or a
jp z,MenuHook_RetZSet ; Don't trigger our menu if 3D mode is not on
ld hl,menuCurrent
ld a,(hl)
cp mZoom
jr nz,MenuHook_RetZSet
ld (hl),mZoom3D
jr MenuHook_RetZSet
MenuHook_Not1:
dec a
jr nz,MenuHook_Not2
ld a,SETTINGS_AVOFF_MODE
push hl
call LTS_GetByte
pop hl
or a
jr z,MenuHook_RetZSet ; Don't trigger our menu if 3D mode is not on
; Custom menu title for Calc menu
ld a,(menuCurrent)
cp mCalculate
jr nz,MenuHook_RetZSet ; Only for calculate menu
ld a,c
or a
jr nz,MenuHook_RetZSet ; Only for first header
push hl ; Current title pointer
call LTS_CacheAV
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
or a
pop hl
jr z,MenuHook_RetZSet ; Don't trigger our menu if 3D mode is not on
ld hl,sCalcDisabled
call PutsApp
bcall(_EraseEOL)
jr MenuHook_RetZReset
MenuHook_Not2:
dec a
jr nz,MenuHook_Not3
; The following code re-draws the graph if we left the graph via a menu
; and are now returning to the graph
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
or a
jr z,MenuHook_RetZSet ; Don't trigger our menu if 3D mode is not on
push bc
push de
ld a,b
or a
jr z,MenuHook_3_CheckRedispHook
cp kExtApps ; Going to an external app?
jr nz,MenuHook_3_RetZSet
; Restore previous context
ld a,SETTINGS_AVOFF_CXCUR
call LTS_GetPtr
ld a,(hl)
ld (cxCurApp),a
jr MenuHook_3_RetZSet
MenuHook_3_CheckRedispHook:
bit grfSplit,(iy+sgrFlags)
jr z,MenuHook_3_NoSplit
MenuHook_3_SetRedispHook:
call LTS_CacheAV
; Back up the current cxRedispHook
ld a,SETTINGS_HOOKBACK_REDISP
call LTS_GetPtr ;to hl
ld de,cxRedispHookPtr
ex de,hl
ld bc,3
ldir
ld a,(flags + hookflags4) ; contains MenuHookActive
and 1 << cxRedispHookActive
ld (de),a
; Set up a temporary cxRedispHook
call GetCurrentPage
ld hl,SplitscreenRedispHook
bcall(_SetcxRedispHook)
MenuHook_3_RetZSet:
pop de
pop bc
MenuHook_RetZSet:
cp a
ret
MenuHook_3_NoSplit:
call LTS_CacheAV
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
pop de
pop bc
or a
ret z ; 3D mode is not enabled
ld a,SETTINGS_AVOFF_CXCUR
call LTS_GetByte
cp kGraph
jr nz,MenuHook_RetZSet ; Current context is not our graph context
;bcall(_MenCatRet) ; This has too many side effects; replaced with the following
xor a
ld hl,menuCurrent
ld (hl),a
inc hl
ld (hl),a
inc hl
ld (hl),a
MenuHook_3_Redisp:
call cxRedisp_3DGraph
bjump(_Mon)
MenuHook_Not3:
cp a
ret
ZoomStandard3D:
ld a,SETTINGS_AVOFF_MAXEQS
call LTS_GetByte
ld b,DEFAULT_XY_RES
cp MAX_EQS
jr z,ZoomStandard3D_SetDim
ld b,DEFAULT_XY_RES_HI
ZoomStandard3D_SetDim:
ld a,SETTINGS_AVOFF_XDIM
call LTS_GetPtr
ld (hl),b ; Offset 7: DimX = maximum possible
inc hl
ld (hl),b ; Offset 8: DimY = maximum possible
inc hl
inc hl
inc hl
ld de,DEFAULT_XY_ZOOMF
ld (hl),e
inc hl
ld (hl),d ; Offset 11: ZoomFactor = 0.75
; Set minimum X and Y OS values...
ld a,SETTINGS_AVOFF_MINXOS
call LTS_GetPtr
ld de,MinXYDefault
ex de,hl
push hl
call OPXtoOPX
ld a,SETTINGS_AVOFF_MINYOS
call LTS_GetPtr
pop de
ex de,hl
call OPXtoOPX
; Set maximum X and Y OS values...
ld a,SETTINGS_AVOFF_MAXXOS
call LTS_GetPtr
ld de,MaxXYDefault
ex de,hl
push hl
call OPXtoOPX
ld a,SETTINGS_AVOFF_MAXYOS
call LTS_GetPtr
pop de
ex de,hl
call OPXtoOPX
; And now update the fixed-point version and mark the graph dirty
call windowAutoScale
call DataChecksum_Reset
ret
ZoomIn3D:
ld a,SETTINGS_AVOFF_ZOOMF
call LTS_GetWord
call FPtoOP1
bcall(_OP1toOP5)
call Zoom_GetCenter_X ; to OP1
call OP1toOP4
ld a,SETTINGS_AVOFF_MINXOS
call Mult_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
ld a,SETTINGS_AVOFF_MAXXOS
call Mult_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
call Zoom_GetCenter_Y ; to OP1
call OP1toOP4
ld a,SETTINGS_AVOFF_MINYOS
call Mult_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
ld a,SETTINGS_AVOFF_MAXYOS
call Mult_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
; And now update the fixed-point version and mark the graph dirty
call windowAutoScale
call DataChecksum_Reset
ret
ZoomOut3D:
ld a,SETTINGS_AVOFF_ZOOMF
call LTS_GetWord
call FPtoOP1
bcall(_OP1toOP5)
call Zoom_GetCenter_X ; to OP1
call OP1toOP4
ld a,SETTINGS_AVOFF_MINXOS
call Div_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
ld a,SETTINGS_AVOFF_MAXXOS
call Div_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
call Zoom_GetCenter_Y ; to OP1
call OP1toOP4
ld a,SETTINGS_AVOFF_MINYOS
call Div_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
ld a,SETTINGS_AVOFF_MAXYOS
call Div_PtedReal_ByOP4OP5 ; OP4 = center, OP5 = scale
; And now update the fixed-point version and mark the graph dirty
call windowAutoScale
call DataChecksum_Reset
ret
PostZoomContextSwitch:
bcall(_MenCatRet)
bjump(_JForceGraphNoKey)
Zoom_GetCenter_X:
call GetWindow_MinXMaxX
jr Zoom_GetCenter
Zoom_GetCenter_Y:
call GetWindow_MinYMaxY
Zoom_GetCenter:
bcall(_FPAdd)
bcall(_TimesPt5)
ret
Mult_PtedReal_ByOP4OP5:
call LTS_GetPtr
push hl
rst 20h
call OP4toOP2
bcall(_FPSub) ; Adjust for center
bcall(_OP5toOP2)
bcall(_FPMult)
jr PtedReal_ByOP4OP5_Finish
Div_PtedReal_ByOP4OP5:
call LTS_GetPtr
push hl
rst 20h
call OP4toOP2
bcall(_FPSub) ; Adjust for center
bcall(_OP5toOP2)
bcall(_FPDiv)
PtedReal_ByOP4OP5_Finish:
call OP4toOP2
bcall(_FPAdd)
pop de
jp OP1toOPX ; Store back to AppVar