1;Copyright (c) 1990-2012 by Neil Dodwell
2;Released with permission from Neil Dodwell under GPLv2
3;See LICENSE file for full license text
4Screenwidth	equ	320		;physical width of screen
5
6
7
8Allocatework	proc	near
9
10	mov	bx,1000h
11	call	allocatemem
12	mov	workspace,ax
13	ret
14
15	endp
16
17
18
19
20
21Showpcx	proc	near
22
23	call	openfile
24	mov	bx,handle
25	mov	ds,workspace
26	mov	ah,3fh
27	mov	cx,128
28	mov	dx,0
29	int	21h
30
31	mov	ds,workspace
32	mov	si,16
33	mov	cx,48
34	mov	es,buffers
35	mov	di,maingamepal
36pcxpal:	push	cx
37	call	readabyte
38	shr	al,1
39	shr	al,1
40	stosb
41	pop	cx
42	loop	pcxpal
43	mov	cx,768-48
44	mov	ax,0ffffh
45	rep	stosw
46
47	call	readoneblock
48	mov	si,0
49	mov	di,0
50	mov	cx,480
51convertpcx:	push	cx
52	push	di
53	mov	ds,workspace
54	mov	es,buffers
55	mov	di,pointerback
56	mov	bx,0
57sameline:	call	readabyte
58	mov	ah,al
59	and	ah,11000000b
60	cmp	ah,11000000b
61	jnz	normal
62	mov	cl,al
63	and	cl,00111111b
64	mov	ch,0
65	push	cx
66	call	readabyte
67	pop	cx
68	add	bx,cx
69	rep	stosb
70	cmp	bx,4*80
71	jnz	sameline
72	jmp	endline
73normal:	stosb
74	inc	bx
75	cmp	bx,4*80
76	jnz	sameline
77
78endline:	pop	di
79	push	si
80	mov	dx,0a000h
81	mov	es,dx
82	mov	si,pointerback
83	mov	ds,buffers
84
85	mov	dx,03c4h
86	mov	al,2
87	mov	ah,1
88	out	dx,ax
89	mov	cx,40
90	push	di
91	rep	movsw
92	pop	di
93	mov	ah,2
94	out	dx,ax
95	mov	cx,40
96	push	di
97	rep	movsw
98	pop	di
99	mov	ah,4
100	out	dx,ax
101	mov	cx,40
102	push	di
103	rep	movsw
104	pop	di
105	mov	ah,8
106	out	dx,ax
107	mov	cx,40
108	rep	movsw
109
110	pop	si
111	pop	cx
112	loop	convertpcx
113
114	mov	bx,handle
115	call	closefile
116	ret
117
118	endp
119
120
121
122
123Readabyte	proc	near
124
125	cmp	si,30000
126	jnz	notendblock
127	push	bx es di ds si
128	call	readoneblock
129	pop	si ds di es bx
130	mov	si,0
131notendblock:	lodsb
132	ret
133
134	endp
135
136
137
138
139Readoneblock	proc	near
140
141	mov	bx,handle
142	mov	ah,3fh
143	mov	ds,workspace
144	mov	ah,3fh
145	mov	cx,30000
146	mov	dx,0
147	int	21h
148	ret
149
150	endp
151
152
153
154
155
156
157
158
159Loadpalfromiff	proc	near
160
161	mov	dx,offset cs:palettescreen
162	call	openfile
163	mov	cx,2000
164	mov	ds,mapstore
165	mov	dx,0
166	call	readfromfile
167	call	closefile
168	mov	es,buffers
169	mov	di,maingamepal
170	mov	ds,mapstore
171	mov	si,30h
172	mov	cx,768
173palloop:	lodsb
174	shr	al,1
175	shr	al,1
176
177	cmp	brightness,1
178	jnz	nought
179	cmp	al,0
180	jz	nought
181       	mov	ah,al
182	shr	ah,1
183	add	al,ah
184	shr	ah,1
185	add	al,ah
186	cmp	al,64
187	jc	nought
188	mov	al,63
189
190nought:	stosb
191	loop	palloop
192	ret
193
194	endp
195
196
197
198
199
200
201Setmode	proc	near
202
203	call	vsync
204	mov	ah,12h
205	mov	al,1
206	mov	bl,33h
207	int	10h
208
209	mov	ah,0
210	mov	al,13h
211	int	10h
212
213	mov	al,6	; sets graphic controller
214	mov	dx,3ceh 	; register 6 (MM) to 1 - 64K
215	out	dx,al
216	inc	dx
217	in	al,dx
218	and	al,11110011b
219	or	al,00000100b
220	out	dx,al
221
222	mov	al,4	; sets sequencer
223	mov	dx,3c4h 	; register 4 (EM) to 1 - >64K
224	out	dx,al
225	inc	dx
226	in	al,dx
227	and	al,11111101b
228	or	al,00000010b
229	out	dx,al
230
231	mov	al,13h		;give screen 16 extra hidden
232	mov	dx,3d4h 		;pixels at one side
233	out	dx,al
234	inc	dx
235	mov	al,screenwidth/8 ; width of screen
236	out	dx,al
237
238	mov	al,8h
239	mov	dx,3d4h
240	out	dx,al
241	inc	dx
242	mov	al,00000000b
243	out	dx,al
244
245	mov	al,11h
246	mov	dx,3d4h
247	out	dx,al
248	inc	dx
249	in	al,dx
250	or	al,128
251	out	dx,al
252
253	mov	al,00
254	mov	dx,3d4h
255	out	dx,al
256	inc	dx
257	mov	al,3fh
258	out	dx,al
259	mov	al,01
260	mov	dx,3d4h
261	out	dx,al
262	inc	dx
263	mov	al,3fh
264	out	dx,al
265	ret
266
267	endp
268
269
270
271Cls	proc	near
272
273	mov	ax,0a000h
274	mov	es,ax
275	mov	di,0
276	mov	cx,7fffh
277	mov	ax,0
278	rep	stosw
279	ret
280
281	endp
282
283
284
285Printundermon	proc	near		;prints workspace through the text
286
287	mov	si,(screenwidth*43)+76
288	mov	di,si
289	mov	es,workspace
290	add	si,8*screenwidth
291	mov	dx,0a000h
292	mov	ds,dx
293	mov	cx,104
294scrollmonloop1: push	cx di si
295	mov	cx,170
296scrollmonloop2: lodsb
297	cmp	al,231
298	jnc	dontplace
299placeit:	stosb
300	loop	scrollmonloop2
301	jmp	finmonscroll
302dontplace:	inc	di
303	loop	scrollmonloop2
304
305finmonscroll:	pop	si di cx
306	add	si,screenwidth
307	add	di,screenwidth
308	loop	scrollmonloop1
309	ret
310
311	endp
312
313
314
315
316
317
318
319
320Worktoscreen	proc	near
321
322	call	vsync
323	mov	si,0
324	mov	di,0
325	mov	cx,25
326	mov	ds,workspace
327	mov	dx,0a000h
328	mov	es,dx
329
330dumpallloop:	call	width160
331	call	width160
332	call	width160
333	call	width160
334	call	width160
335	call	width160
336	call	width160
337	call	width160
338	loop	dumpallloop
339
340	ret
341
342	endp
343
344
345
346
347
348
349
350
351
352;
353;Worktoscreen2	proc	near
354;
355;	call	showpointer
356;
357;	mov	ds,workspace
358;	mov	dx,0a000h
359;	mov	es,dx
360;
361;	mov	si,320-16
362;	mov	di,320-16
363;	mov	bl,33
364;	mov	cx,16
365;screen2loop1:	push	di si cx
366;	call	vsync
367;	cmp	bl,21
368;	jc	screen2loop2
369;	sub	cx,16
370;	jz	isoneblock
371;screen2loop2:	movsw
372;	movsw
373;	movsw
374;	movsw
375;	movsw
376;	movsw
377;	movsw
378;	movsw
379;	add	di,320-15
380;	add	si,320-15
381;	loop	screen2loop2
382;isoneblock:	mov	cx,16
383;	mov	ax,320-15
384;oneblockloop:	push	cx
385;	rep	movsb
386;	pop	cx
387;	add	si,ax
388;	add	di,ax
389;	inc	ax
390;	loop	oneblockloop
391;
392;	pop	cx si di
393;	add	cx,16
394;	cmp	cx,200
395;	jc	itsallright
396;	mov	cx,200
397;itsallright:	sub	si,16
398;	sub	di,16
399;	dec	bl
400;	jnz	screen2loop1
401;
402;	call	delpointer
403;	ret
404;
405;	endp
406;
407;
408;
409;
410
411
412
413
414Paneltomap	proc	near
415
416	mov	di,mapxstart
417	add	di,mapadx
418	mov	bx,mapystart
419	add	bx,mapady
420	mov	ds,mapstore
421	mov	si,0
422	mov	cl,mapxsize
423	mov	ch,mapysize
424	call	multiget
425	ret
426
427	endp
428
429
430
431Maptopanel	proc	near
432
433	mov	di,mapxstart
434	add	di,mapadx
435	mov	bx,mapystart
436	add	bx,mapady
437	mov	ds,mapstore
438	mov	si,0
439	mov	cl,mapxsize
440	mov	ch,mapysize
441	call	multiput
442
443	ret
444
445	endp
446
447
448
449
450
451Dumpmap	proc	near
452
453	mov	di,mapxstart
454	add	di,mapadx
455	mov	bx,mapystart
456	add	bx,mapady
457	mov	cl,mapxsize
458	mov	ch,mapysize
459	call	multidump
460	ret
461
462	endp
463
464
465
466
467Pixelcheckset	proc	near		;al=x, ah=y, es:bx=setlist pos
468				;checks exact pixel in a frame
469	push	ax
470	sub	al,[es:bx]		;for detection.
471	sub	ah,[es:bx+1]		;al,ah now holds offset within
472				;the frame
473	push	es bx cx ax
474	mov	al,[es:bx+4]		;object number
475	call	getsetad
476	mov	al,[es:bx+17]		;finds frame number
477	mov	es,setframes
478	mov	bx,framedata
479	mov	ah,0
480	mov	cx,6
481	mul	cx
482	add	bx,ax		;get data for this frame in es:bx
483	pop	ax
484
485	push	ax
486	mov	al,ah
487	mov	ah,0
488	mov	cl,[es:bx]
489	mov	ch,0
490	mul	cx
491	pop	cx
492	mov	ch,0
493	add	ax,cx		;ax now holds offset from corner
494				;of the frame
495	add	ax,[es:bx+2]
496	mov	bx,ax		;es:bx now holds offset of pixel!
497	add	bx,frames
498
499	mov	al,[es:bx]
500	mov	dl,al
501	pop	cx bx es ax
502	cmp	dl,0
503	ret
504
505	endp
506
507
508
509
510
511
512
513
514
515
516
517
518Createpanel	proc	near
519
520	mov	di,0
521	mov	bx,8
522	mov	ds,icons2
523	mov	al,0
524	mov	ah,2
525	call	showframe ;spritef
526	mov	di,160
527	mov	bx,8
528	mov	ds,icons2
529	mov	al,0
530	mov	ah,2
531	call	showframe ;spritef
532	mov	di,0
533	mov	bx,104
534	mov	ds,icons2
535	mov	al,0
536	mov	ah,2
537	call	showframe ;spritef
538	mov	di,160
539	mov	bx,104
540	mov	ds,icons2
541	mov	al,0
542	mov	ah,2
543	call	showframe ;spritef
544	ret
545
546	endp
547
548
549
550Createpanel2	proc	near
551
552	call	createpanel
553	mov	di,0
554	mov	bx,0
555	mov	ds,icons2
556	mov	al,5
557	mov	ah,2
558	call	showframe
559	mov	di,160
560	mov	bx,0
561	mov	ds,icons2
562	mov	al,5
563	mov	ah,2
564	call	showframe
565	ret
566
567	endp
568
569
570
571
572
573
574;Showspritef	proc	near
575;
576;	mov	ax,bx
577;	mov	bx,screenwidth
578;	mul	bx
579;	add	di,ax
580;	mov	dx,screenwidth
581;	mov	es,workspace
582;	mov	si,2080
583;	mov	ah,0
584;	add	ax,ax
585;	mov	bx,ax
586;	add	ax,ax
587;	add	bx,ax
588;	add	si,[bx+2]
589;	mov	cx,[bx+0]
590;spritefloop:	push	cx di
591;	call	width80
592;	pop	di cx
593;	add	di,dx
594;	dec	ch
595;	jnz	spritefloop
596;	ret
597;
598;	endp
599;
600;
601
602
603
604
605
606
607
608
609Clearwork	proc	near
610
611	mov	ax,0h
612	mov	es,workspace
613	mov	di,0
614	mov	cx,(200*320)/64
615clearloop:	stosw
616	stosw
617	stosw
618	stosw
619	stosw
620	stosw
621	stosw
622	stosw
623	stosw
624	stosw
625	stosw
626	stosw
627	stosw
628	stosw
629	stosw
630	stosw
631	stosw
632	stosw
633	stosw
634	stosw
635	stosw
636	stosw
637	stosw
638	stosw
639	stosw
640	stosw
641	stosw
642	stosw
643	stosw
644	stosw
645	stosw
646	stosw
647	loop	clearloop
648	ret
649
650	endp
651
652
653
654
655
656
657Vsync	proc	near
658
659	push	ax bx cx dx si di ds es
660
661	mov	dx,03dah
662loop2:	in	al,dx
663	test	al,8
664	jz	loop2
665loop1:	in	al,dx
666	test	al,8
667	jnz	loop1
668
669	call	doshake
670	call	dofade
671	if	debuglevel2
672	call	debugkeys
673	endif
674	pop	es ds di si dx cx bx ax
675	ret
676
677	endp
678
679
680
681Doshake	proc	near
682
683	cmp	shakecounter,48
684	jz	finishshake
685            	inc	shakecounter
686	mov	bl,shakecounter
687	mov	bh,0
688	add	bx,offset cs:shaketable
689	mov	al,10h
690	mov	dx,3d4h
691	out	dx,al
692	inc	dx
693	mov	al,[cs:bx]
694	out	dx,al
695finishshake:	ret
696
697shaketable:	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
698	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
699	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
700	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
701	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
702	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
703	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
704	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9eh
705	db	9ch,9ah,9fh,9ah,9ch,9eh,0a0h,9bh,9dh,99h,9fh,9ch
706
707	endp
708
709
710
711
712
713
714Zoom	proc	near
715
716	cmp	watchingtime,0
717	jnz	inwatching
718	cmp	zoomon,1
719	jz	zoomswitch
720inwatching:	ret
721
722zoomswitch:	cmp	commandtype,199
723	jc	zoomit
724cantzoom:	call	putunderzoom
725	ret
726
727zoomit:	mov	ax,oldpointery
728	sub	ax,9
729	mov	cx,screenwidth
730	mul	cx
731	add	ax,oldpointerx
732	sub	ax,11
733	mov	si,ax
734
735	mov	ax,zoomy+4
736	mov	cx,screenwidth
737	mul	cx
738	add	ax,zoomx+5
739	mov	di,ax
740	mov	es,workspace
741	mov	ds,workspace
742
743	mov	cx,20
744zoomloop:	push	cx
745	mov	cx,23
746zoomloop2:	lodsb
747	mov	ah,al
748	stosw
749	mov	[es:di+screenwidth-2],ax
750	loop	zoomloop2
751	add	si,screenwidth-23
752	add	di,screenwidth-46+screenwidth
753	pop	cx
754	loop	zoomloop
755
756	call	crosshair
757	mov	didzoom,1
758	ret
759
760	endp
761
762
763
764
765
766
767
768
769
770Delthisone	proc	near
771
772	push	ax
773	push	ax
774	mov	al,ah
775	mov	ah,0
776	add	ax,mapady
777	mov	bx,screenwidth
778	mul	bx
779	pop	bx
780	mov	bh,0
781	add	bx,mapadx
782	add	ax,bx
783	mov	di,ax
784	pop	ax
785	push	ax
786	mov	al,ah
787	mov	ah,0
788	mov	bx,22*8
789	mul	bx
790	pop	bx
791	mov	bh,0
792	add	ax,bx
793	mov	si,ax
794
795	mov	es,workspace
796	mov	ds,mapstore
797	mov	dl,cl
798	mov	dh,0
799	mov	ax,screenwidth
800	sub	ax,dx
801	neg	dx
802	add	dx,22*8
803deloneloop:	push	cx
804	mov	ch,0
805	rep	movsb
806	pop	cx
807	add	di,ax
808	add	si,dx
809	dec	ch
810	jnz	deloneloop
811	ret
812
813	endp
814
815
816
817
818
819
820
821;------------------------------------------------------------Pointer update----
822
823
824Multiget	proc	near		;di,bx = dest x,y
825				;cl,ch = size
826	mov	ax,bx		;si,di = storage
827	mov	bx,screenwidth
828	mul	bx
829	add	di,ax
830
831	mov	es,workspace
832	push	es ds
833	pop	es ds
834	xchg	di,si
835	mov	al,cl
836	mov	ah,0
837	mov	dx,screenwidth
838	sub	dx,ax
839
840	mov	al,cl
841	and	al,1
842	jnz	oddwidth2
843
844	mov	bl,cl
845	mov	bh,0
846	mov	ax,offset cs:width0
847	shr	bx,1
848	sub	ax,bx
849	mov	cl,ch
850	mov	ch,0
851multiloop3:	call	ax
852	add	si,dx
853	loop	multiloop3
854	ret
855
856oddwidth2:	mov	bl,cl
857	mov	bh,0
858	shr	bx,1
859	mov	ax,offset cs:width0
860	sub	ax,bx
861	mov	cl,ch
862	mov	ch,0
863multiloop4:	call	ax
864	movsb
865	add	si,dx
866	loop	multiloop4
867	ret
868
869	endp
870
871
872
873
874
875
876
877Multiput	proc	near		;di,bx = dest x,y
878				;cl,ch = size
879	mov	ax,bx		;si,di = storage
880	mov	bx,screenwidth
881	mul	bx
882	add	di,ax
883
884	mov	es,workspace
885	mov	al,cl
886	mov	ah,0
887	mov	dx,screenwidth
888	sub	dx,ax
889
890	mov	al,cl
891	and	al,1
892	jnz	oddwidth3
893
894	mov	bl,cl
895	mov	bh,0
896	shr	bx,1
897	mov	ax,offset cs:width0
898	sub	ax,bx
899	mov	cl,ch
900	mov	ch,0
901multiloop5:	call	ax
902	add	di,dx
903	loop	multiloop5
904	ret
905
906oddwidth3:	mov	bl,cl
907	mov	bh,0
908	shr	bx,1
909	mov	ax,offset cs:width0
910	sub	ax,bx
911	mov	cl,ch
912	mov	ch,0
913multiloop6:	call	ax
914	movsb
915	add	di,dx
916	loop	multiloop6
917	ret
918
919
920	endp
921
922
923
924
925
926
927
928
929
930Multidump	proc	near		;di,bx = dest x,y
931				;cl,ch = size
932	mov	dx,0a000h
933	mov	es,dx
934	mov	ds,workspace
935
936	mov	ax,bx
937	mov	bx,screenwidth
938	mul	bx
939	add	di,ax
940	mov	dx,screenwidth
941	mov	si,di
942
943	mov	al,cl
944	and	al,1
945	jnz	oddwidth
946
947	mov	bl,cl
948	mov	bh,0
949	shr	bx,1
950	mov	ax,offset cs:width0
951	sub	ax,bx
952	mov	bl,cl
953	mov	bh,0
954	neg	bx
955	add	bx,dx
956	mov	cl,ch
957	mov	ch,0
958multiloop1:	call	ax
959	add	di,bx
960	add	si,bx
961	loop	multiloop1
962	ret
963
964oddwidth:	mov	bl,cl
965	mov	bh,0
966	shr	bx,1
967	mov	ax,offset cs:width0
968	sub	ax,bx
969	mov	bl,cl
970	mov	bh,0
971	neg	bx
972	add	bx,screenwidth
973	mov	cl,ch
974	mov	ch,0
975multiloop2:	call	ax
976	movsb
977	add	di,bx
978	add	si,bx
979	loop	multiloop2
980	ret
981
982	endp
983
984
985
986
987
988Width160	proc	near
989
990	movsw
991	movsw
992	movsw
993	movsw
994	movsw
995	movsw
996	movsw
997	movsw
998	movsw
999	movsw
1000	movsw
1001	movsw
1002	movsw
1003	movsw
1004	movsw
1005	movsw
1006	movsw
1007	movsw
1008	movsw
1009	movsw
1010	movsw
1011	movsw
1012	movsw
1013	movsw
1014	movsw
1015	movsw
1016	movsw
1017	movsw
1018	movsw
1019	movsw
1020	movsw
1021	movsw
1022width128:	movsw
1023	movsw
1024	movsw
1025	movsw
1026	movsw
1027	movsw
1028	movsw
1029	movsw
1030	movsw
1031	movsw
1032	movsw
1033	movsw
1034	movsw
1035	movsw
1036	movsw
1037	movsw
1038	movsw
1039	movsw
1040	movsw
1041width110:	movsw
1042	movsw
1043	movsw
1044	movsw
1045	movsw
1046	movsw
1047	movsw
1048	movsw
1049	movsw
1050	movsw
1051	movsw
1052	movsw
1053	movsw
1054	movsw
1055	movsw
1056	movsw
1057	movsw
1058	movsw
1059	movsw
1060	movsw
1061	movsw
1062	movsw
1063width88:	movsw
1064	movsw
1065	movsw
1066	movsw
1067	movsw
1068	movsw
1069	movsw
1070	movsw
1071width80:	movsw
1072	movsw
1073	movsw
1074	movsw
1075	movsw
1076	movsw
1077	movsw
1078	movsw
1079	movsw
1080	movsw
1081	movsw
1082	movsw
1083	movsw
1084	movsw
1085	movsw
1086	movsw
1087	movsw
1088width63:	movsw
1089width62:	movsw
1090width61:	movsw
1091width60:	movsw
1092width59:	movsw
1093width58:	movsw
1094width57:	movsw
1095width56:	movsw
1096width55:	movsw
1097width54:	movsw
1098width53:	movsw
1099width52:	movsw
1100width51:	movsw
1101width50:	movsw
1102width49:	movsw
1103width48:	movsw
1104width47:	movsw
1105width46:	movsw
1106width45:	movsw
1107width44:	movsw
1108width43:	movsw
1109width42:	movsw
1110width41:	movsw
1111width40:	movsw
1112width39:	movsw
1113width38:	movsw
1114width37:	movsw
1115width36:	movsw
1116width35:	movsw
1117width34:	movsw
1118width33:	movsw
1119width32:	movsw
1120width31:	movsw
1121width30:	movsw
1122width29:	movsw
1123width28:	movsw
1124width27:	movsw
1125width26:	movsw
1126width25:	movsw
1127width24:	movsw
1128width23:	movsw
1129width22:	movsw
1130width21:	movsw
1131width20:	movsw
1132width19:	movsw
1133width18:	movsw
1134width17:	movsw
1135width16:	movsw
1136width15:	movsw
1137width14:	movsw
1138width13:	movsw
1139width12:	movsw
1140width11:	movsw
1141width10:	movsw
1142width9: 	movsw
1143width8: 	movsw
1144width7: 	movsw
1145width6: 	movsw
1146width5: 	movsw
1147width4: 	movsw
1148width3: 	movsw
1149width2: 	movsw
1150width1: 	movsw
1151width0: 	ret
1152
1153	endp
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163Doblocks	proc	near
1164
1165	mov	es,workspace
1166	mov	ax,mapady
1167	mov	cx,screenwidth
1168	mul	cx
1169	mov	di,mapadx
1170	add	di,ax
1171
1172	mov	al,mapy
1173	mov	ah,0
1174	mov	bx,mapwidth
1175	mul	bx
1176	mov	bl,mapx
1177	mov	bh,0
1178	add	ax,bx
1179
1180	mov	si,map
1181	add	si,ax
1182
1183	mov	cx,10
1184loop120:	push	di cx
1185	mov	cx,11
1186loop124:	push	cx di
1187
1188	mov	ds,mapdata
1189	lodsb
1190	mov	ds,backdrop
1191
1192	push	si
1193	cmp	al,0
1194	jz	zeroblock
1195	mov	ah,al
1196	mov	al,0
1197	mov	si,blocks
1198	add	si,ax
1199	mov	bh,14
1200
1201
1202	mov	bh,4
1203firstbitofblock:	movsw
1204	movsw
1205	movsw
1206	movsw
1207	movsw
1208	movsw
1209	movsw
1210	movsw
1211	add	di,screenwidth-16
1212	dec	bh
1213	jnz	firstbitofblock
1214
1215	mov	bh,12
1216loop125:	movsw
1217	movsw
1218	movsw
1219	movsw
1220	movsw
1221	movsw
1222	movsw
1223	movsw
1224	mov	ax,0dfdfh
1225	stosw
1226	stosw
1227
1228	add	di,screenwidth-20
1229	dec	bh
1230	jnz	loop125
1231
1232	add	di,4
1233	mov	ax,0dfdfh
1234	stosw
1235	stosw
1236	stosw
1237	stosw
1238	stosw
1239	stosw
1240	stosw
1241	stosw
1242	add	di,screenwidth-16
1243	stosw
1244	stosw
1245	stosw
1246	stosw
1247	stosw
1248	stosw
1249	stosw
1250	stosw
1251	add	di,screenwidth-16
1252	stosw
1253	stosw
1254	stosw
1255	stosw
1256	stosw
1257	stosw
1258	stosw
1259	stosw
1260	add	di,screenwidth-16
1261	stosw
1262	stosw
1263	stosw
1264	stosw
1265	stosw
1266	stosw
1267	stosw
1268	stosw
1269
1270
1271zeroblock:	pop	si
1272
1273	pop	di cx
1274	add	di,16
1275	loop	loop124
1276	add	si,mapwidth-11
1277	pop	cx di
1278	add	di,screenwidth*16
1279	loop	loop120
1280	ret
1281
1282	endp
1283
1284
1285
1286
1287
1288
1289
1290;----------------------------------------------General sprite output routine----
1291
1292Showframe	proc	near 	; shows a frame from sprites
1293
1294	push	dx ax	; es=destination
1295	mov	cx,ax	; ds=source
1296	and	cx,511	; di=x, bx=y
1297	add	cx,cx	; al=frame number
1298	mov	si,cx	; ah=effects flag
1299	add	cx,cx
1300	add	si,cx
1301	cmp	word ptr [si],0
1302	jnz	notblankshow
1303	pop ax dx
1304	mov	cx,0
1305	ret
1306
1307notblankshow:	test	ah,128
1308	jnz	skipoffsets
1309	mov	al,[si+4]
1310	mov	ah,0
1311	add	di,ax
1312	mov	al,[si+5]
1313	mov	ah,0
1314	add	bx,ax
1315skipoffsets:	mov	cx,[si+0]
1316	mov	ax,[si+2]
1317	add	ax,2080
1318	mov	si,ax
1319	pop	ax dx
1320	cmp	ah,0
1321	jz	noeffects
1322
1323	test	ah,128
1324	jz	notcentred
1325	push	ax
1326	mov	al,cl
1327	mov	ah,0
1328	shr	ax,1
1329	sub	di,ax
1330	mov	al,ch
1331	mov	ah,0
1332	shr	ax,1
1333	sub	bx,ax
1334	pop	ax
1335
1336notcentred:	test	ah,64
1337	jz	notdiffdest
1338	push	cx
1339	call	frameoutfx
1340	pop	cx
1341	ret
1342
1343notdiffdest:	test	ah,8
1344	jz	notprintlist
1345	push	ax
1346	mov	ax,di
1347	sub	ax,mapadx
1348	push	bx
1349	sub	bx,mapady
1350	mov	ah,bl
1351	pop	bx
1352	;call	addtoprintlist
1353	pop	ax
1354
1355notprintlist:	test	ah,4
1356	jz	notflippedx
1357	mov	dx,screenwidth
1358	mov	es,workspace
1359	push	cx
1360	call	frameoutfx
1361	pop	cx
1362	ret
1363
1364notflippedx:	test	ah,2
1365	jz	notnomask
1366	mov	dx,screenwidth
1367	mov	es,workspace
1368	push	cx
1369	call	frameoutnm
1370	pop	cx
1371	ret
1372
1373notnomask:	test	ah,32
1374	jz	noeffects
1375	mov	dx,screenwidth
1376	mov	es,workspace
1377	push	cx
1378	call	frameoutbh
1379	pop	cx
1380	ret
1381
1382noeffects:	mov	dx,screenwidth
1383	mov	es,workspace
1384	push	cx
1385	call	frameoutv
1386	pop	cx		; returns size printed in cx
1387	ret
1388
1389	endp
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400Frameoutv	proc	near
1401
1402	push	dx
1403	mov	ax,bx
1404	mov	bx,dx
1405	mul	bx
1406	add	di,ax
1407	pop	dx
1408
1409	push	cx
1410	mov	ch,0
1411	sub	dx,cx
1412	pop	cx
1413
1414frameloop1:	push	cx
1415	mov	ch,0
1416
1417frameloop2:	lodsb
1418	cmp	al,0
1419	jnz	backtosolid
1420backtoother:	inc	di
1421	loop	frameloop2
1422	pop	cx
1423	add	di,dx
1424	dec	ch
1425	jnz	frameloop1
1426	ret
1427
1428frameloop3:	lodsb
1429	cmp	al,0
1430	jz	backtoother
1431backtosolid:	stosb
1432	loop	frameloop3
1433	pop	cx
1434	add	di,dx
1435	dec	ch
1436	jnz	frameloop1
1437	ret
1438
1439	endp
1440
1441
1442
1443
1444
1445
1446Frameoutnm	proc	near
1447
1448	push	dx
1449	mov	ax,bx
1450	mov	bx,dx
1451	mul	bx
1452	add	di,ax
1453	pop	dx
1454
1455	push	cx
1456	mov	ch,0
1457	sub	dx,cx
1458	pop	cx
1459
1460	mov	al,cl
1461	and	al,1
1462	jnz	oddwidthframe
1463
1464	mov	bl,cl
1465	mov	bh,0
1466	mov	ax,offset cs:width0
1467	shr	bx,1
1468	sub	ax,bx
1469	mov	cl,ch
1470	mov	ch,0
1471nmloop1:	call	ax
1472	add	di,dx
1473	loop		nmloop1
1474	ret
1475
1476oddwidthframe:	mov	bl,cl
1477	mov	bh,0
1478	shr	bx,1
1479	mov	ax,offset cs:width0
1480	sub	ax,bx
1481	mov	cl,ch
1482	mov	ch,0
1483nmloop2:	call	ax
1484	movsb
1485	add	di,dx
1486	loop	nmloop2
1487	ret
1488
1489	endp
1490
1491
1492
1493
1494
1495
1496Frameoutbh	proc	near
1497
1498	push	dx
1499	mov	ax,bx
1500	mov	bx,dx
1501	mul	bx
1502	add	di,ax
1503	pop	dx
1504
1505	push	cx
1506	mov	ch,0
1507	sub	dx,cx
1508	pop	cx
1509
1510bhloop2:	push	cx
1511	mov	ch,0
1512	mov	ah,255
1513bhloop1:	cmp	[es:di],ah
1514	jnz	nofill
1515	movsb
1516	loop	bhloop1
1517	jmp	nextline
1518nofill:	inc	di
1519	inc	si
1520	loop	bhloop1
1521nextline:	add	di,dx
1522	pop	cx
1523	dec	ch
1524	jnz	bhloop2
1525	ret
1526
1527	endp
1528
1529
1530
1531
1532
1533
1534
1535Frameoutfx	proc	near
1536
1537	push	dx
1538	mov	ax,bx
1539	mov	bx,dx
1540	mul	bx
1541	add	di,ax
1542	pop	dx
1543
1544	push	cx
1545	mov	ch,0
1546	add	dx,cx
1547	pop	cx
1548
1549frameloopfx1:	push	cx
1550	mov	ch,0
1551
1552frameloopfx2:	lodsb
1553	cmp	al,0
1554	jnz	backtosolidfx
1555backtootherfx:	dec	di
1556	loop	frameloopfx2
1557	pop	cx
1558	add	di,dx
1559	dec	ch
1560	jnz	frameloopfx1
1561	ret
1562
1563frameloopfx3:	lodsb
1564	cmp	al,0
1565	jz	backtootherfx
1566backtosolidfx:	mov	[es:di],al
1567	dec	di
1568	loop	frameloopfx3
1569	pop	cx
1570	add	di,dx
1571	dec	ch
1572	jnz	frameloopfx1
1573	ret
1574
1575	endp
1576
1577
1578
1579
1580;---------------------------------------------------Transfers for extra data----
1581
1582Transferinv	proc	near
1583
1584	mov	di,exframepos
1585	push	di
1586	mov	al,expos
1587	mov	ah,0
1588	mov	bx,ax
1589	add	ax,ax
1590	add	ax,bx
1591	inc	ax
1592	mov	cx,6
1593	mul	cx
1594	mov	es,extras
1595	mov	bx,exframedata
1596	add	bx,ax
1597	add	di,exframes
1598
1599	push	bx
1600	mov	al,itemtotran
1601	mov	ah,0
1602	mov	bx,ax
1603	add	ax,ax
1604	add	ax,bx
1605	inc	ax
1606	mov	cx,6
1607	mul	cx
1608	mov	ds,freeframes
1609	mov	bx,frframedata
1610	add	bx,ax
1611	mov	si,frframes
1612	mov	al,[bx]
1613	mov	ah,0
1614	mov	cl,[bx+1]
1615	mov	ch,0
1616	add	si,[bx+2]		;we have si, and length
1617	mov	dx,[bx+4]
1618	pop	bx
1619	mov	[es:bx+0],al
1620	mov	[es:bx+1],cl
1621	mov	[es:bx+4],dx
1622
1623	mul	cx
1624	mov	cx,ax
1625	push	cx
1626	rep	movsb
1627	pop	cx
1628	pop	ax
1629	mov	[es:bx+2],ax
1630	add	exframepos,cx
1631	ret
1632
1633	endp
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644Transfermap	proc	near
1645
1646	mov	di,exframepos
1647	push	di
1648	mov	al,expos
1649	mov	ah,0
1650	mov	bx,ax
1651	add	ax,ax
1652	add	ax,bx
1653	mov	cx,6
1654	mul	cx
1655	mov	es,extras
1656	mov	bx,exframedata
1657	add	bx,ax
1658	add	di,exframes
1659
1660	push	bx
1661	mov	al,itemtotran
1662	mov	ah,0
1663	mov	bx,ax
1664	add	ax,ax
1665	add	ax,bx
1666	mov	cx,6
1667	mul	cx
1668	mov	ds,freeframes
1669	mov	bx,frframedata
1670	add	bx,ax
1671	mov	si,frframes
1672	mov	al,[bx]
1673	mov	ah,0
1674	mov	cl,[bx+1]
1675	mov	ch,0
1676	add	si,[bx+2]		;we have si, and length
1677	mov	dx,[bx+4]
1678	pop	bx
1679	mov	[es:bx+0],al
1680	mov	[es:bx+1],cl
1681	mov	[es:bx+4],dx
1682
1683	mul	cx
1684	mov	cx,ax
1685	push	cx
1686	rep	movsb
1687	pop	cx
1688	pop	ax
1689	mov	[es:bx+2],ax
1690	add	exframepos,cx
1691	ret
1692
1693	endp
1694
1695
1696;------------------------------------------------------------------Filenames----
1697
1698
1699Spritename1	db	"DREAMWEB.S00",0
1700Spritename3	db	"DREAMWEB.S02",0
1701
1702Idname	db	"INSTALL.DAT",0
1703
1704Characterset1	db	"DREAMWEB.C00",0
1705Characterset2	db	"DREAMWEB.C01",0
1706Characterset3	db	"DREAMWEB.C02",0
1707
1708Samplename	db	"DREAMWEB.V00",0
1709
1710Basicsample	db	"DREAMWEB.V99",0
1711
1712Icongraphics0	db	"DREAMWEB.G00",0
1713Icongraphics1	db	"DREAMWEB.G01",0
1714Extragraphics1	db	"DREAMWEB.G02",0
1715Icongraphics8	db	"DREAMWEB.G08",0
1716Mongraphicname	db	"DREAMWEB.G03",0
1717Mongraphics2	db	"DREAMWEB.G07",0
1718Cityname	db	"DREAMWEB.G04",0
1719Travelgraphic1	db	"DREAMWEB.G05",0
1720Travelgraphic2	db	"DREAMWEB.G06",0
1721Diarygraphic	db	"DREAMWEB.G14",0
1722
1723Monitorfile1	db	"DREAMWEB.T01",0
1724Monitorfile2	db	"DREAMWEB.T02",0
1725Monitorfile10	db	"DREAMWEB.T10",0	;News items 10-13
1726Monitorfile11	db	"DREAMWEB.T11",0
1727Monitorfile12	db	"DREAMWEB.T12",0
1728Monitorfile13	db	"DREAMWEB.T13",0
1729Monitorfile20	db	"DREAMWEB.T20",0
1730Monitorfile21	db	"DREAMWEB.T21",0	;Ryan's private stuff
1731Monitorfile22	db	"DREAMWEB.T22",0	;Use for blank carts
1732Monitorfile23	db	"DREAMWEB.T23",0	;Use for edens cart
1733Monitorfile24	db	"DREAMWEB.T24",0	;Use for church cart
1734Foldertext	db	"DREAMWEB.T50",0
1735Diarytext	db	"DREAMWEB.T51",0
1736Puzzletextname	db	"DREAMWEB.T80",0	;puzzle text
1737Traveltextname	db	"DREAMWEB.T81",0	;location descriptions
1738Introtextname	db	"DREAMWEB.T82",0	;intro sequence
1739Endtextname	db	"DREAMWEB.T83",0	;end sequence/credits
1740Commandtextname	db	"DREAMWEB.T84",0	;commands
1741
1742Volumetabname	db	"DREAMWEB.VOL",0
1743
1744Foldergraphic1	db	"DREAMWEB.G09",0
1745Foldergraphic2	db	"DREAMWEB.G10",0
1746Foldergraphic3	db	"DREAMWEB.G11",0
1747Symbolgraphic	db	"DREAMWEB.G12",0
1748Gungraphic	db	"DREAMWEB.G13",0
1749Monkface	db	"DREAMWEB.G15",0
1750
1751Title0graphics	db	"DREAMWEB.I00",0
1752Title1graphics	db	"DREAMWEB.I01",0
1753Title2graphics	db	"DREAMWEB.I02",0
1754Title3graphics	db	"DREAMWEB.I03",0
1755Title4graphics	db	"DREAMWEB.I04",0
1756Title5graphics	db	"DREAMWEB.I05",0
1757Title6graphics	db	"DREAMWEB.I06",0
1758Title7graphics	db	"DREAMWEB.I07",0
1759
1760Palettescreen	db	"DREAMWEB.PAL",0
1761