]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cpu_x86.nasm
Borland C++ compile fix - works/compiles now.
[xonotic/darkplaces.git] / cpu_x86.nasm
1           BITS 32
2           GLOBAL _Mod_PointInLeaf
3           GLOBAL _SV_HullPointContents
4           SECTION .text
5 _Mod_PointInLeaf
6
7 ;{
8
9         mov     eax, dword [esp+12-4] ; model
10         sub     esp, 4
11         push    ebx
12         push    esi
13
14 ;       mnode_t         *node;
15 ;       node = model->nodes;
16
17         mov     esi, dword [eax+200] ; model->nodes
18
19 ;       if (node->contents < 0)
20
21         cmp     dword [esi], 0 ; node->contents
22         jge     .firstvalid
23
24 ;               return (mleaf_t *)node;
25
26         mov     eax, esi
27         pop     esi
28         pop     ebx
29         add     esp, 4
30         ret     0
31 .firstvalid
32         mov     edx, dword [esp+8+8] ; p
33 .loop
34
35 ;       while (1)
36
37         xor     ecx, ecx
38         mov     eax, dword [esi+76] ; node->plane
39         mov     cl, byte [eax+16] ; node->plane->type
40
41 ;       {
42 ;               node = node->children[(node->plane->type < 3 ? p[node->plane->type] : DotProduct (p,node->plane->normal)) < node->plane->dist];
43
44         cmp     cl, 3
45         jb      .axisplane
46         fld     dword [eax+4] ; node->plane->normal[1]
47         fmul    dword [edx+4] ; p[1]
48         fld     dword [eax+8] ; node->plane->normal[2]
49         fmul    dword [edx+8] ; p[2]
50         fld     dword [eax]   ; node->plane->normal[0]
51         fmul    dword [edx]   ; p[0]
52         faddp   st1, st0
53         faddp   st1, st0
54         fld     dword [eax+12] ; node->plane->dist
55         fcompp
56         fnstsw  ax
57         test    ah, 65                                  ; 00000041H
58         sete    cl
59         mov     esi, dword [esi+ecx*4+80] ; node = node->children[condition]
60
61 ;               if (node->contents < 0)
62
63         cmp     dword [esi], 0
64         jge     .loop
65
66 ;                       return (mleaf_t *)node;
67
68         mov     eax, esi
69
70 ;       }
71 ;       return NULL;    // never reached
72 ;}
73
74         pop     esi
75         pop     ebx
76         add     esp, 4
77         ret     0
78 .axisplane:
79         fld     dword [edx+ecx*4]
80         fld     dword [eax+12]
81         fcompp
82         fnstsw  ax
83         test    ah, 65                                  ; 00000041H
84         sete    cl
85         mov     esi, dword [esi+ecx*4+80] ; node = node->children[condition]
86
87 ;               if (node->contents < 0)
88
89         cmp     dword [esi], 0
90         jge     .loop
91
92 ;                       return (mleaf_t *)node;
93
94         mov     eax, esi
95
96 ;       }
97 ;       return NULL;    // never reached
98 ;}
99
100         pop     esi
101         pop     ebx
102         add     esp, 4
103         ret     0
104
105
106 _SV_HullPointContents
107
108 ;{
109         mov     ecx, [esp+12-4] ; num
110         sub     esp, 4
111         test    ecx, ecx
112         nop                     ; padding
113         push    ebx
114         push    esi
115         push    edi
116         push    ebp
117
118 ;       while (num >= 0)
119
120         jge     .firstvalid
121 ;       return num;
122         mov     eax, ecx
123         pop     ebp
124 ;}
125         pop     edi
126         pop     esi
127         pop     ebx
128         add     esp, 4
129         ret     0
130 .firstvalid
131         mov     eax, [esp+8+16] ; hull
132         mov     edx, [esp+16+16] ; p
133         mov     esi, [eax]
134         mov     edi, [eax+4]
135 .loop
136         mov     eax, [esi+ecx*8]
137         lea     ebx, [eax+eax*2]
138         xor     eax, eax
139         mov     al, [edi+ebx*8+16]
140         lea     ebp, [edi+ebx*8]
141
142 ;               num = hull->clipnodes[num].children[(hull->planes[hull->clipnodes[num].planenum].type < 3 ? p[hull->planes[hull->clipnodes[num].planenum].type] : DotProduct (hull->planes[hull->clipnodes[num].planenum].normal, p)) < hull->planes[hull->clipnodes[num].planenum].dist];
143
144         cmp     al, 3
145         jb      .axisplane
146         fld     dword [edx+8]
147         fmul    dword [ebp+8]
148         fld     dword [edx+4]
149         fmul    dword [ebp+4]
150         fld     dword [edx]
151         fmul    dword [ebp]
152         faddp   st1, st0
153         faddp   st1, st0
154         fstp    dword [esp-4+20]
155
156         fld     dword [ebp+12]
157         fcomp   dword [esp-4+20]
158         xor     ebx, ebx
159         fnstsw  ax
160         test    ah, 65                                  ; 00000041H
161         sete    bl
162         lea     eax, [ebx+ecx*4]
163         movsx   ecx, word [esi+eax*2+4]
164         test    ecx, ecx
165         jge     .loop
166 ;       return num;
167         mov     eax, ecx
168         pop     ebp
169 ;}
170         pop     edi
171         pop     esi
172         pop     ebx
173         add     esp, 4
174         ret     0
175
176 .axisplane
177         mov     eax, [edx+eax*4]
178         mov     [esp-4+20], eax
179
180         fld     dword [ebp+12]
181         fcomp   dword [esp-4+20]
182         xor     ebx, ebx
183         fnstsw  ax
184         test    ah, 65                                  ; 00000041H
185         sete    bl
186         lea     eax, [ebx+ecx*4]
187         movsx   ecx, word [esi+eax*2+4]
188         test    ecx, ecx
189         jge     .loop
190 ;       return num;
191         mov     eax, ecx
192         pop     ebp
193 ;}
194         pop     edi
195         pop     esi
196         pop     ebx
197         add     esp, 4
198         ret     0