/*==============================================================================*/ /* Program to calculcate ACR/AMR registers... */ /* */ /* DATE: 2004-Jun-06 23:45:45 */ /* */ /* Copyright (c) 2004 Attila Vass */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining a copy */ /* of this software and associated documentation files (the "Software"),to deal */ /* in the Software without restriction, including without limitation the rights */ /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */ /* copies of the Software, and to permit persons to whom the Software is */ /* furnished to do so, subject to the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be included in */ /* all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */ /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */ /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */ /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS */ /* IN THE SOFTWARE. */ /*==============================================================================*/ /* cc acramr_calc.c -o acramr_calc './acramr_calc 0x3cb 0x3ca 0x3c8 0x348 0x3b' produces the following output : Working with 5 IDs : 3CB 001111001011 3CA 001111001010 3C8 001111001000 348 001101001000 03B 000000111011.... Number of possible combinations = 30 Best result = 9 Worst result = 264 9 results : ACR = 07606900 AMR = 000F106F :: 03B 348 349 34A 34B 3C8 3C9 3CA 3CB 9 results : ACR = 69000760 AMR = 106F000F :: 03B 348 349 34A 34B 3C8 3C9 3CA 3CB */ #include #include #define USE_SORTING 1 #define MAXARRAYSIZE 32 int ID[MAXARRAYSIZE]; int numofids=0,numofposs; int WorstNo,BestNo,ResultPhase; int WID1[MAXARRAYSIZE],WID2[MAXARRAYSIZE],WIDW[MAXARRAYSIZE]; int ACR,AMR; #ifdef USE_SORTING int *ResultsBuffer=NULL; int NoOfResults=0,SizeOfResultsBuffer=0; #endif unsigned char PCOM[4096]; int GiveACRAMR(int *IDBuffer) // -1 terminated { int a,b,c,d; ACR=0;AMR=0; for(a=0;a<11;a++) { c=-1; for(b=0;IDBuffer[b]!=-1;b++) { d=((IDBuffer[b]>>a)&1); switch(c) { case -1 : // no data yet. c=d; break; case 1 : // so far 1s if(d==0) c=2; // this is going to be a don't care bit break; case 0 : if(d==1) c=2; break; } } if(c==2) AMR|=(1<=0;b--) { if(((AMR>>b)&1)) c*=2; } return(c); } void PrintHexa(int NumOfDigits,int Number) { register int a,b; for(a=(NumOfDigits-1);a>=0;a--) { b=((Number>>(a<<2))&0xF); if(b<10) printf("%d",b); else printf("%c",('A'+b-10)); } } #ifdef USE_SORTING void SortAndPrintResults(void) // Just a quick bubble... No brainer, since result is limited... { register int a,b,c; for(a=0;a<(NoOfResults-1);a++) { for(b=(a+1);bResultsBuffer[b]) { c=ResultsBuffer[a]; ResultsBuffer[a]=ResultsBuffer[b]; ResultsBuffer[b]=c; } } } for(a=0;a>=1; if(tam&1) { PCOM[a]=1; if(--c==0) { CEval(); PCOM[a]=0; } else CWalkThisMany(npc,c,a+1); PCOM[a]=0;c=tm; } } return; } void CWalker(int npc) { int a,k; for(a=1;a>5; am=lamr>>5; c=1;d=0; for(b=11;b>=0;b--) { if(((am>>b)&1)) {c*=2;++d;} } #ifdef USE_SORTING AddToResultsBuffer(ac); #else printf("%03x ",ac);fflush(stdout); #endif if(d) { ACR=ac;AMR=am; CWalker(npc); } } void Eval(void) { int a,b,c,r,r1,r2; int lACR,lAMR,lsACR,lsAMR; numofposs++;b=0;c=0; for(a=0;aWorstNo) WorstNo=r; } else { if(r==BestNo) { printf("\n %d results : ",r);fflush(stdout); r1=GiveACRAMR(WID1); ACR<<=5;AMR<<=5; AMR|=0xF; // don't care about data bytes lACR=ACR;lAMR=AMR; r2=GiveACRAMR(WID2); ACR<<=5;AMR<<=5; AMR|=0xF; // don't care about data bytes lsACR=ACR;lsAMR=AMR; // printf("\tACR = %04x%04x AMR = %04x%04x",lACR,ACR,lAMR,AMR); printf("\tACR = ");PrintHexa(4,lACR);PrintHexa(4,ACR); printf(" AMR = ");PrintHexa(4,lAMR);PrintHexa(4,AMR); printf("\n\t :: ");fflush(stdout); NoOfResults=0; GiveCombo(r1,lACR,lAMR); GiveCombo(r2,lsACR,lsAMR); #ifdef USE_SORTING SortAndPrintResults(); #endif } } } void WalkThisMany(int tm,int frh) { int a,c=tm; for(a=frh;a1) { while(a=MAXARRAYSIZE) { printf("\nSorry, code configured for max %d values...",MAXARRAYSIZE); printf("\nPlease change MAXARRAYSIZE variable and rebuild the code.\n(I was lazy to do proper malloc... Sorry...)\n\n");fflush(stdout); exit(0); } if((sscanf(argv[a],"%0xd",&ID[numofids]))!=1) if((sscanf(argv[a],"%d",&ID[numofids]))!=1) { printf("Error reading '%s'",argv[a]);fflush(stdout); return(1); } ++numofids; ++a; } } else { printf("Usage : %s id id ... ( 0xXXXX for hexa or DDDDD for decimals...\n\n",argv[0]);fflush(stdout); return(1); } printf("\nWorking with %d IDs : ",numofids); for(a=0;a0;b--) { printf("%d",((ID[a]>>b)&1)); } printf("%d",((ID[a]>>b)&1)); } for(a=0;a