-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoTC_Sprite.asm
1024 lines (915 loc) · 13.7 KB
/
DoTC_Sprite.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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ------------------------------------------------------------------------------
; from SPRITE.ASM
; ---------------------------
; a -> lutin number
; hl <- sprite ptr
getlut:
; ---------------------------
push af
dec a
add a,a
add a,sprite_table
ld l,a
adc a,sprite_table/&100
sub l
ld h,a
ld a,(hl)
inc hl
ld h,(hl)
ld l,a ; hl -> sprite ptr
pop af
ret
; ---------------------------
; Initialisation du sprite manager
lutinit:
; @todo Calcul et install de l'adresse du buffer ?
; ---------------------------
push hl
ld hl,lutin_current_idx
ld (hl),&00
pop hl
ret
; ---------------------------
; Declaration d'un lutin au sprite manager
; Table des sprites en BUFSPR
; Buffer de sauvegarde en (ANIBUF)
; l -> ligne
; h -> colonne
; a <- numéro du lutin
; c <- declaration ok
; nc<- plus de place dans le buffer de sauvegarde ecran
lutin
; @todo Calcul et install de l'adresse du buffer ?
; ---------------------------
push bc
push de
push hl
ld (lutin_sprite_nb),a ; sprite number
lutin_current_idx equ $+1
ld a,0
inc a
ld (lutin_idx),a
cp LUTIN_NB+1
jr nz,lutin_idx_ok
dec a
ld (lutin_idx),a
jr lutin_end
lutin_idx_ok
ld (lutin_current_idx),a
ld b,h
ld c,l ; bc -> Y, X
call scradd
push hl
call getlut
ld (hl),c
inc hl
ld (hl),b
inc hl
pop bc ; bc = screen address
ld (hl),c
inc hl
ld (hl),b
inc hl
ex de,hl
lutin_sprite_nb equ $+1
ld a,0 ; sprite number
ld hl,BUFSPR
lutin_getspr_loop
ld c,(hl)
inc hl
ld b,(hl)
inc hl
dec a
jr z,lutin_getspr_ok
add hl,bc
jr lutin_getspr_loop
lutin_getspr_ok
ex de,hl
; de -> data sprite address
ld (hl),e
inc hl
ld (hl),d
; inc hl
lutin_end
pop hl
pop de
pop bc
lutin_idx equ $+1
ld a,0
ret
; ---------------------------
; affichage d'un lutin
; a -> lutin number
luton
; ---------------------------
push af
push bc
push de
push hl
call getlut
inc hl
inc hl ; skip x,y
ld e,(hl)
inc hl
ld d,(hl) ; de = actual screen address
inc hl
ld a,(hl)
inc hl
ld h,(hl)
ld l,a ; hl = sprite address
ld c,(hl)
inc hl
ld b,(hl) ; bc = sprite width, height
inc hl
ex de,hl
call putspr
pop hl
pop de
pop bc
pop af
ret
; ---------------------------
; effacement d'un lutin
; a -> lutin number
lutoff:
; ---------------------------
push af
push bc
push de
push hl
call getlut
inc hl
inc hl ; skip x,y
ld e,(hl)
inc hl
ld d,(hl) ; de = actual screen address
inc hl
ld c,(hl)
inc hl
ld h,(hl)
ld l,c ; hl = sprite address
ld b,(hl)
inc hl
ld c,(hl) ; bc = sprite height,width
inc hl
; ex de,hl
call lutmscr
pop hl
pop de
pop bc
pop af
ret
; ---------------------------
; sauvegarde de l'ecran sous un lutin
; a -> lutin number
lutsave
; ---------------------------
push af
push bc
push de
push hl
call getlut
inc hl
inc hl ; skip x,y
ld e,(hl)
inc hl
ld d,(hl) ; de = actual screen address
inc hl
ld a,(hl)
inc hl
ld h,(hl)
ld l,a ; hl = sprite address
ld b,(hl)
inc hl
ld c,(hl) ; bc = sprite height,width
inc hl
ex de,hl
call lutscrm
pop hl
pop de
pop bc
pop af
ret
; ---------------------------
; inversion d'une region a l'ecran
; hl-> adresse ecran
; de-> sprite
; b -> nombre d'octets par ligne
; c -> nombre de lignes
;modifies- aucun
xorreg:
; ---------------------------
push af
push bc
push de
push hl
xorreg0
push bc
push hl
xorreg1
ld a,(de)
xor (hl)
ld (hl),a
inc hl
inc de
djnz xorreg1
pop hl
call nextline
pop bc
dec c
jr nz,xorreg0
pop hl
pop de
pop bc
pop af
ret
; ---------------------------
; descend d'une ligne
; hl -> old address
; hl <- next address
nextline:
; @todo - voir si besoin du push/pop af ?
; ---------------------------
push af
read "../include/screen_next_line_hl.asm"
pop af
ret
; ---------------------------
; calcul d'une adresse ecran
; hl -> h = Colonne (0 -> 159), l -> Ligne (199 -> 0)
; hl <- screen address
scradd:
; ---------------------------
push af
push bc
push de
ld e,h
ld h,0
ld d,h
sla e
rl d
call SCR_DOT_POSITION ; #bc1d
pop de
pop bc
pop af
ret
; ---------------------------
; a <- le code d'un octet ecran de la couleur dans a
encode:
; ---------------------------
push bc
ld c,a
xor a
bit 3,c
jr z,encod0
or #03
encod0
bit 2,c
jr z,encod1
or #30
encod1
bit 1,c
jr z,encod2
or #0c
encod2
bit 0,c
jr z,encod3
or #c0
encod3
pop bc
ret
TEST equ 1
IF TEST
; 2960
; ---------------------------
lutscrm
; ---------------------------
push bc
push hl
lutsave0
push bc
push hl
ld b,0
ldir
pop hl
inline_bc26_hl
pop bc
djnz lutsave0
pop hl
pop bc
ret
; ---------------------------
; affichage d'un sprite sans transparence
; hl -> buffer data
; de -> screen address
; b -> nombre d'octets par ligne
; c -> nombre de lignes
; ---------------------------
putsprb:
ld a,b
ld b,c
ld c,a
; ---------------------------
; hl -> buffer data
; de -> screen address
; b -> nombre d'octets par ligne
; c -> nombre de lignes
lutmscr:
; ---------------------------
lutrest0
push bc
push de
ld b,0
ldir
ex de,hl
pop hl
inline_bc26_hl
ex de,hl
pop bc
djnz lutrest0
ret
; ---------------------------
; recherche et affichage d'un sprite
; Table des sprites en BUFSPR
; a -> no du sprite
; l -> ligne
; h -> colonne
; modifies- aucun
affspr
; ---------------------------
push bc
push de
push hl
call scradd
ex de,hl
ld hl,BUFSPR
call getspr
ex de,hl
call putspr
pop hl
pop de
pop bc
ret
; ---------------------------
; recherche et affichage d'un sprite sans transparence
; Table des sprites en BUFSPR
; a -> no du sprite
; l -> ligne
; h -> colonne
; modifies- aucun
affsprb
; ---------------------------
push bc
push de
push hl
call scradd
ex de,hl
ld hl,BUFSPR
call getspr
call putsprb
pop hl
pop de
pop bc
ret
; ---------------------------
; recherche et affichage d'un sprite avec effacement en couleur b
; Table des sprites en BUFSPR
; a -> no du sprite
; l -> ligne
; h -> colonne
; modifies- aucun
affsprc
; ---------------------------
push bc
push de
push hl
call scradd
ex de,hl
ld hl,BUFSPR
push af
ld a,b
call encode
ld (fond),a
pop af
call getspr
ex de,hl
call clean
call putspr
pop hl
pop de
pop bc
ret
; ---------------------------
; affichage d'un sprite
; hl-> adresse ecran
; de-> sprite
; b -> nombre d'octets par ligne
; c -> nombre de lignes
putspr:
; ---------------------------
push af
push de
putspr0
push bc
push hl
putspr1
ld a,(de)
and #aa
jr nz,putspr2
ld a,(hl)
and #aa
putspr2
ld c,a
ld a,(de)
and #55
jr nz,putspr3
ld a,(hl)
and #55
putspr3
or c
ld (hl),a
inc de
inc hl
djnz putspr1
pop hl
INLINE_BC26_HL
pop bc
dec c
jr nz,putspr0
pop de
pop af
ret
; ---------------------------
; effacement sous un sprite
clean
; ---------------------------
push hl
push de
push bc
ld e,b
ld b,c
ld c,e
dec c
clean0
push bc
push hl
ld b,0
ld d,h
ld e,l
inc de
fond equ $+1
ld (hl),0
ldir
pop hl
call nextline
pop bc
djnz clean0
pop bc
pop de
pop hl
ret
; ---------------------------
getspr
push de
push af
getspr0
ld e,(hl)
inc hl
ld d,(hl)
inc hl
dec a
jr z,getspr1
add hl,de
jr getspr0
getspr1
ld c,(hl)
inc hl
ld b,(hl)
inc hl
pop af
pop de
ret
; recherche d'un sprite
; a -> sprite number
; hl -> sprite data table ptr
; hl <- sprite ptr
; b <- nombre d'octets par ligne
; c <- nombre de lignes
;getspr:
; ---------------------------
; push af
; dec a
; add a,a
; add a,l
; ld l,a
; adc a,h
; sub l
; ld h,a
; ld a,(hl)
; inc hl
; ld h,(hl)
; ld l,a ; hl <- sprite ptr
; ld c,(hl)
; inc hl
; ld b,(hl)
; inc hl ; bc <- width, height
; pop af
; ret
; ---------------------------
; identification de la region pointee par la fleche
; carry -> region trouvee
; a -> numero de la region pointee par la fleche
;modifies- af
whatreg
; ---------------------------
push bc
push de
push hl
push ix
call tfleche
ld c,a
ld b,REGIONS_NB
whatreg0
push bc
ld a,b
ld hl,BUFSPR
call getspr
ex de,hl
call getreg
ld l,(ix+REGION_LIGNE)
ld h,(ix+REGION_COLONNE)
; insquare
ld a,(flrow)
cp l
jr z,insq1
jr nc,insquare_end
insq1
add a,c
cp l
jr z,insquare_end
jr c,insq2
ld a,(flcol)
cp h
jr c,insq2
sla b
sub b
srl b
cp h
jr insquare_end
insq2
ccf
insquare_end
jr c,whatreg4
pop bc
jr whatreg3
whatreg4
call scradd
push bc
call vbl_wait ; #bd19
pop bc
; di
call xorreg
call tfleche
call xorreg
; ei
pop bc
cp c
jr nz,whatreg1
whatreg3
djnz whatreg0
xor a
jr whatreg2
whatreg1
ld a,b
scf
whatreg2
pop ix
pop hl
pop de
pop bc
ret
; ---------------------------
; affichage d'une region
; a -> numero de la region
affreg
; ---------------------------
push af
push bc
push de
push hl
push ix
push iy
ld (cour_reg+1),a
ld (cour_re2+1),a
ld hl,BUFSPR
call getspr
ex de,hl
call getreg
ld a,(ix+REGION_PROPRIO)
or a
jr nz,affre0
ld a,13
jr affre1
affre0
call getlord
ld a,(iy+LORD_CASTLE)
ld hl,chato
call rdtab_4
ld a,(hl)
affre1
call encode
ld (affreg2+1),a
ld l,(ix+REGION_LIGNE)
ld h,(ix+REGION_COLONNE)
call scradd
affreg0
push bc
push hl
affreg1
ld a,(de)
cpl
and (hl)
ld c,a
ld a,(de)
affreg2
and 0
or c
ld (hl),a
inc de
inc hl
djnz affreg1
pop hl
call nextline
pop bc
dec c
jr nz,affreg0
; ld a,(lord)
; call getlord
ld iy,(player1_lord)
ld a,(ix+REGION_CONSTRUCTION)
or a
jr z,affregnc
add a,19 ; castle sprite (20,21,22)
ld l,(ix+REGION_Y_CHATEAU)
ld h,(ix+REGION_X_CHATEAU)
call affspr
ld a,(iy+LORD_CASTLE)
ld hl,chato+1
call rdtab_4
cour_reg
ld a,0
cp (hl)
jr nz,affregnc
ld a,(ix+REGION_Y_CHATEAU)
add a,6
ld l,a
ld a,(ix+REGION_X_CHATEAU)
add a,4
ld h,a
ld a,24 ; flag
call affspr
affregnc
cour_re2
ld a,0
cp (iy+LORD_REGION)
jr nz,affregnh
ld a,23 ; horse+knight
ld l,(ix+REGION_Y_LORD)
ld h,(ix+REGION_X_LORD)
call affspr
affregnh
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ret
;
animate
animateb
LUTMODV
ret
ELSE
PUTSPR
GETSPR
WHATREG
affspr
AFFSPRB
AFFSPRC
LUTMSCR
lutscrm
ret
; ---------------------------
; execution d'une animation
; hl -> adresse de l'animation
animateb
; ---------------------------
push af
push hl
ld a,#c9
ld (qlutoff),a
ld (qlutsav),a
ld hl,putsprb
ld (qlonmod+1),hl
ld a,#cd
ld (animint),a
ld (animint+1),de
pop hl
pop af
call animate
push hl
push af
ld hl,putspr
ld (qlonmod+1),hl
ld a,#01
ld (qlutoff),a
ld (qlutsav),a
ld hl,animint
dec a
ld (hl),a
inc hl
ld (hl),a
inc hl
ld (hl),a
pop af
pop hl
ret
animate
push hl
push bc
push de
push af
push ix
ld b,(hl)
inc hl
animbcl push bc
ld a,(hl)
inc hl
ld c,a
and #07
push af
push hl
ld hl,luttab+7
ld de,7
call rdtab
push hl
pop ix
pop hl
bit 5,c
ld b,(ix+00)
jr z,animat1
ld b,(hl)
inc hl
animat1 ld d,(ix+01)
ld e,(ix+02)
bit 4,c
jr z,animat2
ld e,(hl)
inc hl
ld d,(hl)
inc hl
animat2 bit 7,c
jr z,animat3
push hl
ld h,(ix+01)
ld l,(ix+02)
ld a,h
add a,d
ld d,a
ld a,l
add a,e
ld e,a
pop hl
animat3 pop af
ex de,hl
call lutmodv
ex de,hl
bit 3,c
jp z,animsui0
ld a,(hl)
inc hl
call milpause
animint nop
nop
nop
animsui0 pop bc
djnz animbcl
pop ix
pop af
pop de
pop bc
pop hl
ret
; ---------------------------
; deplacement d'un lutin avec changement
; h -> colonne
; l -> ligne
; b -> numero sprite
; a -> lutin number
lutmodv
; ---------------------------
push af
push bc
push de
push hl
push ix
push iy
push bc
push hl
call getlut
ld (qlofsz+1),bc
ld (qlofbf+1),de
ld (qlofad+1),hl
ld (qlsvbf+1),de
pop hl
ld (ix+01),h
ld (ix+02),l
call scradd
ld (qlsvad+1),hl
ld (qlonad+1),hl
pop af
ld (ix+00),a
ld hl,BUFSPR
call getspr
ld (qlsvsz+1),bc
ld (qlonsz+1),bc
ld (qlonsp+1),hl
call vbl_wait ; #bd19
di
call qlutoff
call qlutsav
call qluton
ei
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ret
;
qluton
qlonsz ld bc,0
qlonsp ld de,0
qlonad ld hl,0
qlonmod jr putspr
;
qlutoff
qlofsz ld bc,0
qlofbf ld de,0
qlofad ld hl,0
jr lutmscr
;
qlutsav
qlsvsz ld bc,0
qlsvbf ld de,0
qlsvad ld hl,0
jp lutscrm
; 2128
; ---------------------------
; de -> sprite_data
; bc -> background_data
;putspr:
; ---------------------------
push af
; push bc
; push de
; push hl
push ix
push iy
ld ixh,c ; 2
ld a,b
ld (putspr_loop_sprite_width),a
ld b,h
ld c,l
ld iyl,c
ld hl,sprite_mask_table
putspr_loop_height
putspr_loop_sprite_width equ $ +2
ld ixl,&00
putspr_loop_width
ld a,(de) ; get one byte of sprite data
inc de ; next
ld l,a ; l = sprite_data=sprite_mask_index
ld a,(bc) ; get background_data
and (hl) ; sprite_mask and background_data
or l ; (sprite_mask and background_data) or sprite_data