-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathionlibsp0.inc
532 lines (515 loc) · 7.76 KB
/
ionlibsp0.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
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
;-----------------------------------------------------------
; Filename: iolibsp.inc
; Long name: Ion Extended Libs for 83+/84+/SE
; Author: Kerm Martian aka Christopher Mitchell
; Last Update: June 2, 2006
;
;Please consult license.txt for the fair use agreement
;implicitly binding by you continuing to read past this
;point. Close and delete this file if you do not agree
;to the terms of the agreement.
;-----------------------------------------------------------
; The Built-in Ion Library Routines by Joe Wingbermuehle
#define TI83P_USE_FLASH_iDetect
iCheckInts0:
;Push a zero byte to the stack and pop it
xor a
push af
pop af
ld a,i
ret pe
;See if an interrupt triggered. If so, the byte on the stack will not be 0 anymore
dec sp
dec sp
pop af
add a,a
ret z
xor a
ret
;-----> Return Ion iVersion information
; hl=Ion iVersion,a=Ion compatibility number
; d=routine compatability number
; e=number of routines
iVersion:
ld a,ION_COMPATIBILITY
ld hl,iVersion_MAJOR*256+iVersion_MINOR
ld de,LIBRARY_COMPATIBILITY*256+NUMBER_OF_LIBRARIES
ret
;-----> Generate a iRandom number
; input b=upper bound
; ouput a=answer 0<=a<b
; all registers are preserved except: af and bc
iRandom:
push hl
push de
ld hl,(randData)
ld a,r
ld d,a
ld e,(hl)
add hl,de
add a,l
xor h
ld (randData),hl
sbc hl,hl
ld e,a
ld d,h
iRandomLoop:
add hl,de
djnz iRandomLoop
ld a,h
pop de
pop hl
ret
;-----> Draw a sprite
; b=size of sprite
; l=yc
; a=xc
; ix holds pointer
iPutSprite:
ld e,l
ld h,$00
ld d,h
add hl,de
add hl,de
add hl,hl
add hl,hl
ld e,a
and $07
ld c,a
srl e
srl e
srl e
add hl,de
ld de,gbuf
add hl,de
iPutSpriteLoop1:
sl1: ld d,(ix)
ld e,$00
ld a,c
or a
jr z,iPutSpriteSkip1
iPutSpriteLoop2:
srl d
rr e
dec a
jr nz,iPutSpriteLoop2
iPutSpriteSkip1:
ld a,(hl)
xor d
ld (hl),a
inc hl
ld a,(hl)
xor e
ld (hl),a
ld de,$0B
add hl,de
inc ix
djnz iPutSpriteLoop1
ret
;-----> Draw a picture
;Input: ix->sprite
; a=x
; l=y
; b=height (in pixels)
; c=width (in bytes, e.g. 2 would be 16)
;Output: nothing
; All registers are destroyed except bc', de', hl'
iLargeSprite:
ld d,a
call iCheckInts0
push af
ld a,d
di
ex af,af'
ld a,c
push af
ex af,af'
ld e,l
ld h,$00
ld d,h
add hl,de
add hl,de
add hl,hl
add hl,hl
ld e,a
and $07
ld c,a
srl e
srl e
srl e
add hl,de
ld de,gbuf
add hl,de
iLargeSpriteLoop1:
push hl
iLargeSpriteLoop2:
ld d,(ix)
ld e,$00
ld a,c
or a
jr z,iLargeSpriteSkip1
iLargeSpriteLoop3:
srl d
rr e
dec a
jr nz,iLargeSpriteLoop3
iLargeSpriteSkip1:
ld a,(hl)
xor d
ld (hl),a
inc hl
ld a,(hl)
xor e
ld (hl),a
inc ix
ex af,af'
dec a
push af
ex af,af'
pop af
jr nz,iLargeSpriteLoop2
pop hl
pop af
push af
ex af,af'
ld de,$0C
add hl,de
djnz iLargeSpriteLoop1
pop af
pop af
ret po
;#ifdef enablecn2eis
ei
;#endif
ret
;-----> Get pixel information
; input: e=y coordinate
; a=x coordinate
; output: a holds data for pixel (e.g. %00100000)
; hl->byte where pixel is on the gbuf
iGetPixel:
ld d,$00
ld h,d
ld l,e
add hl,de
add hl,de
add hl,hl
add hl,hl
ld de,gbuf
add hl,de
ld b,$00
ld c,a
and %00000111
srl c
srl c
srl c
add hl,bc
ld b,a
inc b
ld a,%00000001
iGetPixelLoop:
rrca
djnz iGetPixelLoop
ret
;-----> Copy the gbuf to the screen, guaranteed
;Courtesy of Runer112/Axe.
;Input: nothing
;Output:graph buffer is copied to the screen, no matter the speed settings
iFastCopy:
ld hl,gbuf
ld a,$80
out ($10),a
call Safety
push af
ld a,$1F
__iFastCopyAgain:
inc a
out ($10),a ;many cc into, 72cc loop
cp $2B
ld bc,(64<<9)+$11
push hl
inc de ;waste
__iFastCopyLoop:
push af ;semi waste
ld de,11
outi ;71cc into, 71cc loop
add hl,de
pop af ;semi waste
djnz __iFastCopyLoop
pop hl
inc hl
jr c,__iFastCopyAgain
__iFastCopyRestore:
pop af
out ($20),a
ret c
ei
ret
;Safety stuff (Stupid TI/z80!)
Safety: ;Output: af holds state to-be-pushed
;DESTROYS B, all other registers okay.
in a,($02) ;Save model settings
rla ;BE flag into carry
sbc a,a ;00 if BE else FF
jr z,__SafetyBE ;Check If model is base edition
in a,($20) ;Get current speed setting
__SafetyBE:
ld b,a ;Save speed setting
xor a ;Set nc (interrupts)
out ($20),a ;Set speed to slow
SafetyIntOnly:
push af ;Check interrupts
pop af
ld a,i ;pe if interrupt
di
ld a,b ;Restore speed setting
ret pe ;Return if interrupts on
dec sp ;Otherwise, robust test
dec sp
pop af
or a ;Set nc (interrupts)
ld a,b
ret nz ;Return if interrupts on
scf ;Set c (no interrupts)
ret ;Return
;-----> iDetect a file
; input:
; hl=place to start looking
; ix->first line of data (0 terminated)
; output:
; de=place stopped + 1
; hl->program data (after the string)
; z=0 if found, z=1 if not found.
; All registers destroyed
iDetect: ld de,(ptemp)
bcall(_cphlde)
ld a,(hl)
jr nz,iDetectContinue
inc a
ret
iDetectContinue:
push hl
and $01
jr nz,iDetectSkip
dec hl
dec hl
dec hl ; hl->lsb ptr
ld e,(hl)
dec hl
ld d,(hl)
dec hl ; hl->page
ld a,(hl)
or a
push af
ld h,d
ld l,e ; hl & de->program
jr z,iDetectNoMove
push hl
bcall(_memfree)
ld bc,64
sbc hl,bc
pop hl
jr c,iDetectNotEnough
ld de,($9820)
push ix
push hl
push de
bcall(_flashToRam)
pop hl
push hl
pop ix
ld a,10
add a,(ix+9)
ld e,a
ld d,0 ; de=flash offset
add hl,de
ex (sp),hl
add hl,de
pop de
ex de,hl ; hl-temp, de-perm
pop ix
iDetectNoMove:
inc de
inc de
ld c,(hl)
inc hl
ld b,(hl)
inc hl ; hl->data in ram
push bc
push ix
pop bc
iDetectCheck:
ld a,(bc)
or a
jr z,iDetectFound
cp (hl)
inc bc
inc de
inc hl
jr z,iDetectCheck
iDetectBad:
pop bc
iDetectNotEnough:
pop af
iDetectSkip:
pop hl
ld bc,-6
add hl,bc
ld b,(hl)
dec hl
iDetectNameLoop2:
dec hl
djnz iDetectNameLoop2
jr iDetect
iDetectFound:
pop hl
; hl=size, de->data
pop af ; a=page, f=(or a)
jr z,iDetectInRam
push de ; data
push af
push hl
bcall(_enoughRam)
pop bc
jr c,iDetectBad
pop af
pop hl
ld de,($9820) ; tempMem
push de
bcall(_flashToRam)
pop de
iDetectInRam: ; de->data in RAM
pop hl ; hl->vat location
ld bc,-6
add hl,bc
ld b,(hl)
inc b
iDetectNameLoop1:
dec hl
djnz iDetectNameLoop1
ex de,hl
xor a
ret
;-----> iDecompress data
; input:
; hl->compressed data
; de->place to load data
; b=length of compressed data
; c=compression factor (1, 3, or 15)
; output:
; level is iDecompressed
; hl->next byte of compressed data
iDecompress:
call iCheckInts0
push af
di
iDecompressLoop:
push bc
ld a,(hl)
ex af,af'
ld a,c
ld b,8
cp 1
jr z,dcmp1
ld b,4
cp 3
jr z,dcmp1
ld b,2
dcmp1: push bc
ld a,c
ld b,1
cp 1
jr z,dcmp2
inc b
cp 3
jr z,dcmp2
ld b,4
dcmp2: ex af,af'
dcmp3: rlca
djnz dcmp3
ld b,a
ex af,af'
ld a,b
and c
ld (de),a
inc de
pop bc
djnz dcmp1
inc hl
pop bc
djnz iDecompressLoop
pop af
ret po
;#ifdef enablecn2eis
ei
;#endif
ret
; End of Ion Library Routines by Joe Wingbermuehle
; Ion Extended Routines by Joe Wingbermuehle and Kerm Martian
iPutSpriteMask:
ld e,l
ld h,$00
ld d,h
add hl,de
add hl,de
add hl,hl
add hl,hl
ld e,a
and $07
ld c,a
srl e
srl e
srl e
add hl,de
ld de,gbuf
add hl,de
iPutSpriteLoop1Mask:
ld d,(ix)
ld e,$FF
ld a,c
or a
jr z,iPutSpriteSkip1Mask
iPutSpriteLoop2Mask:
srl d
rr e
set 7,d
dec a
jr nz,iPutSpriteLoop2Mask
iPutSpriteSkip1Mask:
ld a,(hl)
and d
ld (hl),a
inc hl
ld a,(hl)
and e
ld (hl),a
push ix
dec hl
ld de,8
add ix,de
iPutSpriteLoop1AND:
ld d,(ix)
ld e,$00
ld a,c
or a
jr z,iPutSpriteSkip1AND
iPutSpriteLoop2AND:
srl d
rr e
dec a
jr nz,iPutSpriteLoop2AND
iPutSpriteSkip1AND:
ld a,(hl)
xor d
ld (hl),a
inc hl
ld a,(hl)
xor e
ld (hl),a
pop ix
ld de,$0B
add hl,de
inc ix
djnz iPutSpriteLoop1Mask
ret
; End of Ion Library Routines by Kerm Martian