1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19*/
20//
21// worlda.s
22// x86 assembly-language server testing stuff
23//
24
25#define GLQUAKE	1	// don't include unneeded defs
26#include "asm_i386.h"
27#include "quakeasm.h"
28#include "d_ifacea.h"
29
30#if id386
31
32	.data
33
34Ltemp:	.long	0
35
36	.text
37
38//----------------------------------------------------------------------
39// hull-point test
40//----------------------------------------------------------------------
41
42#define hull	4+8				// because only partially pushed
43#define	num		8+4				// because only partially pushed
44#define p		12+12			// because only partially pushed
45
46	.align 4
47.globl C(SV_HullPointContents)
48C(SV_HullPointContents):
49	pushl	%edi				// preserve register variables
50	movl	num(%esp),%eax
51	testl	%eax,%eax
52	js		Lhquickout
53
54//	float		d;
55//	dclipnode_t	*node;
56//	mplane_t	*plane;
57
58	pushl	%ebx
59	movl	hull(%esp),%ebx
60
61	pushl	%ebp
62	movl	p(%esp),%edx
63
64	movl	hu_clipnodes(%ebx),%edi
65	movl	hu_planes(%ebx),%ebp
66
67	subl	%ebx,%ebx
68	pushl	%esi
69
70// %ebx: 0
71// %eax: num
72// %edx: p
73// %edi: hull->clipnodes
74// %ebp: hull->planes
75
76//	while (num >= 0)
77//	{
78
79Lhloop:
80
81//		node = hull->clipnodes + num;
82//		plane = hull->planes + node->planenum;
83// !!! if the size of dclipnode_t changes, the scaling of %eax needs to be
84//     changed !!!
85	movl	nd_planenum(%edi,%eax,8),%ecx
86	movl	nd_children(%edi,%eax,8),%eax
87	movl	%eax,%esi
88	rorl	$16,%eax
89	leal	(%ecx,%ecx,4),%ecx
90
91//		if (plane->type < 3)
92//			d = p[plane->type] - plane->dist;
93	movb	pl_type(%ebp,%ecx,4),%bl
94	cmpb	$3,%bl
95	jb		Lnodot
96
97//		else
98//			d = DotProduct (plane->normal, p) - plane->dist;
99	flds	pl_normal(%ebp,%ecx,4)
100	fmuls	0(%edx)
101	flds	pl_normal+4(%ebp,%ecx,4)
102	fmuls	4(%edx)
103	flds	pl_normal+8(%ebp,%ecx,4)
104	fmuls	8(%edx)
105	fxch	%st(1)
106	faddp	%st(0),%st(2)
107	faddp	%st(0),%st(1)
108	fsubs	pl_dist(%ebp,%ecx,4)
109	jmp		Lsub
110
111Lnodot:
112	flds	pl_dist(%ebp,%ecx,4)
113	fsubrs	(%edx,%ebx,4)
114
115Lsub:
116	sarl	$16,%eax
117	sarl	$16,%esi
118
119//		if (d < 0)
120//			num = node->children[1];
121//		else
122//			num = node->children[0];
123	fstps	Ltemp
124	movl	Ltemp,%ecx
125	sarl	$31,%ecx
126	andl	%ecx,%esi
127	xorl	$0xFFFFFFFF,%ecx
128	andl	%ecx,%eax
129	orl		%esi,%eax
130	jns		Lhloop
131
132//	return num;
133Lhdone:
134	popl	%esi
135	popl	%ebp
136	popl	%ebx				// restore register variables
137
138Lhquickout:
139	popl	%edi
140
141	ret
142
143#endif	// id386
144
145