-
Notifications
You must be signed in to change notification settings - Fork 37
/
PCRLIB_A.ASM
2439 lines (1975 loc) · 43.7 KB
/
PCRLIB_A.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
; The 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.
IDEAL
MODEL SMALL,C
;
;offsets into .SPK file at segment SPKRfile, offset 0
;
;sound records each take up 16 bytes, and start at $10, and continue to $3F0
snd_start equ 0
snd_priority equ 2
snd_samples equ 3
snd_name equ 4
;
; EGA registers
;
SCindex equ 3C4h
SCmapmask equ 2
GCindex equ 3CEh
GCmode equ 5
DATASEG
;
; stuff for pics and sprites
;
STRUC picstruct ; sprite info extracted by refresh
width dw ?
height dw ?
shapeptr dw ?
ENDS
EXTRN pictable: picstruct ; array of picture info
EXTRN charptr:WORD
EXTRN tileptr:WORD
EXTRN picptr:WORD
EXTRN spriteptr:WORD ;paraligned pointers
EXTRN grmode:WORD
EXTRN crtcaddr:WORD
;
; stuff for pics and sprites
;
STRUC picstruct ; sprite info extracted by refresh
width dw ?
height dw ?
shapeptr dw ?
ENDS
EXTRN imageinfo: picstruct ; array of picture info
SPKactive dw 0 ;set non zero when started
SoundData dd ? ;two word pointer to SPKR file, PARA aligned
soundmode dw 1 ;0=nosound, 1=SPKR, 2= adlib...
OldInt8 dd ? ;StartupSPK saves here, Shutdown restores
ExtraInts db ? ;number of PlaySPKR's to a regular int 8
Intcount db ? ;counter for extraints, call OldInt8 at 0
sndspeed dw ? ;timer count speed
SndPtr dw ? ;Pointer to frequency of current sound
SndPriority db ? ;current sound's priority
pausesndptr dw ?
pausepriority db ?
pauseextraints db ?
pauseintcount db ?
pausespeed dw ?
_dontplay dw 0 ;set to 1 to avoid all interrupt and timer stuff
xormask dw 0 ;to invert characters
_yshift dw 0 ;to shift char lines
screenseg dw 0a000h ;changes with grmode, page flips, & scrolls
PUBLIC soundmode,SoundData,xormask,screenseg,_dontplay
CODESEG
PUBLIC CGAylookup,EGAylookup,VGAylookup
;========
;
; YLOOKUP has the offsets from screen mem of each screen line (multiples of 8)
;
;========
CGAylookup dw 0,8192, 80,8272, 160,8352, 240,8432, 320,8512, 400,8592, 480,8672
dw 560,8752, 640,8832, 720,8912, 800,8992, 880,9072, 960,9152,1040,9232
dw 1120,9312,1200,9392,1280,9472,1360,9552,1440,9632,1520,9712,1600,9792
dw 1680,9872,1760,9952,1840,10032,1920,10112,2000,10192,2080,10272,2160,10352
dw 2240,10432,2320,10512,2400,10592,2480,10672,2560,10752,2640,10832,2720,10912
dw 2800,10992,2880,11072,2960,11152,3040,11232,3120,11312,3200,11392,3280,11472
dw 3360,11552,3440,11632,3520,11712,3600,11792,3680,11872,3760,11952,3840,12032
dw 3920,12112,4000,12192,4080,12272,4160,12352,4240,12432,4320,12512,4400,12592
dw 4480,12672,4560,12752,4640,12832,4720,12912,4800,12992,4880,13072,4960,13152
dw 5040,13232,5120,13312,5200,13392,5280,13472,5360,13552,5440,13632,5520,13712
dw 5600,13792,5680,13872,5760,13952,5840,14032,5920,14112,6000,14192,6080,14272
dw 6160,14352,6240,14432,6320,14512,6400,14592,6480,14672,6560,14752,6640,14832
dw 6720,14912,6800,14992,6880,15072,6960,15152,7040,15232,7120,15312,7200,15392
dw 7280,15472,7360,15552,7440,15632,7520,15712,7600,15792,7680,15872,7760,15952
dw 7840,16032,7920,16112
EGAylookup dw 0, 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 520
dw 560, 600, 640, 680, 720, 760, 800, 840, 880, 920, 960,1000,1040,1080
dw 1120,1160,1200,1240,1280,1320,1360,1400,1440,1480,1520,1560,1600,1640
dw 1680,1720,1760,1800,1840,1880,1920,1960,2000,2040,2080,2120,2160,2200
dw 2240,2280,2320,2360,2400,2440,2480,2520,2560,2600,2640,2680,2720,2760
dw 2800,2840,2880,2920,2960,3000,3040,3080,3120,3160,3200,3240,3280,3320
dw 3360,3400,3440,3480,3520,3560,3600,3640,3680,3720,3760,3800,3840,3880
dw 3920,3960,4000,4040,4080,4120,4160,4200,4240,4280,4320,4360,4400,4440
dw 4480,4520,4560,4600,4640,4680,4720,4760,4800,4840,4880,4920,4960,5000
dw 5040,5080,5120,5160,5200,5240,5280,5320,5360,5400,5440,5480,5520,5560
dw 5600,5640,5680,5720,5760,5800,5840,5880,5920,5960,6000,6040,6080,6120
dw 6160,6200,6240,6280,6320,6360,6400,6440,6480,6520,6560,6600,6640,6680
dw 6720,6760,6800,6840,6880,6920,6960,7000,7040,7080,7120,7160,7200,7240
dw 7280,7320,7360,7400,7440,7480,7520,7560,7600,7640,7680,7720,7760,7800
dw 7840,7880,7920,7960,8000,8040,8080,8120,8160,8200,8240,8280,8320,8360
dw 8400,8440,8480,8520,8560,8600,8640,8680,8720,8760,8800,8840,8880,8920
dw 8960,9000,9040,9080,9120,9160,9200,9240,9280,9320,9360,9400,9440,9480
dw 9520,9560,9600,9640,9680,9720,9760,9800,9840,9880,9920,9960,10000,10040
dw 10080,10120,10160,10200
VGAylookup dw 0, 320, 640, 960,1280,1600,1920,2240,2560,2880,3200,3520,3840,4160
dw 4480,4800,5120,5440,5760,6080,6400,6720,7040,7360,7680,8000,8320,8640
dw 8960,9280,9600,9920,10240,10560,10880,11200,11520,11840,12160,12480,12800,13120
dw 13440,13760,14080,14400,14720,15040,15360,15680,16000,16320,16640,16960,17280,17600
dw 17920,18240,18560,18880,19200,19520,19840,20160,20480,20800,21120,21440,21760,22080
dw 22400,22720,23040,23360,23680,24000,24320,24640,24960,25280,25600,25920,26240,26560
dw 26880,27200,27520,27840,28160,28480,28800,29120,29440,29760,30080,30400,30720,31040
dw 31360,31680,32000,32320,32640,-32576,-32256,-31936,-31616,-31296,-30976,-30656,-30336,-30016
dw -29696,-29376,-29056,-28736,-28416,-28096,-27776,-27456,-27136,-26816,-26496,-26176,-25856,-25536
dw -25216,-24896,-24576,-24256,-23936,-23616,-23296,-22976,-22656,-22336,-22016,-21696,-21376,-21056
dw -20736,-20416,-20096,-19776,-19456,-19136,-18816,-18496,-18176,-17856,-17536,-17216,-16896,-16576
dw -16256,-15936,-15616,-15296,-14976,-14656,-14336,-14016,-13696,-13376,-13056,-12736,-12416,-12096
dw -11776,-11456,-11136,-10816,-10496,-10176,-9856,-9536,-9216,-8896,-8576,-8256,-7936,-7616
dw -7296,-6976,-6656,-6336,-6016,-5696,-5376,-5056,-4736,-4416,-4096,-3776,-3456,-3136
dw -2816,-2496,-2176,-1856
;=======================================================================
;========
;
; StartupSound
;
; Sets up the new INT 8 ISR and various internal pointers.
; Assumes that the calling program has pointer SOUNDDATA to something
; meaningful...
;
;========
PROC StartupSound
PUBLIC StartupSound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
test [SPKactive],0FFFFh ;see if library is active
jne @@started ;library was allready started
@@start:
call NEAR PTR StopSound ;make sure nothing is playing
mov ax,3508h ;call bios to get int 8
int 21h
mov [WORD oldint8],bx
mov ax,es
mov [WORD oldint8+2],ax
mov ax,1
mov [extraints],al ;the timer is still going at the
mov [intcount],al ;normal rate now
push ds
push cs
pop ds
lea dx,[UpdateSPKR]
mov ax,2508h ;call bios to set int 8
int 21h
pop ds
inc [SPKactive] ;sound routines are now active
@@started:
mov ax,1
mov [soundmode],ax ;set soundmode to SPKR
ret
ENDP
;=======================================================================
;========
;
; ShutdownSound
;
;========
PROC ShutdownSound
PUBLIC ShutdownSound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
mov al,36h ;tell the timer chip we are going to
out 43h,al ;change the speed of timer 0
mov al,0 ;system expects 0000 for rate
out 40h,al ;low
out 40h,al ;high
mov ax,[SPKactive]
cmp ax,0
je @@done ;sound library wasn't started...
push ds
mov dx,[WORD Oldint8]
mov ax,[WORD Oldint8+2]
mov ds,ax
mov ax,2508h ;call bios to set int 8
int 21h
pop ds
mov [SPKactive],0 ;sound routines are now inactive
in al,61h ;get peripheral (speaker) port value
and al,11111101b ;turn speaker off
out 61h,al
@@done:
ret
ENDP
;=========================================================================
;===========
;
; PlaySound (soundnum)
;
; If the sound's priority is >= the current priority, SoundPtr, SndPriority,
; and the timer speed are changed
;
;===========
PROC PlaySound playnum:WORD
PUBLIC PlaySound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
mov ax,[playnum] ;index into the sound headers
push si
mov si,ax
shl si,1
shl si,1
shl si,1
shl si,1
mov ax,[WORD SoundData+2]
mov es,ax ;point es: to the spkr file
mov al,[es:si+snd_Priority] ;priority table (one byte each)
cmp al,[SndPriority]
jb @@playdone ;current sound has higher priority
mov [SndPriority],al
mov ax,[es:si+snd_Start] ;offset in .SPK file
mov [SndPtr],ax ;store it in the sound playing table
mov bl,[es:si+snd_samples] ;samples / regular timer tick (1-255)
mov [extraints],bl ;an OldInt8 will be called after this
mov [intcount],bl ;many UpdateSPKR times have been called
cmp bl,1 ;sample rate of 0 or 1 = 0000 for timer
ja @@oktodiv
xor bx,bx
jmp @@settimer
@@oktodiv:
xor bh,bh
xor ax,ax
mov dx,1
div bx ;$10000 / samples = timer rate
mov bx,ax
mov [sndspeed],bx ;save off the timer rate
@@settimer:
mov al,36h ;tell the timer chip we are going to
out 43h,al ;change the speed of timer 0
mov al,bl ;low byte of sample rate
out 40h,al
mov al,bh ;high byte of sample rate
out 40h,al
@@playdone:
pop si
ret
ENDP
;======================================================================
;===========
;
; StopSound
;
;===========
PROC StopSound
PUBLIC StopSound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
xor ax,ax ;set to 0
mov [SndPtr],ax
mov [SndPriority],al
mov [sndspeed],ax
in al,61h ;get peripheral (speaker) port value
and al,11111101b ;turn speaker off
out 61h,al
mov al,36h ;tell the timer chip we are going to
out 43h,al ;change the speed of timer 0
mov al,0 ;back to normal clock speed
out 40h,al
out 40h,al
inc al
mov [extraints],al ;one bios int / int8
mov [intcount],al
ret
ENDP
;======================================================================
;===========
;
; PauseSound
;
;===========
PROC PauseSound
PUBLIC PauseSound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
mov ax,[SndPtr] ;save off the current values
mov [pausesndptr],ax
mov al,[SndPriority]
mov [pausepriority],al
mov al,[extraints]
mov [pauseextraints],al
mov al,[intcount]
mov [pauseintcount],al
mov ax,[sndspeed]
mov [pausespeed],ax
call StopSound
ret
ENDP
;======================================================================
;===========
;
; ContinueSound
;
;===========
PROC ContinueSound
PUBLIC ContinueSound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
mov ax,[pausesndptr]
mov [SndPtr],ax ;restore the old values
mov al,[pausepriority]
mov [SndPriority],al
mov al,[pauseextraints]
mov [extraints],al
mov al,[pauseintcount]
mov [intcount],al
mov bx,[pausespeed]
mov al,36h ;tell the timer chip we are going to
out 43h,al ;change the speed of timer 0
mov al,bl ;low byte of sample rate
out 40h,al
mov al,bh ;high byte of sample rate
out 40h,al
ret
ENDP
;======================================================================
;========
;
; WaitendSound
; Just waits around until the current sound stops playing
;
;========
PROC WaitEndSound
PUBLIC WaitEndSound
test [_dontplay],0ffffh
je @@dowork
ret
@@dowork:
pushf
call FAR PTR UpdateSPKR ;in case a sound was just started and hasn't
;been hit by an INT yet
@@wait:
mov ax,[sndptr]
cmp ax,0 ;when the ptr is 0, nothing is on
jne @@wait
ret
ENDP
;=========================================================================
;========
;
; UpdateSPKR
; only called by interrupt $8!
;
;=========
PROC UpdateSPKR FAR
push ax
push bx
push cx
push si
push ds
push es
mov ax,_DATA
mov ds,ax ;ds to this data segment
mov ax,[WORD SoundData+2]
mov es,ax ;es to sound file
mov al,20h
out 20h,al ;we got the interrupt here
dec [intcount] ;see if it is time for a BIOS int 8...
jne @@dosounds
mov al,[extraints]
mov [intcount],al ;reset interrupt counter
pushf ;so the IRET from bios returns right
call [OldInt8] ;call the old BIOS timer routine
@@dosounds:
;
; play the speaker
;
mov si,[SndPtr]
cmp si,0
je @@nosound ;nothing playing
mov bx,[es:si]
inc [SndPtr]
inc [SndPtr]
cmp bx,0
je @@nosound ;a zero frequency is no sound, but don't stop
cmp bx,-1 ;a -1 frequency is end of sound
jne @@playfreq
call StopSound
jmp @@doneplay
@@nosound:
in al,61h ;get peripheral (speaker) port value
and al,11111100b ;turn speaker off
out 61h,al
jmp @@doneplay
@@playfreq:
test [soundmode],0FFh ;if soundon=0, don't play anything
je @@nosound
mov al,10110110b ;write to channel 2 (speaker) timer
out 43h,al
mov al,bl
out 42h,al ;low byte
mov al,bh
out 42h,al ;high byte
in al,61h ;get peripheral (speaker) port value
or al,00000011b ;turn speaker on to timer
out 61h,al
@@doneplay:
pop es
pop ds
pop si
pop cx
pop bx
pop ax
iret
ENDP
;==========================================================================
;========================================================================
DATASEG
rndindex dw ?
rndtable db 0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66
db 74, 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36
db 95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188
db 52, 140, 202, 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224
db 149, 104, 25, 178, 252, 182, 202, 182, 141, 197, 4, 81, 181, 242
db 145, 42, 39, 227, 156, 198, 225, 193, 219, 93, 122, 175, 249, 0
db 175, 143, 70, 239, 46, 246, 163, 53, 163, 109, 168, 135, 2, 235
db 25, 92, 20, 145, 138, 77, 69, 166, 78, 176, 173, 212, 166, 113
db 94, 161, 41, 50, 239, 49, 111, 164, 70, 60, 2, 37, 171, 75
db 136, 156, 11, 56, 42, 146, 138, 229, 73, 146, 77, 61, 98, 196
db 135, 106, 63, 197, 195, 86, 96, 203, 113, 101, 170, 247, 181, 113
db 80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112, 166, 103, 241
db 24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, 143, 224
db 145, 224, 81, 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95
db 28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226
db 71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36
db 17, 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106
db 197, 242, 98, 43, 39, 175, 254, 145, 190, 84, 118, 222, 187, 136
db 120, 163, 236, 249
;
; 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
CODESEG
;=================================================
;
; Init RND generator
; if randomize is false, the counter is set to 0
;
; 11-Sep-90 LR FIX initialization to use TIME!
;=================================================
PROC initrnd randomize:word
public initrnd
push si
push di
mov ax,ds
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)
mov [LastRnd],0
mov [indexi],17*2
mov [indexj],5*2
mov ax,[randomize]
cmp ax,0
je @@setit ;if randomize is true, really random
mov ah,2ch
int 21h ;GetSystemTime
mov [RndArray+34-2],dx
xor dx,cx ;init w/seconds values
mov [RndArray+10-2],dx
@@setit:
mov ax,0ffffh
push ax
call Random ;warm up generator!
pop ax
pop di
pop si
ret
ENDP
;=================================================
;
; Return a random # between 0-?
; Exit : AX = 0-max value
;
; 11-Sep-90 LR -modify to save registers!
;=================================================
PROC random maxval:WORD
public random
push si
push bx ;save registers so we work OK!
push cx
push dx
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:
mov bx,[indexi] ;this routine was converted from
mov si,[indexj] ;the Random macro on Merlin GS
mov ax,[RndArray-2+bx]
adc ax,[RndArray-2+si]
mov [RndArray-2+bx],ax
add ax,[LastRnd]
mov [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 [indexi],bx
mov [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:
pop dx
pop cx ;restore registers
pop bx
pop si
ret
ENDP
;===========================================================================
;=================================================
;
; Init table based RND generator
; if randomize is false, the counter is set to 0
;
;=================================================
PROC initrndt randomize:word
uses si,di
public initrndt
mov ax,[randomize]
cmp ax,0
; jne @@timeit ;if randomize is true, really random
mov dx,0 ;set to a definate value
jmp @@setit
@@timeit:
mov ah,2ch
int 21h ;GetSystemTime
and dx,0ffh
@@setit:
mov [rndindex],dx
ret
ENDP
;=================================================
;
; Return a random # between 0-255
; Exit : AX = value
;
;=================================================
PROC rndt
public rndt
mov bx,[rndindex]
inc bx
and bx,0ffh
mov [rndindex],bx
mov al,[rndtable+BX]
xor ah,ah
ret
ENDP
;===========================================================================
;========
;
; WAITVBL
;
;========
PROC WaitVBL
PUBLIC WaitVBL
push si
push di
mov dx,[crtcaddr]
add dx,6
waitvbl1:
in al,dx
test al,00001000b ;look for vbl
jnz waitvbl1
waitvbl2:
in al,dx
test al,00001000b ;look for vbl
jz waitvbl2
pop di
pop si
ret
ENDP
;=======================================================================
;====================
;
; EGAplane
; Sets read/write mode 0 and selects the given plane (0-3)
; for reading and writing
;
;====================
PROC EGAplane plane:WORD
PUBLIC EGAplane
mov dx,GCindex
mov ax,GCmode
out dx,ax ;set read / write mode 0
mov dx,GCindex
mov al,4 ;read map select
mov ah,[BYTE plane] ;read from this plane number
out dx,ax
mov dx,SCindex
mov al,SCmapmask
mov ah,1
mov cl,[BYTE plane] ;write to this plane only
shl ah,cl
out dx,ax
ret
ENDP
;=======================================================================
;====================
;
; EGAlatch
; Sets write mode 1 with all planes selected
;
;====================
PROC EGAlatch plane:WORD
PUBLIC EGAlatch
mov dx,GCindex
mov ax,1*256 + GCmode
out dx,ax ;set read 0 / write mode 1
mov dx,SCindex
mov ax,15*256 + SCmapmask ;write to all planes
out dx,ax
ret
ENDP
;=======================================================================
;============
;
; drawchar
; Calls CGAcharout / EGAcharout / VGAcharout
; based on grmode
;
;============
PROC drawchar xcoordinate:WORD, ycoordinate:WORD, char:WORD
PUBLIC drawchar
push si
push di
mov ax,[screenseg]
mov es,ax
mov si,[char] ;low level routines get stuff in registers
mov di,[xcoordinate]
mov bx,[ycoordinate]
shl bx,1
shl bx,1
shl bx,1
shl bx,1
add bx,[_yshift] ;allow printing on non-char lines
mov ax,[grmode]
cmp ax,1 ;CGA mode
jne @@notcga
call CgaCharout
pop di
pop si
ret
@@notcga:
cmp ax,2 ;EGA mode
jne @@notega
call EgaCharout
pop di
pop si
ret
@@notega:
cmp ax,3 ;VGA mode
jne @@done
call VgaCharout
@@done:
pop di
pop si
ret
ENDP
;===========================================================================
;============
;
; CGAcharout
; SI= character; DI= xcoordinate; BX= ycoordinate*2
;
;============
PROC CgaCharOut
shl si,1
shl si,1
shl si,1
shl si,1 ;char * 16 = tile's offset in PICS
shl di,1 ;x * 2 + ylookup[y] = screen location
add di,[CGAylookup+bx] ;BX is pointer into YLOOKUP
mov bx,[xormask] ;so chars can be inverted
mov ax,[WORD charptr+2]
mov ds,ax ;segment of tile pictures (PARA'd)
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,_DATA
mov ds,ax ;restore turbo's data segment
ret
ENDP
;=======================================================================
;============
;
; EGAcharout
; SI= character; DI= xcoordinate; BX= ycoordinate
;
;============
PROC EgaCharOut
shl si,1
shl si,1
shl si,1 ;char * 8 = tile's offset in PICS
add di,[EGAylookup+bx] ;BX is pointer into YLOOKUP
mov cx,ds
mov dx,GCindex
mov ax,GCmode
out dx,ax ;set read / write mode 0
cld
mov bx,si ;so the planes can be drawn the same
mov cx,di