-
Notifications
You must be signed in to change notification settings - Fork 2
/
PutSprite.asm.m4
669 lines (526 loc) · 14.4 KB
/
PutSprite.asm.m4
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
669
; *************************************************************************
; Convert the Y AND X pixel values TO the correct Screen Address - Address in DE
;
; IN:
; b row
; c col
;
; OUT:
; de screen addr
;
; MODIFIED REGISTERS
; a
; de
;
define( `GET_SCREEN_ADDR', `
IFDEF __ZX81__
push hl
ld de,(16518)
ld l,b
ld h,0
; row x 32
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
add hl,hl ; x16
add hl,hl ; x32
; col / 8
ld a,c
srl a
srl a
srl a
add a,l
ld l,a
ld a,0
adc a,h
ld h,a
add hl,de
pop de
ex de,hl
ENDIF
IFDEF __SPECTRUM__
; 77t
ex de,hl
ld h, ScreenTables/256
ld l,b
ld a,(hl)
inc h
ld l,(hl)
ld h,a
ld a,c
srl a
srl a
srl a
add a,l
ld l,a
ex de,hl
ENDIF
')
; **************************************************************************************************+
; Sprite and Print functions
; by Juan Jose Ponteprino
; **************************************************************************************************'
SECTION data_user
rotate_bits:
db 0
IFDEF __SPECTRUM__
EXTERN ScreenTables
ENDIF
EXTERN _CHARSET
SECTION code_user
PUBLIC _PutSprite1, _PutSprite1Merge, _PutSprite1Delete, _PutSprite2, _PutSprite3, _PrintChar
PUBLIC _PutSprite1_internal, _PutSprite1M_internal, _PutSprite1D_internal, _PutSprite2_internal
; **************************************************************************************************'
; (byte x, byte y, void * spr)
; **************************************************************************************************'
_PutSprite1:
pop hl ; return
pop bc ; coordenadas
ex (sp),hl ; sprite
_PutSprite1_internal:
; hl: sprite address
; b: y
; c: x
GET_SCREEN_ADDR
; hl => sprite data
; de => target
ld a,c
and 7
ld (rotate_bits),a
ld a,8 ; set counter TO 8 - Bytes of Character Data TO put down
Loop1:
IFDEF __ZX81__
push af ; save off Counter
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
ld a,(rotate_bits) ; a = posiciones a rotar
or a
jr z, norotate1 ; if the the X value is on an actual Character boundary i.e. there's no need to shift anything
push hl ; Data Address
; push de ; Screen Address
ld b,a ; rotate times
ld c,255 ; mask
ld a,(hl) ; sprite data
ld l,e ; hl = screen address (target)
ld h,d ; hl = screen address (target)
ld e,a ; sprite data
xor a ; MSB mask
ld d,a ; MSB sprite
rotate1:
srl e ; rotate sprite
rr d
srl c ; rotate mask
rra
djnz rotate1
ld b,a ; mascara = c, b
; pop hl ; recupero direccion destino
ld a,c
cpl
ld c,a
ld a,b
cpl
ld b,a
ld a,(hl) ; 1er byte rotado del sprite (con mascara)
and c
or e
ld (hl),a
inc l
ld a,(hl) ; 2er byte rotado del sprite (con mascara)
and b
or d
ld (hl),a
dec l
ex de,hl
pop hl ; get the Address of the Character Data back AND increment it ready FOR the NEXT BYTE of data
row_complete1:
IFDEF __ZX81__
ld a,32
add a,e
ld e,a
ld a,0
adc a,d
ld d,a ; it AND Increment the Y value in B AS well
ENDIF
IFDEF __SPECTRUM__
inc d ; it AND Increment the Y value in B AS well
ld a,d ; now check IF the Y value has gone OVER a Character Boundary i.e. we will need TO recalculate the Screen
; Address IF we've jumped from one Character Line to another - messy but necessary especially for lines 7 and 15 '
and 7
jp nz, addr_ok1
ld a,e
add 32
ld e,a
jp c, addr_ok1
ld a,d
sub 8
ld d,a
addr_ok1:
ENDIF
inc hl
IFDEF __ZX81__
pop af ; get the Counter value back, decrement it AND GO back FOR another write IF we haven't reached the end yet '
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
dec a
jp nz, Loop1
ret
norotate1:
ld a,(hl) ; get a BYTE of Character Data TO put down - but ignore the following Mask shifting
ld (de),a
jp row_complete1
; **************************************************************************************************'
; (byte x, byte y, void * spr)
; **************************************************************************************************'
_PutSprite1Merge: ; Merge
pop hl ; return
pop bc ; coordenadas
ex (sp),hl ; sprite
_PutSprite1M_internal:
; hl: sprite address
; b: y
; c: x
GET_SCREEN_ADDR
; hl => sprite data
; de => target
ld a,c
and 7
ld (rotate_bits),a
ld a,8 ; set counter TO 8 - Bytes of Character Data TO put down
Loop1M:
IFDEF __ZX81__
push af ; save off Counter
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
ld a,(rotate_bits) ; a = posiciones a rotar
or a
jr z, norotate1M ; if the the X value is on an actual Character boundary i.e. there's no need to shift anything
ld b,a ; rotate times
ld c,(hl)
xor a
rotate1M:
srl c ; rotate sprite
rra
djnz rotate1M
ld b,a
ld a,(de) ; 1er byte rotado del sprite (con mascara)
or c
ld (de),a
inc e
ld a,(de) ; 2er byte rotado del sprite (con mascara)
or b
ld (de),a
dec e
row_complete1M:
IFDEF __ZX81__
ld a,32
add a,e
ld e,a
ld a,0
adc a,d
ld d,a ; it AND Increment the Y value in B AS well
ENDIF
IFDEF __SPECTRUM__
inc d ; it AND Increment the Y value in B AS well
ld a,d ; now check IF the Y value has gone OVER a Character Boundary i.e. we will need TO recalculate the Screen
; Address IF we've jumped from one Character Line to another - messy but necessary especially for lines 7 and 15 '
and 7
jp nz, addr_ok1M
ld a,e
add 32
ld e,a
jp c, addr_ok1M
ld a,d
sub 8
ld d,a
addr_ok1M:
ENDIF
inc hl
IFDEF __ZX81__
pop af ; get the Counter value back, decrement it AND GO back FOR another write IF we haven't reached the end yet '
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
dec a
jp nz, Loop1M
ret
norotate1M:
ld a,(de) ; get a BYTE of Character Data TO put down - but ignore the following Mask shifting
or (hl)
ld (de),a
jp row_complete1M
; **************************************************************************************************'
; (byte x, byte y, void * spr)
; **************************************************************************************************'
_PutSprite1Delete:
pop hl ; return
pop bc ; coordenadas
ex (sp),hl ; sprite
_PutSprite1D_internal:
; hl: sprite address
; b: y
; c: x
GET_SCREEN_ADDR
; hl => sprite data
; de => target
ld a,c
and 7
ld (rotate_bits),a
ld a,8 ; set counter TO 8 - Bytes of Character Data TO put down
Loop1D:
IFDEF __ZX81__
push af ; save off Counter
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
ld a,(rotate_bits) ; a = posiciones a rotar
or a
jr z, norotate1D ; if the the X value is on an actual Character boundary i.e. there's no need to shift anything
ld b,a ; rotate times
ld c,(hl)
xor a
rotate1D:
srl c ; rotate sprite
rra
djnz rotate1D
cpl
ld b,a
ld a,c
cpl
ld c,a
ld a,(de) ; 1er byte rotado del sprite (con mascara)
and c
ld (de),a
inc e
ld a,(de) ; 2er byte rotado del sprite (con mascara)
and b
ld (de),a
dec e
row_complete1D:
IFDEF __ZX81__
ld a,32
add a,e
ld e,a
ld a,0
adc a,d
ld d,a ; it AND Increment the Y value in B AS well
ENDIF
IFDEF __SPECTRUM__
inc d ; it AND Increment the Y value in B AS well
ld a,d ; now check IF the Y value has gone OVER a Character Boundary i.e. we will need TO recalculate the Screen
; Address IF we've jumped from one Character Line to another - messy but necessary especially for lines 7 and 15 '
and 7
jp nz, addr_ok1D
ld a,e
add 32
ld e,a
jp c, addr_ok1D
ld a,d
sub 8
ld d,a
addr_ok1D:
ENDIF
inc hl
IFDEF __ZX81__
pop af ; get the Counter value back, decrement it AND GO back FOR another write IF we haven't reached the end yet '
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
dec a
jp nz, Loop1D
ret
norotate1D:
ld a,(hl) ; get a BYTE of Character Data TO put down - but ignore the following Mask shifting
ex de,hl
cpl
and (hl)
ld (hl),a
ex de, hl
jp row_complete1D
; **************************************************************************************************'
; (byte x, byte y, void * spr)
; **************************************************************************************************'
_PutSprite2:
pop hl ; return
pop bc ; coordenadas
ex (sp),hl ; sprite
_PutSprite2_internal:
; hl: sprite address
; b: y
; c: x
GET_SCREEN_ADDR
; hl => sprite data
; de => target
ld a,c
and 7
ld (rotate_bits),a
ld a,8 ; set counter TO 8 - Bytes of Character Data TO put down
Loop2:
IFDEF __ZX81__
push af ; save off Counter
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
push hl ; save off Address of Character Data, Screen Address, Screen Address
ld a,(rotate_bits) ; a = posiciones a rotar
or a
jr z, norotate2 ; if the the X value is on an actual Character boundary i.e. there's no need to shift anything
push de ; Screen Address
; push de ; Screen Address
ld b,a ; rotate times
ld e,(hl)
inc hl
ld c,(hl)
xor a
ld d,255 ; mask
ld l,a
rotate2:
srl e ; rotate sprite
rr c
rra
srl d ; rotate mask
rr l
djnz rotate2
; ld c, h
ld b, l ; mascara = d, $ff, b
pop hl ; recupero direccion destino
push af ; guardo sprite rotado
ld a,d
cpl
ld d,a
ld a,b
cpl
ld b,a
ld a,(hl) ; 1er byte rotado del sprite (con mascara)
and d
or e
ld (hl),a
; ld c,d ; 2do byte rotado lo paso a c
pop de ; 3er recupero byte rotado (push af)
inc l ; Increment the Screen Address AND check TO see IF it's at the end of a line,
ld a,l
and 31 ; if so THEN there's no need to put down the second part of the sprite
jp z, row_complete2b2
ld (hl),c ; 2do byte rotado del sprite (va directo, sin mascara)
inc l
ld a,l
and 31 ; if so THEN there's no need to put down the 3rd part of the sprite
jp z, row_complete2b1
ld a,(hl) ; 3er byte rotado del sprite (con mascara)
and b
or d
ld (hl),a
row_complete2b1:
dec l
row_complete2b2:
dec l
ex de,hl ; de = screen address
row_complete2b:
; pop de ; get the Screen Address back into DE, increment Y
row_complete2:
IFDEF __ZX81__
ld a,32
add a,e
ld e,a
ld a,0
adc a,d
ld d,a ; it AND Increment the Y value in B AS well
ENDIF
IFDEF __SPECTRUM__
inc d ; it AND Increment the Y value in B AS well
ld a,d ; now check IF the Y value has gone OVER a Character Boundary i.e. we will need TO recalculate the Screen
; Address IF we've jumped from one Character Line to another - messy but necessary especially for lines 7 and 15 '
and 7
jp nz, addr_ok2
ld a,e
add 32
ld e,a
jp c, addr_ok2
ld a,d
sub 8
ld d,a
addr_ok2:
ENDIF
pop hl ; get the Address of the Character Data back AND increment it ready FOR the NEXT BYTE of data
inc hl
inc hl
IFDEF __ZX81__
pop af ; get the Counter value back, decrement it AND GO back FOR another write IF we haven't reached the end yet '
ENDIF
IFDEF __SPECTRUM__
ex af,af'
ENDIF
dec a
jp nz, Loop2
ret
norotate2:
ld a,(hl) ; get a BYTE of Character Data TO put down - but ignore the following Mask shifting
ld (de),a
inc hl
inc e
ld a,e
and 31 ; if so THEN there's no need to put down the 3rd part of the sprite
jp z, skip_2nd_byte2
ld a,(hl)
ld (de),a
skip_2nd_byte2:
dec e
jp row_complete2
; -------------------------------------------------------
; (byte x, byte y, byte char, byte mode )
_PrintChar:
pop hl
pop bc
ex (sp), hl ; l = char, h = mode
ex de, hl ; e = char, d = mode
IFDEF _CHARSET
ld a,e
sub a,32
ld l,a
ELSE
ld l,e
ENDIF
ld h,0
ld a,d
add hl,hl
add hl,hl
add hl,hl
IFDEF _CHARSET
ld de, _CHARSET
ELSE
ld de, (23606)
ENDIF
add hl,de
and a
jp z, _PutSprite1_internal
dec a
jp z, _PutSprite1M_internal
dec a
jp z, _PutSprite1D_internal
ret
; -------------------------------------------------------
; (byte x, byte y, void * spr)
_PutSprite3:
pop hl ; return
pop bc ; coordenadas
ex (sp),hl ; sprite
push bc
push hl
call _PutSprite2_internal
pop hl
pop bc
ld a,c
add 16
ld c,a
ld de, 16
add hl, de
jp _PutSprite1_internal