5 ;;; For some reason MSVC like to put an extra underscore in front of
6 ;;; global identifer names. If this is gcc, compensate.
9 %define _g_VectorDelta g_VectorDelta
10 %define _g_PieceData g_PieceData
16 db 43h,30h,50h,56h, 72h,31h,47h,34h, 54h,20h,32h,30h
17 db 30h,36h,20h,53h, 63h,30h,74h,74h, 20h,47h,61h,73h
18 db 63h,34h,00h,01h, 22h,15h,48h,35h, 31h,21h,55h,46h
21 ;;; Note: The reason for this OSX stuff is that there is a bug in the mac
22 ;;; version of nasm. See comments in data.c for more details.
24 [GLOBAL g_NasmVectorDelta]
25 [GLOBAL _g_NasmVectorDelta]
31 [GLOBAL g_NasmPieceData]
32 [GLOBAL _g_NasmPieceData]
38 [EXTERN _g_VectorDelta]
49 ;; LastBit(BITBOARD bb)
71 ;; FirstBit(BITBOARD bb)
75 mov ecx, [esp+8] ; half of bb
76 mov edx, [esp+4] ; the other half
93 ;; CountBits(BITBOARD bb)
97 xor eax, eax ; eax is the count
98 mov ecx, [esp+4] ; half of bb
100 jz .c2 ; skip first loop?
106 .c2: mov ecx, [esp+8] ; the other half of bb
108 jz .cdone ; skip second loop?
119 [GLOBAL LockCompareExchange]
120 [GLOBAL _LockCompareExchange]
122 %define uComp esp+0xC
128 ;; LockCompareExchange(void *dest, ; esp + 4
129 ;; ULONG exch, ; esp + 8
130 ;; ULONG comp) ; esp + C
133 _LockCompareExchange:
137 lock cmpxchg dword [ecx], edx
142 [GLOBAL LockIncrement]
143 [GLOBAL _LockIncrement]
146 ;; LockIncrement(ULONG *pDest)
158 [GLOBAL LockDecrement]
159 [GLOBAL _LockDecrement]
162 ;; LockDecrement(ULONG *pDest)
178 db 43h,30h,50h,56h,72h,31h,47h,34h,54h,20h,32h,30h,30h
179 db 36h,20h,53h,63h,30h,74h,74h,20h,47h,61h,73h,63h,34h
184 %define uSide ebp+0x14
185 %define cSquare ebp+0x10
193 %define pOldList ebp-0x10
197 %define _cNonPawns 0x478
198 %define _uNonPawnCount 0x500
199 %define _rgSquare 0x0
203 ;; GetAttacks(SEE_LIST *pList, ; ebp + 8
204 ;; POSITION *pos, ; ebp + 0xC
205 ;; COOR cSquare, ; ebp + 0x10
206 ;; ULONG uSide) ; ebp + 0x14
216 ;; SEE_LIST *pOldList
225 mov dword [pOldList], ecx
230 ;; pList = &(pList.data[0]);
234 ;; c = cSquare + iDelta[uColor]
235 mov esi, dword [uSide]
236 mov ebx, dword [cSquare]
237 mov eax, dword [iDelta+esi*4]
240 ;; pPawn = BLACK_PAWN | uColor
248 ;; if (!IS_ON_BOARD(c)) goto try other pawn
252 ;; p = pos->pSquare[c];
253 mov eax, dword [edx+ebx*8+_rgSquare]
255 ;; if (p != pPawn) then goto try other pawn
259 ;; pOldList->uCount = 1
262 ;; pList->pPiece = p;
266 mov dword [edi+4], ebx
268 ;; pList->iVal = VALUE_PAWN;
269 mov dword [edi+8], 100
278 ;; if (!IS_ON_BOARD(c)) goto done pawns
282 ;; p = pos->pSquare[c];
283 mov eax, dword [edx+ebx*8+_rgSquare]
285 ;; if (p != pPawn) then goto done pawns
289 ;; pList->pPiece = p;
293 mov dword [edi+4], ebx
295 ;; pList->iVal = VALUE_PAWN;
296 mov dword [edi+8], 100
298 ;; pOldList->uCount++
310 ;; for (x = pos->uNonPawnCount[uSide][0] - 1;
315 mov ecx, dword [edx+eax*4+_uNonPawnCount]
323 mov esi, dword [uSide]
326 ;; c = pos->cNonPawns[uSide][x];
330 mov eax, dword [edx+eax*4+_cNonPawns]
333 ;; p = pos->pSquare[c];
334 mov ecx, dword [edx+eax*8+_rgSquare]
336 ;; iIndex = c - cSquare;
337 sub eax, dword [cSquare]
340 ;; If there is no way for that kind of piece to get to this
341 ;; square then keep looking.
343 ;; if (0 == (g_VectorDeltaTable[iIndex].iVector[iSide] &
344 ;; (1 << (PIECE_PIECE(p) >> 1)))) continue;
350 test byte [_g_NasmVectorDelta+eax*4+512], bl
352 test byte [_g_VectorDelta+eax*4+512], bl
356 ;; if (IS_KNIGHT_OR_KING(p)) goto nothing_blocks
363 ;; Not a knight or king. Check to see if there is a piece in
364 ;; the path from cSquare to c that blocks the attack.
366 ;; iDelta = g_VectorDeltaTable[iIndex].iNegDelta;
368 movsx ebx, byte [_g_NasmVectorDelta+eax*4+515]
370 movsx ebx, byte [_g_VectorDelta+eax*4+515]
373 ;; cBlockIndex = cSquare + iDelta
374 mov eax, dword [cSquare]
378 ;; if (cBlockIndex != c)
383 ;; if (IS_EMPTY(pos->pSquare[cBlockIndex]))
385 cmp dword [edx+eax*8], 0
392 ;; pList->pPiece[pList->iCount] = p;
395 ;; pList->cLoc[pList->iCount] = c;
396 mov dword [edi+4], ecx
398 ;; pList->iVal[pList->iCount] = PIECE_VALUE(p)
403 mov ebx, dword [_g_NasmPieceData+ecx]
405 mov ebx, dword [_g_PieceData+ecx]
407 mov dword [edi+8], ebx
410 mov eax, dword [pOldList]
416 pop edi ; restore saved registers