1;Copyright (c) 1987, 1990, 1993, 2005 Vrije Universiteit, Amsterdam, The Netherlands.
2;All rights reserved.
3;
4;Redistribution and use of the Amsterdam Compiler Kit in source and
5;binary forms, with or without modification, are permitted provided
6;that the following conditions are met:
7;
8;   * Redistributions of source code must retain the above copyright
9;     notice, this list of conditions and the following disclaimer.
10;
11;   * Redistributions in binary form must reproduce the above
12;     copyright notice, this list of conditions and the following
13;     disclaimer in the documentation and/or other materials provided
14;     with the distribution.
15;
16;   * Neither the name of Vrije Universiteit nor the names of the
17;     software authors or contributors may be used to endorse or
18;     promote products derived from this software without specific
19;     prior written permission.
20;
21;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
22;CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23;INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24;MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25;IN NO EVENT SHALL VRIJE UNIVERSITEIT OR ANY AUTHORS OR CONTRIBUTORS BE
26;LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27;CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28;SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29;BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30;WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31;OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32;EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35SECTION code_crt0_sccz80
36PUBLIC  l_long_mult
37
38EXTERN __retloc, __math_rhs, __math_lhs, __math_result
39
40; 32 bits signed and unsigned integer multiply routine
41; Expects operands on stack
42; Yields product on stack
43
44; Liberated from ack
45
46l_long_mult:
47
48	LD (__math_rhs),HL	; store multiplier
49	ex	de,hl
50	LD (__math_rhs+2),HL
51
52	POP HL
53	LD (__retloc),HL
54
55	POP HL			; store multiplicand
56	LD (__math_lhs),HL
57	POP HL
58	LD (__math_lhs+2),HL
59	LD HL,0
60	LD (__math_result),HL
61	LD (__math_result+2),HL
62
63	ld hl,__math_rhs
64	ld c,4
65lp1:
66	push hl
67	LD  a,(HL)			; get next byte of multiplier
68	LD  b,8
69lp2:	RRA
70	JP	NC,dont_add
71	LD HL,(__math_lhs)		; add multiplicand to product
72	EX	DE,HL
73	LD HL,(__math_result)
74	ADD	HL,DE
75	LD (__math_result),HL
76	LD HL,(__math_lhs+2)
77	JP	NC,noinc
78	INC HL
79noinc:	EX	DE,HL
80	LD HL,(__math_result+2)
81	ADD	HL,DE
82	LD (__math_result+2),HL
83
84dont_add:
85	LD HL,(__math_lhs)		; shift multiplicand left
86	ADD	HL,HL
87	LD (__math_lhs),HL
88	LD HL,(__math_lhs+2)
89	JP	NC,noshift
90	ADD	HL,HL
91	INC HL
92	JP store
93noshift:
94	ADD	HL,HL
95store:	LD (__math_lhs+2),HL
96
97	DEC b
98	JP	NZ,lp2
99
100        pop hl
101        inc hl
102        dec c
103	JP	NZ,lp1
104
105	LD HL,(__retloc)
106	push hl
107
108	LD HL,(__math_result+2)
109	ex de,hl
110	LD HL,(__math_result)
111	ret
112