| |
#COMPILE DLL
#DIM ALL
#INCLUDE ONCE "Win32API.inc"
GLOBAL ghInstance AS DWORD
'-------------------------------------------------------------------------------
' Main DLL entry point called by Windows...
'
FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _
BYVAL fwdReason AS LONG, _
BYVAL lpvReserved AS LONG) AS LONG
SELECT CASE fwdReason
CASE %DLL_PROCESS_ATTACH
'Indicates that the DLL is being loaded by another process (a DLL
'or EXE is loading the DLL). DLLs can use this opportunity to
'initialize any instance or global data, such as arrays.
ghInstance = hInstance
FUNCTION = 1 'success!
'FUNCTION = 0 'failure! This will prevent the EXE from running.
CASE %DLL_PROCESS_DETACH
'Indicates that the DLL is being unloaded or detached from the
'calling application. DLLs can take this opportunity to clean
'up all resources for all threads attached and known to the DLL.
FUNCTION = 1 'success!
'FUNCTION = 0 'failure!
CASE %DLL_THREAD_ATTACH
'Indicates that the DLL is being loaded by a new thread in the
'calling application. DLLs can use this opportunity to
'initialize any thread local storage (TLS).
FUNCTION = 1 'success!
'FUNCTION = 0 'failure!
CASE %DLL_THREAD_DETACH
'Indicates that the thread is exiting cleanly. If the DLL has
'allocated any thread local storage, it should be released.
FUNCTION = 1 'success!
'FUNCTION = 0 'failure!
END SELECT
END FUNCTION
'******************************************************************************************
' OUR FUNCTION ASLottoGen
'parameters:
' myTotalNum - total number in system (up to 64)
' myNumInComb
- numbers per combination ( from 1 to 8)
' where2put - pointer to memory where we will store combinations
' one byte per number, and combination will be stored one by one
'******************************************************************************************
FUNCTION ASLottoGen ALIAS "ASLottoGen" _
(BYVAL myTotalNum AS LONG, BYVAL myNumInComb AS LONG, _
BYVAL where2put AS LONG) EXPORT AS LONG
#REGISTER NONE
DIM my_1comb(16) AS BYTE 'place where we have current combination from 'my_1comb(1)...my_1comb(myNumInComb).
Tthis array must have size of 16 bytes, for combination we use only 'smaller part but because we transfer 8 bytes every time when we step from one combination to another
'we need some extra space
DIM ptr2_my_1comb AS LONG 'pointer to first elemet of our array
DIM num_combs AS LONG 'we will return value in this variable
ptr2_my_1comb=VARPTR(my_1comb(0))
' ****************************
' OUR FUNCTION START FROM HERE
'*****************************
! push esi
! push edi
! push ebx
! mov eax,where2put ; we will keep these values in our mmx registers
! movd mm1,eax ;in mm1 is pointer where we must store our combinations
! mov ebx,myTotalNum
! movd mm2,ebx ;in mm2 is myTotalNum
! mov ecx,myNumInComb
! movd mm3,ecx ;in mm3 is myNumInComb
! lea edi,mynumberlist ;in edi is pointer to our numbers list
! movq mm0,[edi+1]
! mov esi,ptr2_my_1comb
! movq [esi+1],mm0 ;we will have 1. combination in place
! xor edx,edx ;in edx we will keep counter of combinations, start from 0
! xor eax,eax ;because we must use al (part of eax) we will set it to 0
! je store_comb ;store combinations and increase counter
'**************************************
' the hart of generator, code start here
'**************************************
loop_lotto:
! mov al,[esi+ecx]
! inc eax
! cmp eax,ebx
! jbe next_comb
! dec ebx
! dec ecx
! jne loop_lotto
! jmp gencomb_end
next_comb:
! movq mm0,[edi+eax]
! movq [esi+ecx],mm0
'**********************
' generator code end here,
'**********************
' now combination is ready
'**********************
store_comb:
! movq mm0,[esi+1]
! movd ebx,mm1
! movq [ebx],mm0
! movd ecx,mm3
! add ebx,ecx
! movd mm1,ebx
! movd ebx,mm2
! inc edx
! jne loop_lotto
gencomb_end:
! emms
! mov num_combs,edx
! pop ebx
! pop edi
! pop esi
FUNCTION=num_combs
END FUNCTION
ASMDATA mynumberlist
DB 0,1,2,3,4,5,6,7,8,9,10
DB 11,12,13,14,15,16,17,18,19,20
DB 21,22,23,24,25,26,27,28,29,30
DB 31,32,33,34,35,36,37,38,39,40
DB 41,42,43,44,45,46,47,48,49,50
DB 51,52,53,54,55,56,57,58,59,60
DB 61,62,63,64
END ASMDATA
'**************************************************************
' Function ASLottoGen64B
' myTotalNum - total number in system (up to 64)
' myNumInComb
- numbers per combination ( from 1 to 8)
' where2put - pointer to memory where we will store combinations
' we will have 8bytes per combination, one by one,
'each combination will be represented as 64bit vaue
'**************************************************************
FUNCTION ASLottoGen64B alias "ASLottoGen64B" (BYVAL myTotalNum AS LONG,_
BYVAL myNumInComb AS LONG,BYVAL where2put AS LONG) EXPORT AS LONG
#REGISTER NONE
DIM my_1comb(32) AS BYTE
DIM ptr2_my_1comb AS LONG
DIM my_currentb64(8) AS QUAD
DIM ptr2_my_currentb64 AS LONG
ptr2_my_1comb=VARPTR(my_1comb(0))
ptr2_my_currentb64=VARPTR(my_currentb64(0))
' *********************************
' OUR FUNCTION START FROM HERE
'*********************************
! push esi
! push edi
! push ebx
! mov eax,where2put
! movd mm1,eax ;in mm1 is pointer where we must store our combiations
! lea esi,start64b
! mov edi,ptr2_my_currentb64
! movd mm5,edi ;in mm5 is pointer to my_currentb64
! mov ecx,myNumInComb ;just to calculate how many quads we must take
! mov eax,8
! mul ecx
! mov edx,eax
! mov ecx,8
take_again:
! movq mm7,[esi+ecx]
! movq [edi+ecx],mm7
! add ecx,8
! sub edx,8
! jne take_again
! mov ebx,myTotalNum
! movd mm2,ebx ;in mm2 is myTotalNum
! mov ecx,myNumInComb
! movd mm3,ecx ;in mm3 is myNumInComb
! lea eax,my64numbers
! movd mm4,eax ;in mm4 is pointer to my64numbers list
! lea edi,mynumberlist ;in edi is pointer to our numbers list
! movq mm0,[edi+1]
! mov esi,ptr2_my_1comb
! movq [esi+1],mm0 ;we will have 1. combination in place
! movq mm0,[edi+9]
! movq [esi+9],mm0
! xor eax,eax ;because we must use al (part of eax) we will set it to 0
! je store_comb ;store bitmap representation
loop_lotto:
! mov al,[esi+ecx]
! inc eax
! cmp eax,ebx
! jbe next_comb
! dec ebx
! dec ecx
! jne loop_lotto
! jmp gencomb_end
next_comb:
! movq mm0,[edi+eax]
! movq [esi+ecx],mm0
'---------------------------------------------------------------
' now we will make 64bits representation of current combination
'---------------------------------------------------------------
! push esi ;we will save registers that we will use in next commands
! push edi
! movd esi,mm4 ;esi=pointer to my64numbers list
! movd edi,mm5 ;edi=ptr2_my_currentb64
! dec ecx ;ecx=ecx-1
! movq mm6,[edi+ecx*8] ;load bit representation for numbers from position 1 to ecx
! mov ebx,8 ;number in eax is multiply by 8, to locate its representation
! mul ebx
! movd ebx,mm3 ;ebx=myNumInComb
! inc ecx ;ecx=ecx+1
set_my_currentb64a:
! movq mm7,[esi+eax] ;mm7=bit represenation of number in eax
! por mm7,mm6 ;we will add that bit
! movq [edi+ecx*8],mm7 ;store it in working function memory
! movq mm6,mm7 ;we will remember it in mm6
! add eax,8 ;we need next representation
! inc ecx ;ecx=ecx+1
! cmp ecx,ebx ;are we done with combination?
! jbe set_my_currentb64a
! pop edi
! pop esi
'*********************************
' combination is ready and bitmap is in mm7
'*********************************
store_comb:
! movd ebx,mm1
! movq [ebx],mm7 ;in mm7 we have our bit representation and we will store it in calling function memory
! add ebx,8
! movd mm1,ebx
! movd ecx,mm3
! movd ebx,mm2
! xor eax,eax
! je loop_lotto
gencomb_end:
! emms
! pop ebx
! pop edi
! pop esi
END FUNCTION
ASMDATA start64b
DB 0,0,0,0,0,0,0,0
DB 1,0,0,0,0,0,0,0
DB 3,0,0,0,0,0,0,0
DB 7,0,0,0,0,0,0,0
DB 15,0,0,0,0,0,0,0
DB 31,0,0,0,0,0,0,0
DB 63,0,0,0,0,0,0,0
DB 127,0,0,0,0,0,0,0
END ASMDATA
ASMDATA my64numbers
DB 0,0,0,0,0,0,0,0
DB 1,0,0,0,0,0,0,0
DB 2,0,0,0,0,0,0,0
DB 4,0,0,0,0,0,0,0
DB 8,0,0,0,0,0,0,0
DB 16,0,0,0,0,0,0,0
DB 32,0,0,0,0,0,0,0
DB 64,0,0,0,0,0,0,0
DB 128,0,0,0,0,0,0,0
DB 0,1,0,0,0,0,0,0
DB 0,2,0,0,0,0,0,0
DB 0,4,0,0,0,0,0,0
DB 0,8,0,0,0,0,0,0
DB 0,16,0,0,0,0,0,0
DB 0,32,0,0,0,0,0,0
DB 0,64,0,0,0,0,0,0
DB 0,128,0,0,0,0,0,0
DB 0,0,1,0,0,0,0,0
DB 0,0,2,0,0,0,0,0
D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