xref: /titanic_44/usr/src/cmd/vi/port/ovdoprnt.s (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
1#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
2#	  All Rights Reserved
3
4#
5# CDDL HEADER START
6#
7# The contents of this file are subject to the terms of the
8# Common Development and Distribution License, Version 1.0 only
9# (the "License").  You may not use this file except in compliance
10# with the License.
11#
12# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13# or http://www.opensolaris.org/os/licensing.
14# See the License for the specific language governing permissions
15# and limitations under the License.
16#
17# When distributing Covered Code, include this CDDL HEADER in each
18# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19# If applicable, add the following below this CDDL HEADER, with the
20# fields enclosed by brackets "[]" replaced with your own identifying
21# information: Portions Copyright [yyyy] [name of copyright owner]
22#
23# CDDL HEADER END
24#
25
26#
27# University Copyright- Copyright (c) 1982, 1986, 1988
28# The Regents of the University of California
29# All Rights Reserved
30#
31# University Acknowledgment- Portions of this document are derived from
32# software developed by the University of California, Berkeley, and its
33# contributors.
34#
35
36#pragma ident	"%Z%%M%	%I%	%E% SMI"
37
38/ #ident	"@(#)vi:port/ovdoprnt.s	1.5"
39/ C library -- conversions
40/ Overlay modification -- wfj 8/80
41/ stack frame is one word larger...
42/
43
44/ width=-8.
45/ formp=-10.
46/ rjust=-12.
47/ ndfnd=-14.
48/ ndigit=-16.
49/ zfill=-18.
50width=-10.
51formp=-12.
52rjust=-14.
53ndfnd=-16.
54ndigit=-18.
55zfill=-20.
56.globl	__doprnt
57
58.globl	__strout
59.globl	csv
60.globl	cret
61
62__doprnt:
63	jsr	r5,csv
64	sub	$128.+12.,sp
65	mov	4(r5),formp(r5)		/ format
66	mov	6(r5),r4
67loop:
68	mov	sp,r3
69	mov	formp(r5),r1
702:
71	movb	(r1)+,r2
72	beq	2f
73	cmp	r2,$'%
74	beq	2f
75	movb	r2,(r3)+
76	br	2b
772:
78	mov	r1,formp(r5)
79	cmp	r3,sp
80	beq	2f
81	mov	sp,r0
82	mov	8(r5),-(sp)
83	clr	-(sp)
84	mov	r3,-(sp)
85	sub	r0,(sp)
86	mov	r0,-(sp)
87	jsr	pc,__strout
88	add	$8,sp
892:
90	tst	r2
91	bne	2f
92	jmp	cret
932:
94	mov	sp,r3
952:
96	clr	rjust(r5)
97	clr	ndigit(r5)
98	mov	$' ,zfill(r5)
99	cmpb	*formp(r5),$'-
100	bne	2f
101	inc	formp(r5)
102	inc	rjust(r5)
1032:
104	cmpb	*formp(r5),$'0
105	bne	2f
106	mov	$'0,zfill(r5)
1072:
108	jsr	r3,gnum
109	mov	r1,width(r5)
110	clr	ndfnd(r5)
111	cmp	r0,$'.
112	bne	1f
113	jsr	r3,gnum
114	mov	r1,ndigit(r5)
1151:
116	mov	$swtab,r1
1171:
118	mov	(r1)+,r2
119	bne	2f
120	movb	r0,(r3)+
121	jmp	prbuf
1222:
123	cmp	r0,(r1)+
124	bne	1b
125	jmp	(r2)
126	.data
127swtab:
128	decimal;	'd
129	octal;		'o
130	hex;		'x
131	charac;		'c
132	string;		's
133	longorunsg;	'l
134	longorunsg;	'L
135	unsigned;	'u
136	remote;		'r
137	long;		'D
138	loct;		'O
139	lhex;		'X
140	lunsigned;	'U
141	0;  0
142	.text
143
144longorunsg:
145	movb	*formp(r5),r0
146	inc	formp(r5)
147	cmp	r0,$'o
148	beq	loct
149	cmp	r0,$'x
150	beq	lhex
151	cmp	r0,$'d
152	beq	long
153	cmp	r0,$'u
154	beq	lunsigned
155	dec	formp(r5)
156	br	unsigned
157
158octal:
159	clr	r0
160	br	1f
161loct:
162	mov	(r4)+,r0
1631:
164	mov	$8.,r2
165	br	2f
166
167hex:
168	clr	r0
169	br	1f
170
171lhex:
172	mov	(r4)+,r0
1731:
174	mov	$16.,r2
1752:
176	mov	(r4)+,r1
177	br	compute
178
179decimal:
180	mov	(r4)+,r1
181	sxt	r0
182	bmi	3f
183	br	2f
184
185unsigned:
186	clr	r0
187	br	1f
188
189long:
190	mov	(r4)+,r0
191	bge	1f
192	mov	(r4)+,r1
1933:
194	neg	r0
195	neg	r1
196	sbc	r0
197	movb	$'-,(r3)+
198	br	2f
199
200lunsigned:
201	mov	(r4)+,r0
2021:
203	mov	(r4)+,r1
2042:
205	mov	$10.,r2
206
207/
208/ Algorithm courtesy Keith Davis
209/
210compute:
211	mov	r5,-(sp)
212	mov	r4,-(sp)
213	mov	r0,r4
214	mov	ndigit(r5),r0
215	mov	r1,r5
216	ashc	$0,r4
217	beq	1f
218	tst	r0
219	beq	1f
220	movb	$'0,(r3)+
2211:
222	jsr	pc,1f
223	mov	(sp)+,r4
224	mov	(sp)+,r5
225	br	prbuf
226
2271:
228	clr	r0
229	mov	r4,r1
230	beq	2f
231	div	r2,r0
232	mov	r0,r4
233	mov	r1,r0
2342:
235	mov	r5,r1
236	asl	r2
237	div	r2,r0
238	asr	r2
239	asl	r0
240	cmp	r2,r1
241	bgt	2f
242	sub	r2,r1
243	inc	r0
2442:
245	mov	r1,-(sp)
246	mov	r0,r5
247	bne	2f
248	tst	r4
249	beq	1f
2502:
251	jsr	pc,1b
2521:
253	mov	(sp)+,r0
254	add	$'0,r0
255	cmp	r0,$'9
256	ble	1f
257	add	$'a-'0-10.,r0
2581:
259	movb	r0,(r3)+
260	rts	pc
261
262charac:
263	mov	$' ,zfill(r5)
264	mov	(r4)+,r0
265	bic	$!377,r0
266	beq	prbuf
267	movb	r0,(r3)+
268	br	prbuf
269
270string:
271	mov	$' ,zfill(r5)
272	mov	ndigit(r5),r1
273	mov	(r4),r2
274	mov	r2,r3
275	bne	1f
276	mov	$nulstr,r2
277	mov	r2,r3
278	mov	r2,(r4)
2791:
280	tstb	(r2)+
281	beq	1f
282	inc	r3
283	sob	r1,1b
2841:
285	mov	(r4)+,r2
286	br	prstr
287
288remote:
289	mov	(r4)+,r4
290	mov	(r4)+,formp(r5)
291	jmp	loop
292
293prbuf:
294	mov	sp,r2
295prstr:
296	sub	r2,r3
297	mov	width(r5),r1
298	sub	r3,r1
299	bge	1f
300	clr	r1
3011:
302	tst	rjust(r5)
303	bne	1f
304	neg	r1
3051:
306	mov	zfill(r5),-(sp)
307	mov	8(r5),-(sp)
308	mov	r1,-(sp)
309	mov	r3,-(sp)
310	mov	r2,-(sp)
311	jsr	pc,__strout
312	add	$10.,sp
313	jmp	loop
314
315gnum:
316	clr	ndfnd(r5)
317	clr	r1
3181:
319	movb	*formp(r5),r0
320	inc	formp(r5)
321	sub	$'0,r0
322	cmp	r0,$'*-'0
323	bne	2f
324	mov	(r4)+,r0
325	br	3f
3262:
327	cmp	r0,$9.
328	bhi	1f
3293:
330	inc	ndfnd(r5)
331	mul	$10.,r1
332	add	r0,r1
333	br	1b
3341:
335	add	$'0,r0
336	rts	r3
337
338.data
339nulstr:
340	<(null)\0>
341