forked from CatacombGames/Catacomb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CATASM.ASM
2265 lines (1807 loc) · 50.4 KB
/
CATASM.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
; Catacomb Source Code
; Copyright (C) 1993-2014 Flat Rock Software
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License along
; with this program; if not, write to the Free Software Foundation, Inc.,
; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
MASM
locals
.MODEL TPASCAL
.DATA
EXTRN pics,xormask:WORD
EXTRN oldtiles, view, background, originx, originy: WORD
EXTRN priority: BYTE
objtype STRUC
active db ?
class db ?
x db ?
y db ?
stage db ?
delay db ?
dir db ?
hp db ?
oldx db ?
oldy db ?
oldtile dw ?
filler1 db ?,?,?,?
think db ?
contact db ?
solid db ?
firstchar dw ?
psize db ?
stages db ?
dirmask db ?
speed dw ?
hitpoints db ?
damage db ?
points dw ?
filler2 db ?,?
objtype ENDS
EXTRN obj, altobj: objtype
obp dw ? ;temporary for turbo's BP
;
; rle STUFF
;
MinCnt = 3-1 ;min count for repeat
MaxCnt = 127+MinCnt ;max count (128+ = non repeat string)
handle dw ? ;file i/o requirements are here!
flength1 dw ?
flength2 dw ?
buf1 dw ?
buf2 dw ?
foff1 dw ?
foff2 dw ?
; We store our memory allocation results here
RLESeg dw ? ;RLE packed buf (src/dest)
SrcSeg dw ? ;original source data
RLEIdx dw ? ;indexes for read/write bufs
SRCIdx dw ?
SrcLen dw 2 dup (?) ;length of source & dest bufs
RLELen dw 2 dup (?)
ByteCnt dw ? ;# of sequential bytes
LastByte db ? ;last byte found
DifCnt dw ? ;# of different bytes
EndByte dw ?
.CODE
;========================================================================
;{=========================================}
;{ }
;{ DRAWOBJ }
;{ Draws the object to TILES in the proper }
;{ direction and state. }
;{ }
;{=========================================}
;
;Procedure DrawObj;
;var
; objpri,bsize,tilenum:integer;
;Begin
; tilenum:=obj.firstchar + obj.size * obj.size
; *((integer(obj.dir) and obj.dirmask) * obj.stages + obj.stage);
; obj.oldtile:= tilenum;
; obj.oldx:=obj.x;
; obj.oldy:=obj.y;
; objpri:=priority[tilenum];
; For y:=obj.y to obj.y+obj.size-1 do
; for x:=obj.x to obj.x+obj.size-1 do
; Begin
; if priority[view[y,x]]<=objpri then
; view[y,x]:=tilenum;
; inc(tilenum);
; end;
;End;
;
;
squares db 0,1,4,9,16,25,36,49,64
table86 dw 0, 86, 172, 258, 344, 430, 516, 602, 688, 774, 860, 946,1032,1118
dw 1204,1290,1376,1462,1548,1634,1720,1806,1892,1978,2064,2150,2236,2322
dw 2408,2494,2580,2666,2752,2838,2924,3010,3096,3182,3268,3354,3440,3526
dw 3612,3698,3784,3870,3956,4042,4128,4214,4300,4386,4472,4558,4644,4730
dw 4816,4902,4988,5074,5160,5246,5332,5418,5504,5590,5676,5762,5848,5934
dw 6020,6106,6192,6278,6364,6450,6536,6622,6708,6794,6880,6966,7052,7138
dw 7224,7310,7396
DrawObj PROC NEAR
PUBLIC DrawObj
mov al,obj.dir
and al,obj.dirmask
mul obj.stages
add al,obj.stage
mov cl,al
mov bl,obj.psize
xor bh,bh
mov al,cs:[squares+bx]
mul cl
add ax,obj.firstchar
mov SI,ax
mov obj.oldtile,SI ;SI holds the first tile to put in
mov dl,[priority+SI] ;entire object has same priority
;priority is saved in DL
mov bl,obj.y
mov obj.oldy,bl
xor bh,bh
shl bx,1
mov ax,cs:[table86+bx] ;View is 86*86
mov bl,obj.x
mov obj.oldx,bl
xor bh,bh
add ax,bx ;calculate origin's offset in VIEW
shl ax,1 ;becuase view is WORD width
mov di,ax ;DI will point into VIEW
mov al,obj.psize ;throughout loop
xor ah,ah
mov dh,al ;do this many lines
@@yloop:
mov cx,ax ;do this many characters / line
@@xloop:
mov bx,[view+DI]
cmp dl,[priority+bx] ;check tiles priority level
jb @@next ;don't draw if lower than what's there
mov [view+di],si
@@next:
inc si
inc di
inc di
loop @@xloop
sub di,ax
sub di,ax
add di,86*2 ;position destination at start of next line
dec dh ;any more lines to do?
jnz @@yloop
ret
DrawObj ENDP
;========================================================================
;{=======================================}
;{ }
;{ ERASEOBJ }
;{ Erases the current object by copying }
;{ the background onto the view where the}
;{ object is standing }
;{ }
;{=======================================}
;
;Procedure EraseObj;
;var
; objpri,bsize,tilenum:integer;
;Begin
; tilenum:=obj.oldtile;
; For y:=obj.oldy to obj.oldy+obj.size-1 do
; for x:=obj.oldx to obj.oldx+obj.size-1 do
; Begin
; if view[y,x]=tilenum then
; view[y,x]:=background[y,x];
; inc(tilenum);
; end;
;End;
;
EraseObj PROC NEAR
PUBLIC EraseObj
mov SI,obj.oldtile ;only erase chars that match what was
;drawn by the last drawobj
mov bl,obj.oldy
xor bh,bh
shl bx,1
mov ax,cs:[table86+bx] ;View is 86*86
mov bl,obj.oldx
xor bh,bh
add ax,bx ;calculate origin's offset in VIEW
shl ax,1 ;becuase view is WORD width
mov di,ax ;DI will point into VIEW
mov al,obj.psize ;throughout loop
xor ah,ah
mov dh,al ;do this many lines
@@yloop:
mov cx,ax ;do this many characters / line
@@xloop:
cmp si,[view+DI]
jne @@next ;don't erase if its not part of the shape
mov bx,[background+di]
mov [view+di],bx ;erase it
@@next:
inc si
inc di
inc di
loop @@xloop
sub di,ax
sub di,ax
add di,86*2 ;position destination at start of next line
dec dh ;any more lines to do?
jnz @@yloop
ret
EraseObj ENDP
;========================================================================
;{====================}
;{ }
;{ DoAll }
;{ The main play loop }
;{ }
;{====================}
;
;Procedure Doall;
;begin
; Repeat {until leveldone or playdone}
; For objecton:=numobj downto 0 do
; Begin
; move (o[objecton],obj.active,sizeof(o[objecton]) );
; if obj.class<>nothing then {class=nothing means it was killed}
; Begin
; move (ObjDef[obj.class],obj.think,sizeof(objdef[obj.class]) );
; if obj.active then
; DoActive
; else
; DoInactive;
; end;
; end;
; refresh;
; inc (frameon);
; until leveldone or playdone;
;end;
.DATA
EXTRN o:objtype
EXTRN ObjDef:WORD ;actually the second half of objtype record
EXTRN frameon:WORD
EXTRN numobj:WORD
EXTRN objecton:WORD
EXTRN leveldone:BYTE
EXTRN playdone:BYTE
.CODE
EXTRN refresh:NEAR
EXTRN DoActive:NEAR
EXTRN DoInactive:NEAR
DoAll PROC NEAR
PUBLIC DoAll
@@repeat:
mov ax,[numobj]
mov [objecton],ax
@@forobjecton:
mov si,[objecton]
shl si,1
shl si,1
shl si,1
shl si,1 ;o[] is 16 bytes wide
add si,OFFSET o
mov di,OFFSET obj
push ds
pop es
movsw
movsw
movsw
movsw
movsw
movsw
movsw
movsw ;copy 16 bytes
mov al,[obj.class]
or al,al
jz @@next
xor ah,ah
mov si,ax
shl si,1
shl si,1
shl si,1
shl si,1 ;objdef is 16 bytes wide
add si,OFFSET objdef
movsw
movsw
movsw
movsw
movsw
movsw
movsw
movsw ;copy second 16 bytes into obj
mov al,[obj.active]
or al,al
jnz @@isactive
call DoInactive
jmp @@next
@@isactive:
call DoActive
@@next:
mov al,[leveldone] ; check end
or al,al
jnz @@done
mov al,[playdone]
or al,al
jnz @@done
dec [objecton]
jns @@forobjecton ; END for
call refresh
inc [frameon]
mov al,[leveldone] ; UNTIL
or al,al
jnz @@done
mov al,[playdone]
or al,al
jz @@repeat
@@done:
ret
DoAll ENDP
;========================================================================
;=================================================
;
; Init RND generator
; if randomize is false, the counter is set to 0
;
;=================================================
InitRnd PROC NEAR randomize:byte
public initrnd
mov al,randomize
cmp al,0
jne @@timeit ;if randomize is true, really random
mov dx,0 ;set to a definate value
mov cx,dx
mov [cs:lastrnd],dx
jmp @@setit
@@timeit:
mov ah,2ch
int 21h ;GetSystemTime
@@setit:
mov [cs:RndArray],dx
mov [cs:RndArray+2],cx
mov ax,17*2
mov [cs:indexi],ax
mov ax,5*2
mov [cs:indexj],ax
push ds
push es
mov ax,cs
mov ds,ax
mov es,ax
mov di,offset RndArray
mov si,offset baseRndArray
mov cx,17
cld
rep movsw ;set up the table (which is constantly changed)
pop es
pop ds
mov ax,0ffffh
push ax
call Random ;warm up generator!
mov ax,0ffffh
push ax
call Random
ret
initrnd ENDP
;=================================================
;
; Return a random # between 0-?
; Exit : AX = 0-max value
;
;=================================================
random PROC NEAR maxval:WORD
public random
mov ax,maxval
push ax ;save max value
;
; create a mask to cut down on the # of SUBTRACTS!
;
mov dx,0ffffh ;full-mask
@@0: shl ax,1
jc @@0a
shr dx,1
jmp @@0
@@0a:
pop ax
push ax
mov bx,[cs:indexi] ;this routine was converted from
mov si,[cs:indexj] ;the Random macro on Merlin GS
mov ax,[cs:RndArray-2+bx]
adc ax,[cs:RndArray-2+si]
mov [cs:RndArray-2+bx],ax
add ax,[cs:LastRnd]
mov [cs:LastRnd],ax
dec bx
dec bx
jne @@1
mov bx,17*2
@@1:
dec si
dec si
jne @@2
mov si,17*2
@@2:
mov [cs:indexi],bx
mov [cs:indexj],si
pop cx ;loop -- returns value in range
and ax,dx ;AND our mask!
@@3:
cmp ax,cx ;SUBTRACT to be within range
jbe @@4
shr ax,1
@@4:
ret
random ENDP
;
; Random # Generator vars
;
indexi dw ? ;Rnd#Generator
indexj dw ?
LastRnd dw ?
RndArray dw 17 dup (?)
baseRndArray dw 1,1,2,3,5,8,13,21,54,75,129,204
dw 323,527,850,1377,2227
;===========================================================================
;========
;
; WAITVBL
;
;========
WaitVBL PROC NEAR
PUBLIC WaitVBL
mov dx,3dah
waitvbl1:
in al,dx
and al,00001000b ;look for vbl
jnz waitvbl1
waitvbl2:
in al,dx
and al,00001000b ;look for vbl
jz waitvbl2
ret
WaitVBL ENDP
;=======================================================================
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
;
; Move EGA tiles into EGA memory at "EGATileLoc"!
;
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
EGAMove PROC NEAR
PUBLIC EGAMove
mov dx,3c4h ;turn MapMask register on!
mov al,2
out dx,al
inc dx
mov ax,0A200h
mov es,ax ;ES:DI = just after screen in latch memory
xor di,di
mov ax,WORD PTR [pics+2]
mov ds,ax
xor si,si ;DS:SI = start of tiles!
cld
mov cx,2048
@@0:
mov ah,1b ;start at bitplane 0
mov bx,di
@@2:
mov al,ah
out dx,al ;select new bitplane!
movsb
movsb
movsb
movsb
movsb
movsb
movsb
movsb
mov di,bx
shl ah,1
test ah,1111b
jnz @@2 ;do all bitplanes in shape
add di,8
loop @@0 ;do all tiles
mov al,1111b
out dx,al ;select all bitplanes
mov ax,SEG DATA ;reset DATA segment
mov ds,ax
ret
EGAMove ENDP
;=======================================================================
;============
;
; CGAcharout
;
;============
CgaCharOut PROC NEAR xcoordinate:WORD, ycoordinate:WORD, char:WORD
PUBLIC CgaCharOut
mov si,char
shl si,1
shl si,1
shl si,1
shl si,1 ;char * 16 = tile's offset in PICS
mov di,xcoordinate
shl di,1 ;x * 2 + ylookup[y] = screen location
mov bx,ycoordinate
shl bx,1
add di,cs:CGAylookup[bx] ;BX is pointer into YLOOKUP
mov bx,[xormask] ;so chars can be inverted
mov ax,[pics+2]
mov ds,ax ;segment of tile pictures (PARA'd)
mov ax,0B800h ;segment of screen memory
mov es,ax
cld
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
add di,1FFEh
lodsw
xor ax,bx
stosw
sub di,1FB2h
lodsw
xor ax,bx
stosw
add di,1FFEh
lodsw
xor ax,bx
stosw
sub di,1FB2h
lodsw
xor ax,bx
stosw
add di,1FFEh
lodsw
xor ax,bx
stosw
sub di,1FB2h
lodsw
xor ax,bx
stosw
add di,1FFEh
lodsw
xor ax,bx
stosw
mov ax,SEG DATA
mov ds,ax ;restore turbo's data segment
ret
CgaCharOut ENDP
;=======================================================================
;============
;
; EGAcharout
;
;============
EgaCharOut PROC NEAR xcoordinate:WORD, ycoordinate:WORD, char:WORD
PUBLIC EgaCharOut
mov si,char
mov bx,[xormask] ;so chars can be inverted
or bx,bx ;set flags
je notinv
cmp si,32
jne notspc
mov si,129
jmp notinv
notspc: add si,32 ;make the other set...
notinv:
shl si,1
shl si,1
shl si,1 ;char * 8 = tile's offset in PICS
add si,2000h ;because the screen is in first part
mov di,xcoordinate ;x * + ylookup[y] = screen location
mov bx,ycoordinate
shl bx,1
add di,cs:EGAylookup[bx] ;BX is pointer into YLOOKUP
mov cx,ds
mov ax,0A000h ;segment of screen memory
mov es,ax
mov ds,ax ;tile pictures are also in screen memory
mov ax,105h
mov dx,3ceh ;set write mode 1
out dx,ax
cld
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
add di,39
lodsb ;load in a row of the tile's picture
stosb
mov ax,SEG DATA
mov ds,cx ;restore turbo's data segment
ret
EgaCharOut ENDP
;=======================================================================
;============
;
; VGAcharout
;
;============
VgaCharOut PROC NEAR xcoordinate:WORD, ycoordinate:WORD, char:WORD
PUBLIC VgaCharOut
mov si,char
shl si,1
shl si,1
shl si,1
shl si,1
shl si,1
shl si,1 ;char * 64 = tile's offset in PICS
mov di,xcoordinate
shl di,1
shl di,1
shl di,1 ;x * 8 + ylookup[y] = screen location
mov bx,ycoordinate
shl bx,1
add di,cs:VGAylookup[bx] ;BX is pointer into YLOOKUP
mov bx,[xormask] ;so chars can be inverted
mov ax,[pics+2]
mov ds,ax ;segment of tile pictures (PARA'd)
mov ax,0A000h ;segment of screen memory
mov es,ax
cld
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
add di,312
lodsw ;load in a row of the tile's picture
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
lodsw
xor ax,bx
stosw
mov ax,SEG DATA
mov ds,ax ;restore turbo's data segment
ret
VgaCharOut ENDP
;===========================================================================
;========
;
; YLOOKUP has the offsets from screen mem of each screen line (multiples of 8)
;
;========
CGAylookup label word
EGAylookup label word ;they are the same because of CGA's interleave
dw 320*0,320*1,320*2,320*3,320*4,320*5,320*6,320*7
dw 320*8,320*9,320*10,320*11,320*12,320*13,320*14,320*15
dw 320*16,320*17,320*18,320*19,320*20,320*21,320*22,320*23,320*24
VGAylookup label word
dw 2560*0,2560*1,2560*2,2560*3,2560*4,2560*5,2560*6,2560*7
dw 2560*8,2560*9,2560*10,2560*11,2560*12,2560*13,2560*14,2560*15
dw 2560*16,2560*17,2560*18,2560*19,2560*20,2560*21,2560*22,2560*23
dw 2560*24
;=======================================================================
;=========
;
; CGAREFRESH redraws the tiles that have changed in the tiled screen area
;
;=========
CgaRefresh PROC NEAR
PUBLIC CgaRefresh
mov obp,bp ;save off turbo's BP
mov ax,0B800h ;start of CGA memory
mov es,ax
cld ;just in case
mov cx,OFFSET @@next ;so it can be JMPd to
mov ax,originy
mov bl,86 ;View is 86*86 so no clipping
mul bl
add ax,originx ;calculate origin's offset in VIEW
shl ax,1 ;becuase view is WORD width
mov bp,ax ;BP will point into VIEW
mov dx,ax
add dx,48 ;when BP=DX, one row has been filled
xor bx,bx ;fast mov bx,0
@@check:
mov ax,view[bp] ;load the current tile
cmp ax,oldtiles[bx] ;compare it with the old tile
jne @@drawone ;if different, redraw
@@next:
add bx,2 ;next oldtile
add bp,2 ;next view tile
cmp bp,dx ;has an entire row from VIEW been drawn?
jne @@check
cmp bx,24*24*2 ;have all tiles been drawn?
je @@done
add bp,124 ;point it to the start of the next row
add dx,172 ;point to end of next row
jmp @@check
@@done:
mov bp,obp ;restore turbo's BP
ret
@@drawone:
mov oldtiles[bx],ax ;store the tile back to the oldtiles
mov di,word ptr cs:CGAtileloc[bx] ;set di to screen address
shl ax,1 ;character number * 16 = start of data
shl ax,1
shl ax,1
shl ax,1
mov si,ax
mov ds,[pics+2] ;segment of pics (para aligned)
movsw ;load in a row of the tile's picture
add di,1FFEh
movsw
sub di,1FB2h