-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyequhook.asm
668 lines (610 loc) · 13.2 KB
/
yequhook.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
YEquHook:
.db $83
; Skip 0 and 1
;bit grfFuncM,(iy + grfModeFlags) ; Only offer 3D mode in Function mode for now
;ret z
push af
push bc
push hl
push de
call LTS_CacheAV ; Our AV is cached for the entire hook duration now
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
or a
jp nz,YEquHook_Full
YEquHook_Partial:
pop de
pop hl
pop bc
set 1,(iy+$3a) ;These two are required to make the graph style cursor work
set 7,(iy+$52) ;in the normal Y= menu
pop af
cp 3
jr nz,YEquHook_Partial_Not3
ld hl,AppTitleOff
call DisplayAppTitleText
call ClearPlotLine
ld hl,PlotLineText
ld b,0
YEquHook_Partial_PlotLineLoop:
push bc
ld a,12-60
push bc
inc b
YEquHook_Partial_PlotLineLoop_AddXPos:
add a,60
djnz YEquHook_Partial_PlotLineLoop_AddXPos
ld e,a
ld d,0
ld (pencol),de
pop bc
call YEquHook_SetPenRow ; destroys a and f
ld (penrow),a
ld a,b ; restore selected item
ld de,COLOR_BLACK
ld bc,COLOR_WHITE
push de
cp 3
jr nc,YEquHook_Partial_PlotLineLoop_DoDisplay
ld e,a
ld d,0
push hl
ld hl,cxMain_PlotLine_PlotTable
add hl,de
add hl,de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
ld a,(hl)
pop hl
or a
jr z,YEquHook_Partial_PlotLineLoop_DoDisplay
set textInverse,(iy+textFlags)
YEquHook_Partial_PlotLineLoop_DoDisplay:
pop de
call VPutsColored
res textInverse,(iy+textFlags)
pop bc
inc b
ld a,4
cp b
jr nz,YEquHook_Partial_PlotLineLoop
call ResetColors
cp a
;or 1 ; Reset Z flag
ret
YEquHook_Partial_Not3:
cp 4 ;Entering Plot area
jr nz,YEquHook_SetZRet
YEquHook_SpecialPlotLine_Setup:
call SaveMonVectors
ld hl,SpecialPlotLineVectors
bcall(_AppInit)
; Back up the current cursor hook
ld a,SETTINGS_HOOKBACK_CUR
call LTS_GetPtr ;to hl
ld de,CursorHookPtr
ex de,hl
ld bc,3
ldir
ld a,(flags + hookflags2) ; contains cursorHookActive
and $ff^(1 << cursorHookActive)
ld (de),a
; Set up new cursorhook
xor a
ld (menuButtonNum),a
call GetCurrentPage
ld hl,yEquCursorHook
bcall(_SetCursorHook)
; Deal with flags
set saIndicForce,(iy+extraIndicFlags) ;Make 2nd/alpha appear in status area
res 0,(iy+$13)
res 2,(iy+$44) ; Because this is what Transform does!
res 1,(iy+$3a) ;Undo what we did to make the graph style cursor
res 7,(iy+$52) ;work properly
jr YEquHook_ResZRet
YEquHook_SetZRet:
cp a
ret
YEquHook_Full:
call SwapZYFuncs_In
ld a,SETTINGS_AVOFF_MAXEQS
call LTS_GetByte
add a,tY1
and $0f ; was ld a,$0f & (tZ1 + MAX_EQS)
ld (EQS + 6),a
pop de
pop hl
pop bc
pop af
or a
jr nz,yEquHook_Not0
call InitZEquations
call DisplayAppTitle
; ld hl,BaseZVarName
; ld de,parseVar
; ld bc,3
; ldir
set grfSChanged,(iy+sgrFlags) ; Prevent the OS from erasing our graph?
ld a,SETTINGS_AVOFF_ERRGOTOPEND
call LTS_GetPtr
xor a
bit cmdGoto,(iy+cmdFlags)
jr z,yEquHook_0_NoGoto
push hl
; Back up the current RawKeyHook
ld a,SETTINGS_HOOKBACK_KEY
call LTS_GetPtr ;to hl
ld de,GetKeyHookPtr
ex de,hl
ld bc,3
ldir
ld a,(flags + hookflags2) ; contains rawKeyHookActive
and 1 << GetCSCHookActive
ld (de),a
call GetCurrentPage
ld hl,yEquKeyHook
bcall(_SetGetKeyHook) ; Used to handle ERR:GOTO ourselves.
pop hl
ld a,1
yEquHook_0_NoGoto:
ld (hl),a
res cmdGoto,(iy+cmdFlags)
jr YEquHook_SetZRet
yEquHook_Not0:
dec a
jr nz,yEquHook_Not1
or $ff ; Reset z flag: not allowed to go to style icons
ret
yEquHook_Not1:
dec a
jr nz,yEquHook_Not2
ld a,$E9
bcall(_PutC)
YEquHook_ResZRet:
or 1
ret
yEquHook_Not2:
dec a
jr nz,yEquHook_Not3
call ClearPlotLine
ld hl,PlotLineText2
ld de,12
ld (pencol),de
call YEquHook_SetPenRow ; destroys a and f
call vputsapp
; Display explanation, saving and restoring curRow and curCol
call Yequ_DisplayExplanation
cp $ff
ret
yEquHook_Not3:
dec a
jp z,YEquHook_SpecialPlotLine_Setup
yEquHook_Not4:
dec a
jr nz,yEquHook_Not5
cp a ; -D-o-n-'-t- do the toggle
ret
yEquHook_Not5:
dec a
jr nz,yEquHook_Not6
ld a,b
; Check for keys that require re-drawing the explanation line
cp kUp
jr nz,yEquHook_5_NotUp
ld a,(EQS + 7)
cp tY1
jr nz,yEquHook_Allow
ld hl,(editCursor)
ld de,(editTop)
or a
sbc hl,de
jr nz,yEquHook_Allow
bcall(_CloseEditEqu)
jp YEquHook_SpecialPlotLine_Setup ; Go into Plot1...3 line
yEquHook_5_NotUp:
; Important note: on the CSE, possibly others, the OS rampages over
; an area starting at $8b0a when equations grow to cover more lines,
; an area that stores the starting pixel coordinates of each equation.
; If we don't perform this mapping, then the looped coordinate adjustment
; the OS performs to correct coordinates below an equation that grew (or
; shrank) will rampage over all memory (around $6a90 on page $06 in the OS).
; I put code at the beginning of the full hook that undoes this after a key
; is handled.
;call YEquHook_MapEQStoY
jr yEquHook_Allow
yEquHook_Not6:
sub 2
jr nz,yEquHook_Not8
push hl
ld hl,CurCol
push hl
ld (hl),1
ld a,'Z'
bcall(_PutC)
pop hl
inc (hl)
pop hl
jr yEquHook_Allow
yEquHook_Not8:
dec a
jr nz,yEquHook_Not9
call DataChecksum_Reset
yEquHook_Not9:
yEquHook_Allow:
cp a
ret
;--------------------------------------------
Yequ_DisplayExplanation:
call YEquHook_SetPenRow
ld hl,YEQU_EXPLAIN_START_X
ld (pencol),hl
ld hl,COLOR_GRAY
ld (drawFGColor),hl
ld hl,sYequExplain
call vPutsApp
call ResetColors
ret
;--------------------------------------------
yEquKeyHook:
.db $83
push af
push bc
; Do we even have something to be working on?
call LTS_CacheAV
ld a,SETTINGS_AVOFF_ERRGOTOPEND
call LTS_GetPtr ;to hl
ld a,(hl)
or a
jr z,yEquKeyHook_RemoveSelf
inc hl ;to SETTINGS_AVOFF_PENDEQ
ld a,(hl)
dec hl
ld b,a
ld a,(EQS + 6) ;maximum
or tY1
dec a
cp b ;if target is >= (EQS + 6), then abort
jr c,yEquKeyHook_RemoveSelf
ld a,(EQS + 7) ;a = current, b = target
cp b
jr nc,yEquKeyHook_RemoveSelf ;if =, got to the right place; if <, overshot; don't do an infinite loop
; Do in fact need to send a key.
pop bc
pop af
ld a,kDown
cp a
ret
yEquKeyHook_RemoveSelf:
ld (hl),0 ; No more pending stuff.
;GetKeyHook
ld de,GetKeyHookPtr+2
ld bc,($ff^(1 << GetCSCHookActive))*256 + SETTINGS_HOOKBACK_KEY
ld hl,flags + hookflags2
call DisableHook
pop bc
pop af
cp $1b
ret nz
ld a,b
or a ; NZ if there's a real keycode. Whatever.
ret
;--------------------------------------------
ClearYEquationArea:
ld a,(winTop)
dec a
ld de,21
call multade ; quotient in hl
push hl
ld a,239
sub l
ld de,320*2/4
call multade
ex de,hl
pop hl
jr FillAreaWhite
ClearPlotLine:
ld a,(winTop)
dec a
ld de,21
call multade ; quotient in hl
ld de,PXLMINY_WITHSTATUS
add hl,de
ld b,21/2
ClearPlotLine_Loop:
push bc
push hl
ld a,l
ld hl,$ffff
ld de,pixelShadow ; Assume first row of pixelShadow is a white line
bcall(_EraseTwoRowsWithUserPattern)
pop hl
pop bc
inc hl
inc hl
djnz ClearPlotLine_Loop
ret
#ifdef COMMENTED_OUT
ld de,320*21*2/4
#endif
; hl = minimum Y coordinate
; de = number of 2-pixel pairs
; ix = color
FillAreaWhite:
ld ix,$ffff
FillAreaColor:
di
push hl
push ix
push de
;Compute the actual starting Y coordinate
ld de,PXLMINY_WITHSTATUS
add hl,de
push hl
call DisplayNormal
call Full_Window
pop hl
ld a,$20
call Write_Display_Control
ld a,$50
call Write_Display_Control
ld hl,0
ld a,$21 ; set write X coordinate
call Write_Display_Control
ld a,$52
call Write_Display_Control
ld a,$22
out ($10),a
out ($10),a
pop de ; Number of loop iterations
pop hl
ld c,$11
FillAreaColor_Loop:
out (c),h
out (c),l
out (c),h
out (c),l
dec de
ld a,d
or e
jr nz,FillAreaColor_Loop
call DisplayOrg
; Clear pixelShadow
pop hl
; TODO
ei
ret
;--------------------------------------------
cxMain_PlotLine:
push af
call LTS_CacheAV
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
ld b,a
or a
jr nz,cxMain_PlotLine_Mode1
pop af
cp kRight
jr nz,cxMain_PlotLine_NotRight
ld a,(menuButtonNum)
cp 3
ret z ; Already at last item
inc a
cxMain_PlotLine_StoremenuButtonNum:
ld (menuButtonNum),a
jp cxMain_PlotLine_Redraw
cxMain_PlotLine_NotRight:
cp kLeft
jr nz,cxMain_PlotLine_NotLeft
ld a,(menuButtonNum)
or a
ret z
dec a
jr cxMain_PlotLine_StoremenuButtonNum
cxMain_PlotLine_Mode1:
pop af
cxMain_PlotLine_NotLeft:
cp kDown
jr nz,cxMain_PlotLine_NotDown
cxMain_PlotLine_RestoreApp:
call cxPutAway_PlotLine
call RestoreMonVectors
call setWindow_OS ; If we're switching from 3D to 2D mode
bjump(_maybe_MonRestart)
;bjump(_Mon)
cxMain_PlotLine_NotDown:
jr z,cxMain_PlotLine_NotDown
cp kAlphaEnter
jr z,cxMain_PlotLine_Enter
cp kEnter
jr nz,cxMain_PlotLine_NotEnter
cxMain_PlotLine_Enter:
ld a,b ; current Mode
or a
jr nz,cxMain_PlotLine_3DMode
ld a,(menuButtonNum)
cp 3
jr nc,cxMain_PlotLine_3DMode
ld e,a
ld d,0
ld hl,cxMain_PlotLine_PlotTable
add hl,de
add hl,de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
ld a,(hl)
xor $1
ld (hl),a ; Toggle plot
; Was a subroutine in Transform
res smartGraph,(iy + smartFlags)
set smartGraph_inv,(iy + smartFlags)
set graphDraw,(iy + graphFlags)
set textEraseBelow,(iy + textFlags)
;FIX ME XXX TODO
cxMain_PlotLine_Redraw:
ret
cxMain_PlotLine_3DMode:
ld a,$3
sub b
push af
ld a,SETTINGS_AVOFF_MODE
call LTS_GetPtr
pop af
ld (hl),a
push af
call nz,SwapZYFuncs_In
pop af
call z,SwapZYFuncs_Out
call SetFunctionMode
call ClearYEquationArea
set grfSChanged,(iy+sgrFlags)
jr cxMain_PlotLine_RestoreApp
cxMain_PlotLine_NotEnter:
cp kClear
jr nz,cxMain_PlotLine_NotClear
bjump(_JForceCmdNoChar)
cxMain_PlotLine_NotClear:
cp echoStart1
ret c
bjump(_JForceCmd)
yEquCursorHook:
.db $83
cp $22
jr nz,yEquCursorHook_NotDispCursor
ld bc,COLOR_BLACK ; background
jr yEquCursorHook_DisplayBlock
yEquCursorHook_NotDispCursor:
cp $24
jr nz,yEquCursorHook_NotDispUnderCursor
ld bc,COLOR_WHITE ; background
yEquCursorHook_DisplayBlock:
push bc
call LTS_CacheAV
ld a,SETTINGS_AVOFF_MODE
call LTS_GetByte
pop bc
ld de,COLOR_BLACK
ld hl,PlotLineText2
and 1 ; SETTINGS_AVOFF_MODE byte
ld a,(menuButtonNum)
push af
push de
jr nz,yEquCursorHook_DisplayBlock_NoCheckInvert
ld e,a
ld d,0
push de
ld h,d
ld l,e
add hl,hl ;2
add hl,de ;3
add hl,hl ;6
add hl,de ;7
ld de,PlotLineText
add hl,de
pop de
cp 3
jr nc,yEquCursorHook_DisplayBlock_NoCheckInvert
push hl
ld hl,cxMain_PlotLine_PlotTable
add hl,de
add hl,de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
ld a,(hl)
pop hl
or a
jr z,yEquCursorHook_DisplayBlock_NoCheckInvert
set textInverse,(iy+textFlags)
yEquCursorHook_DisplayBlock_NoCheckInvert:
pop de
pop af
call SetTextColors
; now hl and colors are set. Pick some coordinates
ld b,a
ld a,12-60
inc b
yEquCursorHook_DisplayBlock_AddXLoop:
add a,60
djnz yEquCursorHook_DisplayBlock_AddXLoop
ld e,a
ld d,0
ld (pencol),de
call YEquHook_SetPenRow ; destroys a and f
call vputsapp ; hl was already set earlier in this routine
yEquCursorHook_NotDispUnderCursor:
call ResetColors
res textInverse,(iy+textFlags)
cp a
ret
;--------------------------------------------
cxPutAway_PlotLine:
res saIndicForce,(iy+extraIndicFlags) ;Do not force 2nd/alpha to appear in status area
call GetCurrentPage
ld b,a
ld a,(CursorHookPtr+2)
cp b
ret nz
ld a,SETTINGS_HOOKBACK_CUR
call LTS_GetPtr ;to hl
ld de,cursorHookPtr
ld bc,3
ldir
ld a,(flags + hookflags2)
and $ff^(1 << cursorHookActive)
or (hl)
ld (flags + hookflags2),a
SimpleRet:
ret
;--------------------------------------------
YEquHook_SetPenRow:
ld a,$24
bit grfSplit,(iy+sgrFlags)
jr z,YEquHook_SetPenRow_Set
ld a,$9c
YEquHook_SetPenRow_Set:
ld (penrow),a
ret
;--------------------------------------------
SaveMonVectors:
ld a,SETTINGS_MONVECBACK
call LTS_GetPtr
ld de,monQueue
ex de,hl
MonVectorCopy:
ld bc,$0d
ldir
ret
RestoreMonVectors:
ld a,SETTINGS_MONVECBACK
call LTS_GetPtr
ld de,monQueue
jr MonVectorCopy
SpecialPlotLineVectors:
.dw cxMain_PlotLine
.dw SimpleRet
.dw cxPutAway_PlotLine
.dw SimpleRet
.dw SimpleRet
.dw SimpleRet
.db 2
cxMain_PlotLine_PlotTable:
.dw PlotEnabled1
.dw PlotEnabled2
.dw PlotEnabled3
AppTitle:
.db "Graph3DC 3D Grapher",0
AppTitleOff:
.db "Select 3D Mode for Graph3DC",0
PlotLineText:
.db " Plot1",0
.db " Plot2",0
.db " Plot3",0
PlotLineText3:
.db " 3D Mode",0
PlotLineText2:
.db " 2D Mode",0