1 ;:ts=8
2 ;
3 ; C function call header
4 ;
5 
6 dataseg	segment para public 'data'
7 	public	tick_
8 tick_	dw	0
9 extrn	hit_mul_:word
10 extrn	goodchk_:word
11 extrn	your_na_:word
12 extrn	kild_by_:word
13 extrn	whoami_:word
14 extrn	prbuf_:word
15 extrn	no_step_:word
16 extrn	_Corg_:word
17 extrn	_Cend_:word
18 dataseg	ends
19 
20 codeseg	SEGMENT	para PUBLIC 'code'
21 	PUBLIC dmain_,dmaout_,COFF_,beep_,out_,peekb_,pokeb_
22 	PUBLIC getch_, no_char_,wsetmem_,clock_
23 	PUBLIC getds_, _halt_, csum_
24 	EXTRN	quit_:NEAR
25 	ASSUME	CS:codeseg, DS:dataseg
26 	
27 ;
28 ;  DOS interface routines
29 ;
30 ;  Author:	Jon Lane
31 ;  Date:	February 25, 1983
32 ;
33 
34 ;----------------------------------------------------------------------;
35 ;
36 ;	Do low level stuff so that window can be swapped to disk
37 ;
38 ;  Author:	Jon Lane
39 ;  Date:	February 28, 1983
40 ;
41 ;-------------------------------------------------------------------------
42 ;
43 ;	scrdma(string,length,ds,offset) -- dma a string to the screen
44 ;
45 ;-------------------------------------------------------------------------	
46 
47 dmaout_	PROC	NEAR
48 	PUSH	BP		;Save BP on stack to conform to call
49 	MOV	BP,SP		;Set BP to allow subsequent calls
50 	push	di
51 	push	si
52 	pushf
53 
54 	CLD
55 	MOV	AX,[BP + 8]	;Set string move destination to
56 	MOV	BX,ES		;save the extra segment reg
57 	MOV	ES,AX		;point to the screen
58 	MOV	DI,[BP + 10]	;Set the offset into the screen
59 	MOV	SI,[BP + 4]	;Set the source for the string move
60 	MOV	CX,[BP + 6]	;Set xfer count to 64 words
61 	REP	MOVSW		;Blast this out to the screen
62 
63 	MOV	AH,CL
64 	MOV	ES,BX		;restor the ES
65 
66 	popf
67 	pop	si
68 	pop	di
69 	POP	BP		;reset BP for caller's environment
70 	RET			;return to caller
71 dmaout_	ENDP
72 
73 dmain_	PROC	NEAR
74 	PUSH	BP		;Save BP on stack to conform to call
75 	MOV	BP,SP		;Set BP to allow subsequent calls
76 	push	di
77 	push	si
78 	pushf
79 
80 	MOV	AX,DS		;Set ES to point to the current DS
81 	MOV	BX,ES		; save ES
82 	MOV	ES,AX		;
83 
84 	CLD
85 	MOV	AX,[BP + 8]	;Set string move destination to
86 	MOV	DS,AX		;point to the screen
87 	MOV	SI,[BP + 10]	;Set the offset into the screen
88 	MOV	DI,[BP + 4]	;Set the source for the string move
89 	MOV	CX,[BP + 6]	;Set xfer count
90 	REP	MOVSW		;Blast this out to the screen
91 
92 	MOV	AX,ES		;Restore Current DS
93 	MOV	ES,BX		;Restore ES ???
94 	MOV	DS,AX		;
95 
96 	MOV	AH,CL
97 
98 	popf
99 	pop	si
100 	pop	di
101 	POP	BP		;reset BP for caller's environment
102 	RET			;return to caller
103 dmain_	ENDP
104 
105 wsetmem_	proc	near
106 	push	bp
107 	mov	bp,sp
108 	push	di
109 	push	si
110 	pushf
111 
112 	push	ds
113 	pop	es
114 	
115 	mov	di,[bp + 4]
116 	mov	cx,[bp + 6]
117 	mov	ax,[bp + 8]
118 	cld
119 	repz	stosw
120 
121 	popf
122 	pop	si
123 	pop	di
124 	pop	bp
125 	ret
126 wsetmem_	endp
127 
128 beep_	proc	near
129 	push	bp		;Save BP on stack to conform to call
130 	mov	bp,sp		;Set BP to allow subsequent calls
131 
132 	mov	bx,300		;count of speaker cycles
133 	in	al,61h		;input control info from keyboard/speaker port
134 	push	ax		;save it on the stack
135 cycle:	and	al,0fch		;speaker off pulse (mask out bit 0 and 1)
136 	out	61h,al		;send command to speaker port
137 	mov	cx,50		;time for tone half-cycle
138 l1:	loop	l1		;kill time
139 	or	al,2		;speaker on pulse (bit 1 on)
140 	out	61h,al		;send command to speaker port
141 	mov	cx,50		;time for tone half-cycle
142 l2:	loop	l2		;kill time
143 	dec	bx		;count down of speaker cycles
144 	jnz	cycle		;continue cycling speaker
145 	pop	ax		;restore speaker/keyboard port value
146 	out	61h,al		;send port value out
147 
148 	pop	bp		;reset BP for caller's environment
149 	ret			;return to caller
150 beep_	endp
151 
152 ;------------------------------------------------------------------;
153 ; COFF, vectors CTRL-BREAK interrupts to a small assembly language ;
154 ; function which calls QUIT					   ;
155 ;------------------------------------------------------------------;
156 
157 ctrlbreak:
158 	push	ax		; AX will be destroyed by call
159 	call	quit_
160 	pop	ax		; Restore proper value of ax
161 	iret
162 
163 clock_	proc	near
164 	cli
165 	push	ds
166 	push	ax
167 	; kill single steppers
168 	mov	ax,0
169 	mov	ds,ax
170 	mov	ax,[4]
171 	cmp	ax,0
172 	jz	ok1
173 	call	_halt_
174 ok1:
175 	mov	ax,[6]
176 	cmp	ax,0
177 	jz	ok2
178 	call	_halt_
179 ok2:
180 	; use our data segment
181 	mov	ax,dataseg
182 	mov	ds,ax
183 	inc	tick_		; Tick the old clock
184 
185 	; some more rough stuff for people in debuggers
186 	cmp	no_step_, 0
187 	je	no_big
188 	inc	no_step_
189 	cmp	no_step_,20
190 	jle	no_big
191 	call	_halt_
192 no_big:
193 	; copy protection goodies
194 	cmp	hit_mul_, 1
195 	je	pskip
196 	cmp	goodchk_, 0D0DH
197 	jne	pskip
198 	mov	ax, prbuf_
199 	mov	kild_by_, ax
200 	mov	ax, offset whoami_
201 	mov	your_na_, ax
202 	mov	hit_mul_, 1
203 pskip:
204 	pop	ax
205 	pop	ds
206 	iret			; return from interrupt
207 clock_	endp
208 
209 
210 COFF_	proc	near
211 	mov	dx,offset ctrlbreak	; DX has address of handler
212 	push	ds			; Save value of DS
213 	push	ds			; Save value of DS
214 	push	cs			; Move Value of CS
215 	pop	ds			; into DS
216 	mov	ax,2523h		; Set CTRL-BREAK function call
217 	int	21h
218 	pop	ds			; Restore DS
219 	pop	es
220 	ret
221 COFF_	endp
222 
223 getch_	proc	near
224 	mov	ah,0
225 	int	16h
226 	cmp	al,0
227 	jnz	clrscan
228 	mov	al,ah
229 	or	al,80h
230 clrscan:
231 	mov	ah,0
232 	ret
233 getch_	endp
234 
235 no_char_	proc	near
236 	mov	ah,1
237 	int	16h
238 	mov	ax,0
239 	jnz	n1
240 	inc	ax
241 n1:
242 	ret
243 no_char_	endp
244 
245 out_	proc	near
246 	mov	bx,sp
247 	mov	dx,2[bx]
248 	mov	al,4[bx]
249 	out	dx,al
250 	ret
251 out_	endp
252 
253 pokeb_	proc near
254 	mov	bx,sp
255 	push	ds
256 	mov	al,6[bx]
257 	lds	bx,dword ptr 2[bx]
258 	mov	[bx],al
259 	pop	ds
260 	ret
261 pokeb_	endp
262 
263 peekb_	proc	near
264 	mov	bx,sp
265 	push	ds
266 	lds	bx,dword ptr 2[bx]
267 	mov	al,[bx]
268 	mov	ah,0
269 	pop	ds
270 	ret
271 peekb_	endp
272 
273 getds_	proc	near
274 	push	ds
275 	pop	ax
276 	ret
277 getds_	endp
278 
279 _halt_	proc near
280 	std
281 	cli
282 	mov	ax, ss
283 	mov	ds, ax
284 	mov	di, sp	
285 	mov	ax, 0
286 	mov	cx, 10
287 hcont:
288 	stosw
289 	dec	cx
290 	jnz	hcont
291 
292 	hlt
293 _halt_	endp
294 
295 csum_	proc	near
296 	mov	ax, offset _Corg_
297 	mov	bx, offset _Cend_
298 	mov	cx, 0
299 	push	si
300 	push	ds
301 	push	cs
302 	pop	ds
303 	add	ax, 200H
304 	mov	si, ax
305 	cld
306 csmore:
307 	lodsw
308 	add	cx, ax
309 	cmp	bx, si
310 	jl	csmore
311 	mov	ax, cx
312 	pop	ds
313 	pop	si
314 	ret
315 csum_	endp
316 
317 codeseg	ends
318 	end
319 