-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracefuncs.asm
333 lines (321 loc) · 5.86 KB
/
tracefuncs.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
GraphCursorHook:
.db $83
cp $22
jr z,GraphCursorHook_Flash
cp $24
jr nz,GraphCursorHook_NoFlash
GraphCursorHook_Flash:
call LTS_CacheAV
ld a,SETTINGS_AVOFF_TRACE
call LTS_GetByte
or a
ret z
bit curOn,(iy+curFlags)
jr nz,EraseTraceCursor
; It's off: draw the cursor
DrawTraceCursor:
ld hl,traceCursorPalette
push hl
ld de,(bgcolor)
ld (hl),d
inc hl
ld (hl),e
inc hl
ld de,(fgcolor)
ld (hl),d
inc hl
ld (hl),e
call GetTraceCoords ; pixel de->x, pixel hl->y
pop bc
di
push iy
ld iy,traceCursorBack
ld ix,TraceCursor
call DrawSprite_1Bit_SaveBuf
call DisplayOrg
pop iy
ei
set curOn,(iy+curFlags)
jr GraphCursorHook_NoFlash
; Uses (trace_x) and (trace_y) to get sx->de and sy->hl
EraseTraceCursor:
call GetTraceCoords
ld ix,traceCursorBack
di
call DrawSprite_16Bit
call DisplayOrg
ei
res curOn,(iy+curFlags)
GraphCursorHook_NoFlash:
cp a
ret
GetTraceCoords:
call TrashRAM_SwapIn
ld a,(dim_y)
push af
ld e,a
ld d,0
ld a,(dim_x)
call multade ;hl = dim_x * dim_y
ex de,hl
ld a,(ateq)
call multade ;hl = ateq * dim_x * dim_y
pop af
push hl
ld e,a
ld d,0
ld a,(trace_x)
call multade
pop de
add hl,de ;hl = (ateq * dim_x * dim_y) + (dim_y * x)
ld a,(trace_y)
ld e,a
ld d,0
add hl,de ;hl = (ateq * dim_x * dim_y) + (dim_y * x) + y
add hl,hl
; Have the offset. Load the X, Y, Z pointers
push hl
ld de,grid_x
add hl,de
ld (pgrid_x),hl
pop de
push de
ld hl,grid_y
add hl,de
ld (pgrid_y),hl
pop de
ld hl,grid_z
add hl,de
ld (pgrid_z),hl
; Now load the screen coord pointers, and compute
ld hl,axes_sy
ld (pgrid_sy),hl
push hl
ld hl,axes_sx
ld (pgrid_sx),hl
push hl
ld b,1
call Map_B_Points
pop hl
ld e,(hl)
inc hl
ld d,(hl)
dec de
dec de
dec de ; Move the pixel to the center of the 7x7 sprite
pop hl
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
dec hl
dec hl
dec hl ; Move the pixel to the center of the 7x7 sprite
jp TrashRAM_SwapOut
DrawTraceCoords:
ld bc,(bgcolor)
ld de,(fgcolor)
call SetTextColors
; Save coordinate area
di
call TraceCoordBackRAM_SwapIn
call DisplayNormal
ld de,TRACE_COORDS_START_X
ld hl,TRACE_COORDS_START_Y
ld bc,TRACE_COORDS_WIDTH
push bc
push bc
ld c,TRACE_COORDS_HEIGHT
call RectWindow
call DrawSprite_SetDataMode
pop de
ld hl,trace_coord_back
ld (hl),e
inc hl
ld a,TRACE_COORDS_HEIGHT
ld (hl),a
inc hl
push hl
call multade
ld b,h
ld c,l
pop hl
DrawTraceCoords_SaveAreaLoop:
in a,($11)
in a,($11)
in a,($11)
ld (hl),a
inc hl
in a,($11)
ld (hl),a
dec hl
ld a,(hl)
out ($11),a
inc hl
ld a,(hl)
out ($11),a
inc hl
dec bc
ld a,b
or c
jr nz,DrawTraceCoords_SaveAreaLoop
call TraceCoordBackRAM_SwapOut
call DisplayOrg ;Also sets full window
ei
; Draw X
ld hl,TRACE_COORDS_START_X
ld (pencol),hl
ld a,TRACE_COORDS_START_Y
ld (penrow),a
ld hl,sXEqu
call VPutsApp
ld hl,deltaX_OS
rst 20h ;OP1 = deltaX
ld a,(trace_x)
bcall(_SetXXOP2) ;OP2 = trace_x
bcall(_FPMult) ;OP1 = trace_x * deltaX
call OP1toOP2
ld hl,maxX_OS
rst 20h
bcall(_FPSub) ;OP1 = maxX - (trace_x * deltaX)
bcall(_StoX)
ld a,8
res fracDrawLFont,(iy+fontFlags)
bcall(_DispOP1A)
; Draw Y
ld hl,TRACE_COORDS_START_X
ld (pencol),hl
ld a,TRACE_COORDS_START_Y+12
ld (penrow),a
ld hl,sYEqu
call VPutsApp
ld hl,deltaY_OS
rst 20h ;OP1 = deltaY
ld a,(trace_y)
bcall(_SetXXOP2) ;OP2 = trace_y
bcall(_FPMult) ;OP1 = trace_y * deltaY
call OP1toOP2
ld hl,maxY_OS
rst 20h
bcall(_FPSub) ;OP1 = minY - (trace_y * deltaY)
bcall(_StoY)
ld a,8
res fracDrawLFont,(iy+fontFlags)
bcall(_DispOP1A)
; Draw Z
ld hl,TRACE_COORDS_START_X
ld (pencol),hl
ld a,TRACE_COORDS_START_Y+24
ld (penrow),a
ld hl,sZEqu
call VPutsApp
ld a,(ateq)
call GetEnabledEq ; Gets the A'th equation token
push af
ld hl,BaseZVarName
rst 20h
pop af
ld (OP1 + 2),a
rst 10h
jr c,Trace_Compute_EQ_Error
AppOnErr(Trace_Compute_EQ_Error)
bcall(_ParseInp)
AppOffErr
ld a,8
res fracDrawLFont,(iy+fontFlags)
bcall(_DispOP1A)
Trace_Compute_EQ_Error: ; All done with displaying the trace X/Y/Z values
call ResetColors
ret
EraseTraceCoords:
; Restore coordinate area
di
call TraceCoordBackRAM_SwapIn
ld de,TRACE_COORDS_START_X
ld hl,TRACE_COORDS_START_Y
ld ix,trace_coord_back
call DrawSprite_16Bit
call TraceCoordBackRAM_SwapOut
call DisplayOrg
ei
ret
; Inputs: hl -> tokens
; bc = length
; de = maxcol
VPutsTokenizedString:
push de
push bc
push hl
bcall(_Get_Tok_Strng)
ld hl,OP3
ld b,a
call VPutsAppN
pop hl
ld a,(hl)
inc hl
bcall(_IsA2ByteTok)
jr nz,VPutsTokenizedString_OneByte
inc hl
VPutsTokenizedString_OneByte:
pop bc
pop de
dec bc
ld a,b
or c
ret z
push de
push hl
ld hl,(pencol)
ex de,hl
or a
sbc hl,de
ld de,16
call cphlde
pop hl
pop de
jr nc,VPutsTokenizedString
ld a,b
or a
jr nz,VPutsTokenizedString_Finish
ld a,c
dec a
jr z,VPutsTokenizedString
VPutsTokenizedString_Finish:
ld hl,OP2
ld (hl),$BB ;$BB $DB is an ellipsis
inc hl
ld (hl),$DB
dec hl
bcall(_Get_Tok_Strng)
ld hl,OP3
ld b,a
call VPutsAppN
ret
DrawTraceEquation:
ld de,0
bcall(_ClearAppTitle)
call SetupStatusText
call SetTextColors
ld a,'Z'
bcall(_VPutMap)
ld a,(ateq)
call GetEnabledEq ; Gets the A'th equation token
push af
ld hl,BaseZVarName
rst 20h
pop af
ld (OP1 + 2),a
add a,$81-tZ1 ; Convert Z1-Z6 to sub1 to sub6
bcall(_VPutMap)
ld a,'='
bcall(_VPutMap)
rst 10h
ret c
ex de,hl
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld de,TRACE_EQ_END_X
call VPutsTokenizedString
ret