root / system.inc

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
; Include Header for
; TI83 with Venus 2.4
; TI83+ with ION 1.6 (compatible with MirageOS)
; syntax: SPASM and TASM
; mostly borrowed from dwedit.inc
; How to use this header :
;
;+------------------------------+
;|#INCLUDE "system.inc"         |
;|  .db "Program title",0       |
;|start                         |
;|  [...]   ; program code here |
;|  ret                         |
;+------------------------------+
;
; Labels you have to define:
;TI83
;TI83P
;
;----> Safe Memory Areas (TI83(+))
; saferam1 = 768 bytes (apdram)
; saferam2 = 531 bytes (statram)
; saferam3 = 128 bytes (textmem)
; saferam4 = 66 bytes (ops)
; saferam5 = 10 bytes (imathptrs)

.NOLIST

#IFDEF TI83

#define bcall(xxxx)     call xxxx
#define bcallz(xxxx)    call    z,xxxx
#define bcallnz(xxxx)   call    nz,xxxx
#define bcallc(xxxx)    call    c,xxxx
#define bcallnc(xxxx)   call    nc,xxxx
#define bjump(xxxx)     jp xxxx
#define icall(xxxx)     call xxxx


vRandom		= $FE72	;
FastCopy	= $FE75	; Venus routines

_enoughmem	= 443Ah

_ldhlind	= 4000h
_cphlde		= 4004h
_divhlby10	= 4008h
_divhlbya	= 400Ch
_getcsc		= 4014h
_lcdbusy	= 4066h
_htimesl	= 4382h	; hl=h*l (error if overflow)
usermemoff	= 8565h
progstart	= 9327h
libstart	= 0002h
saferam1	= 8265h
saferam2	= 858Fh
saferam3	= 80C9h
saferam4	= 8039h
_homeup		= 4775h
_newline	= 473Dh
_darkline	= 4AE0h
_indicatorOff	= 4795h
_indicatorOn	= 4791h
_cleargbuf	= 515Bh
_copygbuf	= 4B9Ch
_clrlcdf	= 4755h
_cleartextshad	= 4765h
_clrscr		= 4759h
_clrscrf	= 475Dh
_clrscrnfull	= _clrscrf
_iline		= 4AE4h
_ipoint		= 4AE8h
_disphl		= 4709h
_hltimes9	= 4146h
_vputmap	= 477Dh
_vputs		= 4781h
_vputsn		= 4785h
_putmap		= 4701h
_puts		= 470Dh
_putps		= 4715h
_putc		= 4705h
_getkey		= 4CFEh
_getk		= 4A18h
_rcly		= 4EE0h
_rclx		= 4EE8h
_memfree	= 441Ah
_chksysvar	= 442Ah
_findsym	= 442Eh
_insertmem	= 4432h
_deletemem	= 44B2h
op1		= 8039h
op2		= 8044h
op3		= 804Fh
op4		= 805Ah
op5		= 8065h
op6		= 8070h
imathptr1	= 8094h
imathptr2	= 8096h
imathptr3	= 8098h
imathptr4	= 809Ah
imathptr5	= 809Ch
progptr		= 9319h
cmdshad		= 9157h
plotsscreen	= 8E29h
symtable	= $FE6E
currow		= 800Ch
curcol		= 800Dh
pencol		= 8252h
penrow		= 8253h
curgy		= 886Dh
curgx		= 886Eh
contrast	= $8008


FREE_MEM_START  = $930D
FREE_MEM_END	= $9311


; Some equates to help port

grbuf		= plotsscreen
GRAPH_MEM	= plotsscreen
gbuf		= plotsscreen
sram		= saferam1
apdram		= saferam1
APD_BUF		= saferam1
savesscreen	= saferam1
statram		= saferam2
statvars	= saferam2
vat		= progptr
saferam5	= imathptr1
TEXT_MEM	= saferam3
#ENDIF



#IFDEF TI83P

appBackupScreen	= $9872	; 768 bytes
tempSwapArea	= $82A5
usermemoff	= $89EC
libstart	= $0004
progstart	= 9D95h

saferam1	= 86ECh
saferam2	= 8A3Ah
saferam3	= 8508h
saferam4	= 8478h

op1		= 8478h
op2		= 8483h
op3		= 8499h
op4		= 8499h
op5		= 84A4h
op6		= 84AFh
imathptr1	= 84D3h
imathptr2	= 84D5h
imathptr3	= 84D7h
imathptr4	= 84D9h
imathptr5	= 84DBh
progptr		= 9830h
cmdshad		= 966Eh
plotsscreen	= 9340h
symtable	= $FE6E
currow		= 844Bh
curcol		= 844Ch
pencol		= 86D7h
penrow		= 86D8h
curgy		= 8D18h
curgx		= 8D19h
contrast	= 8447h

FREE_MEM_START	= $9824
FREE_MEM_END	= $9828

;-----> Ion Functions
lVectors	= cmdshad+80
ionVersion	= lVectors
ionRandom	= lVectors+3
ionPutSprite	= lVectors+6
ionLargeSprite	= lVectors+9
ionGetPixel	= lVectors+12
FastCopy	= lVectors+15
ionDetect	= lVectors+18
ionDecompress	= lVectors+21


; Some equates to help port

grbuf		= plotsscreen
GRAPH_MEM	= plotsscreen
gbuf		= plotsscreen
sram		= saferam1
apdram		= saferam1
APD_BUF		= saferam1
savesscreen	= saferam1
statram		= saferam2
statvars	= saferam2
vat		= progptr
saferam5	= imathptr1
TEXT_MEM	= saferam3
#ENDIF



;-----------------
; Ports and flags
;-----------------

lcdinstport	=	$10
lcddataport	=	$11

onflags 	=	9		;on key flags
onrunning	=	3	; 1 = calculator is running
oninterrupt	=	4	; 1=on key interrupt request

;#######################
;## Direct Input Keys ##
;#######################

;Group 1
KeyRow_Pad	= 0feh
KDown		= 254
KLeft		= 253
KRight		= 251
KUp		= 247
KIDown		= 1
KILeft		= 2
KIRight		= 4
KIUp		= 8



;Group 2
KeyRow_5 	= 0fdh
KEnter		= 254
KIEnter		= 1
KPlus		= 253
KMinus		= 251
KMul		= 247
KDiv		= 239
KPower		= 223
KClear		= 191

;Group 3
KeyRow_4 	= 0fbh
KMinus2		= 254
KThree		= 253
KSix		= 251
KNine		= 247
KRbracket	= 239
KTan		= 223
KVars		= 191

;Group 4
KeyRow_3	= 0f7h
KPoint		= 254
KTwo		= 253
KFive		= 251
KEight		= 247
KLbracket	= 239
KCos		= 223
KPrgm		= 191
KStat		= 127

;Group 5
KeyRow_2 	= 0efh
KZero		= 254
KOne		= 253
KFour		= 251
KSeven		= 247
KComma		= 239
KSin		= 223
KMatrx		= 191
KApps		= 191
KX		= 127

;Group 6
KeyRow_1 	= 0dfh
KOn         = 254
KSto		= 253
KLn		= 251
KLog		= 247
kX2		= 239
kX_1		= 223
kMath		= 191
kAlpha		= 127
kIOn    = 1
kIMath  = 64
kIAlpha = 128


;Group 7
KeyRow_Top 	= 0bfh
KGraph		= 254
KTrace		= 253
KZoom		= 251
KWindow		= 247
KY		= 239
k2nd		= 223
kMode		= 191
kDel		= 127

kI2nd = 32
kIMode = 64
kIDel = 128

.LIST


#IFDEF TI83
mysaferam = $9157 ; cmdshadow, 128 bytes
#ENDIF
#IFDEF TI83P
mysaferam = $9872 ; appBackupScreen, 768 bytes
#ENDIF


#IFDEF TI83P
	.org	progstart-2
	.db	$BB,$6D		; ION-compatible program
	ret
	jr	nc,start
#ENDIF

#IFDEF TI83
	.org	9329h
	.db	$E7,$39,$5F,$5B,$56,$3F,$00 ; Send(9prgm0V,0
	jr      nc,start
#ENDIF