UChar_t KVSpectroDetector::GetPosition( Double_t *XYZf, Int_t idx ){ // Returns in the array 'XYZf', the coordinates (in cm) of a point randomly drawn in the // active volume with index 'idx'. We assume that the shape of this // volume is a TGeoBBox. These coordinates are given in the focal-plane // of reference. // The function returns a binary code where: // - bit 0 = 1 if X is OK (001); // - bit 1 = 1 if Y is OK (010); // - bit 2 = 1 if Z is OK (100); // // If no coordinates are OK, the returned value is null (000) and if // X, Y and Z are OK then the returned value is equal 7 (111). TGeoVolume *vol = GetActiveVolume(idx); if( !vol || !PositionIsOK() ) return 0; const TGeoBBox *box = (TGeoBBox *)vol->GetShape(); Double_t dx = box->GetDX(); Double_t dy = box->GetDY(); Double_t dz = box->GetDZ(); Double_t ox = (box->GetOrigin())[0]; Double_t oy = (box->GetOrigin())[1]; Double_t oz = (box->GetOrigin())[2]; Double_t xyz[3]; xyz[0] = ox+( TestBit(kRdmPos) ? dx*(2*gRandom->Rndm()-1) : 0.); xyz[1] = oy+( TestBit(kRdmPos) ? dy*(2*gRandom->Rndm()-1) : 0.); xyz[2] = oz+( TestBit(kRdmPos) ? dz*(2*gRandom->Rndm()-1) : 0.); if( ActiveVolumeToFocal( xyz , XYZf, idx ) ) return 7; return 0; }
void ravage(void) { if (inc_wordnumber(words[wordnumber], "whom")) return; if (wordtype[wordnumber] == NOUNS && (TestBit(location[position].objects, wordvalue[wordnumber]) || (wordvalue[wordnumber] == NORMGOD && TestBit(location[position].objects, BATHGOD)))) { ourtime++; switch (wordvalue[wordnumber]) { case NORMGOD: puts("You attack the goddess, and she screams as you beat her. She falls down"); if (TestBit(location[position].objects, BATHGOD)) puts("crying and tries to cover her nakedness."); else puts("crying and tries to hold her torn and bloodied dress around her."); power += 5; pleasure += 8; ego -= 10; wordnumber--; godready = -30000; murder(); win = -30000; break; case NATIVE: puts("The girl tries to run, but you catch her and throw her down. Her face is"); puts("bleeding, and she screams as you tear off her clothes."); power += 3; pleasure += 5; ego -= 10; wordnumber--; murder(); if (rnd(100) < 50) { puts("Her screams have attracted attention. I think we are surrounded."); SetBit(location[ahead].objects, WOODSMAN); SetBit(location[ahead].objects, DEADWOOD); SetBit(location[ahead].objects, MALLET); SetBit(location[back].objects, WOODSMAN); SetBit(location[back].objects, DEADWOOD); SetBit(location[back].objects, MALLET); SetBit(location[left].objects, WOODSMAN); SetBit(location[left].objects, DEADWOOD); SetBit(location[left].objects, MALLET); SetBit(location[right].objects, WOODSMAN); SetBit(location[right].objects, DEADWOOD); SetBit(location[right].objects, MALLET); } break; default: puts("You are perverted."); wordnumber++; } } else { printf("%s: Who?\n", words[wordnumber]); wordnumber++; } }
void printTwinPrimes(unsigned long int *numOfBitsInBitArray){ unsigned long int i; for(i = 0; i < *numOfBitsInBitArray - 1; i++){ if(TestBit(bitArray, i)){ if(TestBit(bitArray, (i + 1))){ printf("%lu %lu\n", NumAtBitPosition(i), NumAtBitPosition((i + 1))); } } } }
void computeTwinPrimes(unsigned long int *numOfBitsInBitArray){ unsigned long int i; for(i = 0; i < *numOfBitsInBitArray - 1; i++){ if(TestBit(bitArray, i)){ if(TestBit(bitArray, (i + 1))){ //Twin primes are represented by positions i and i + 1 } } } }
void crash(void) { int hurt1, hurt2; fuel--; if (!location[position].flyhere || (TestBit(location[position].objects, LAND) && fuel <= 0)) { if (!location[position].flyhere) puts("You're flying too low. We're going to crash!"); else { puts("You're out of fuel. We'll have to crash land!"); if (!location[position].down) { puts("Your viper strikes the ground and explodes into fiery fragments."); puts("Thick black smoke billows up from the wreckage."); die(0); } position = location[position].down; } notes[LAUNCHED] = 0; SetBit(location[position].objects, CRASH); ourtime += rnd(CYCLE / 4); puts("The viper explodes into the ground and you lose consciousness..."); zzz(); hurt1 = rnd(NUMOFINJURIES - 2) + 2; hurt2 = rnd(NUMOFINJURIES - 2) + 2; injuries[hurt1] = 1; injuries[hurt2] = 1; injuries[0] = 1; /* abrasions */ injuries[1] = 1; /* lacerations */ printf("I'm afraid you have suffered %s and %s.\n", ouch[hurt1], ouch[hurt2]); } }
//______________________________________________________________________________ void KVCanvas::DrawEventStatus(Int_t event, Int_t px, Int_t py, TObject* selected) { // Report name and title of primitive below the cursor. // // This function is called when the option "Event Status" // in the canvas menu "Options" is selected. const Int_t kTMAX = 256; static char atext[kTMAX]; if (!TestBit(kShowEventStatus) || !selected) return; if (!fCanvasImp) return; //this may happen when closing a TAttCanvas TVirtualPad* savepad; savepad = gPad; gPad = GetSelectedPad(); fCanvasImp->SetStatusText(selected->GetTitle(), 0); fCanvasImp->SetStatusText(selected->GetName(), 1); if (event == kKeyPress) snprintf(atext, kTMAX, "%c", (char) px); else snprintf(atext, kTMAX, "%d,%d", px, py); fCanvasImp->SetStatusText(atext, 2); fCanvasImp->SetStatusText(selected->GetObjectInfo(px, py), 3); gPad = savepad; }
Bool_t KVHarpeeSi::PositionIsOK() { // Returns true if all the conditions to access to the particle position // are verified. In this case the position is given by the method // GetPosition(...). // The conditions are: // -the multiplicity of fired ( "Pany" option of Fired() ) Harpee Si // detectors must be equal to one; // -this detectector must be the fired detector. if (!TestBit(kPosIsOK)) { Int_t mult = 0; TIter next(fHarpeeSiList); KVHarpeeSi* si = NULL; while ((si = (KVHarpeeSi*)next())) { if (si->Fired("Pany")) { mult++; fSiForPosition = si; } } if (mult != 1) fSiForPosition = NULL; SetBit(kPosIsOK); } return fSiForPosition == this; }
static void verb_with_all(unsigned int *testarray, int objflg, int (*verbfunc)(void), const char *verbname) { int things, n; things = 0; if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(testarray, n) && (objsht[n] || (objflg & objflags[n]))) { things++; wordvalue[wordnumber + 1] = n; /* Assume it's a NOUN if no short description */ if (objsht[n]) wordtype[wordnumber + 1] = OBJECT; else wordtype[wordnumber + 1] = NOUNS; wordnumber = verbfunc(); } wordnumber += 2; if (!things) printf("Nothing to %s!\n", verbname); } else verbfunc(); }
//______________________________________________________________________________ void KVCanvas::RunAutoExec() { // Execute the list of TExecs in the current pad. if (!TestBit(kAutoExec)) return; if (!gPad) return; ((TPad*)gPad)->AutoExec(); }
void Bert::StopRxBertTest() { ClearBit(m_pcpr, 4); m_board.Write(L_PCPR, 0x11); ClearChannelsMask(); m_board.Write(L_PCPR, m_pcpr); SetChannelsMask(); byte temp = m_board.Read(L_PCPR); if(!TestBit(temp, 0x0)) m_board.MaskClear(L_BIC, 0x01); }
int use(void) { if (inc_wordnumber(words[wordnumber], "what")) return(-1); if (wordvalue[wordnumber] == AMULET && TestBit(inven, AMULET) && position != FINAL) { puts("The amulet begins to glow."); if (TestBit(inven, MEDALION)) { puts("The medallion comes to life too."); if (position == 114) { location[position].down = 160; whichway(location[position]); puts("The waves subside and it is possible to descend to the sea cave now."); ourtime++; wordnumber++; return (-1); } } puts("A light mist falls over your eyes and the sound of purling water trickles in"); puts("your ears. When the mist lifts you are standing beside a cool stream."); if (position == 229) position = 224; else position = 229; ourtime++; notes[CANTSEE] = 0; wordnumber++; return (0); } else if (position == FINAL) puts("The amulet won't work in here."); else if (wordvalue[wordnumber] == COMPASS && TestBit(inven, COMPASS)) printf("Your compass points %s.\n", truedirec(NORTH,'-')); else if (wordvalue[wordnumber] == COMPASS) puts("You aren't holding the compass."); else if (wordvalue[wordnumber] == AMULET) puts("You aren't holding the amulet."); else puts("There is no apparent use."); wordnumber++; return (-1); }
void printPrimes(unsigned long int *numOfBitsInBitArray){ unsigned long int i; printf("2\n"); for(i = 0; i < *numOfBitsInBitArray; i++){ if(TestBit(bitArray, i)){ printf("%lu\n", NumAtBitPosition(i)); } } }
void printobjs(void) { unsigned int *p = location[position].objects; int n; printf("\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(p, n) && objdes[n]) puts(objdes[n]); }
void newlocation(void) { news(); if (beenthere[position] <= ROOMDESC) beenthere[position]++; if (notes[LAUNCHED]) crash(); /* decrements fuel & crash */ if (matchlight) { puts("Your match splutters out."); matchlight = 0; } if (!notes[CANTSEE] || TestBit(inven, LAMPON) || TestBit(location[position].objects, LAMPON)) { writedes(); printobjs(); } else puts("It's too dark to see anything in here!"); whichway(location[position]); }
int main() { int BITFIELDLENGTH = 512; //16*32 is 512 // bitfieldlength is evenly divisible by 32, right? right? unsigned long size = (BITFIELDLENGTH/(sizeof(int)*8)); printf("sizeof int is %lu bytes (%lu bits)\n",sizeof(int), sizeof(int)*8); printf("field length %d means %lu integers and %lu bytes\n", BITFIELDLENGTH, size, (size*sizeof(int))); //allocate and initialize to 0 int *BitField = calloc(size,sizeof(int)); SetBit(BitField,99); //set bit 99 to 1 SetBit(BitField,100); //set bit 100 to 1 SetBit(BitField,101); //set bit 101 to 1 int a = TestBit(BitField,99); //get val of bits 99-101 int b = TestBit(BitField,100); int c = TestBit(BitField,101); printf("vals are: %d, %d, %d\n",a,b,c); ClearBit(BitField,100); //clear bit 100 a = TestBit(BitField,99); b = TestBit(BitField,100); c = TestBit(BitField,101); printf("vals are now: %d, %d, %d\n",a,b,c); }
uint8_t Gui::getTouch(void) { touch((1 << FLAG_REGISTER_END) | (1 << FLAG_REGISTER_COORDINATES)); if (TestBit(_touchBuffer.Flag_Register, FLAG_REGISTER_END)) { drag = 0; } else if (TestBit(_touchBuffer.Flag_Register, FLAG_REGISTER_COORDINATES)) { drag = 1; } if (TestBit(_touchBuffer.Flag_Register, FLAG_REGISTER_COORDINATES)) { touchX = ((_calib.An * _touchBuffer.x_pos) + (_calib.Bn * _touchBuffer.y_pos) + _calib.Cn) / _calib.divider; touchY = ((_calib.Dn * _touchBuffer.x_pos) + (_calib.En * _touchBuffer.y_pos) + _calib.Fn) / _calib.divider; return 1; } return 0; }
void printElemBits( const dcElement_t* const input ) { size_t alphLen = input -> alphSize; printf("[ "); for( size_t bitIdx = 0; bitIdx < input -> alphSize; bitIdx++ ) { if( TestBit(input -> element, bitIdx) ) { //printf("Bit index: %d\n", alphLen * elemNum + bitIdx ); printf("1,"); } else { printf("0,"); } } printf(" ]\n"); }
void undress(void) { if (inc_wordnumber(words[wordnumber], "whom")) return; if (wordvalue[wordnumber] == NORMGOD && (TestBit(location[position].objects, NORMGOD)) && godready >= 2) { wordnumber--; love(); } else { wordnumber--; ravage(); } }
void CNewGameState::Render() { // Draw the base menu's stuff CBaseMenu::Render(); // Draw this menu's stuff pFont->Write("New Slot 1", 32, 12 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); if(TestBit(GAME->m_cLoadedOrNot, 0)) pFont->Write("CONTAINS SAVED DATA", 250, 12 * pFont->GetCharHeight(), D3DCOLOR_XRGB(128, 192, 255)); else pFont->Write("Empty slot", 250, 12 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); pFont->Write("New Slot 2", 32, 13 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); if(TestBit(GAME->m_cLoadedOrNot, 1)) pFont->Write("CONTAINS SAVED DATA", 250, 13 * pFont->GetCharHeight(), D3DCOLOR_XRGB(128, 192, 255)); else pFont->Write("Empty slot", 250, 13 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); pFont->Write("New Slot 3", 32, 14 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); if(TestBit(GAME->m_cLoadedOrNot, 2)) pFont->Write("CONTAINS SAVED DATA", 250, 14 * pFont->GetCharHeight(), D3DCOLOR_XRGB(128, 192, 255)); else pFont->Write("Empty slot", 250, 14 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); pFont->Write("Back", 32, 15 * pFont->GetCharHeight(), D3DCOLOR_XRGB(255, 255, 255)); }
void light(void) { /* synonyms = {strike, smoke} */ if (TestBit(inven, MATCHES) && matchcount) { puts("Your match splutters to life."); ourtime++; matchlight = 1; matchcount--; if (position == 217) { puts("The whole bungalow explodes with an intense blast."); die(0); } } else puts("You're out of matches."); }
void RemoveFromCustomFolder(LPTREEFOLDER lpFolder,int driver_index) { if ((lpFolder->m_dwFlags & F_CUSTOM) == 0) { MessageBox(GetMainWindow(),"Unable to remove game from non-custom folder", MAME32NAME,MB_OK | MB_ICONERROR); return; } if (TestBit(lpFolder->m_lpGameBits,driver_index) != 0) { RemoveGame(lpFolder,driver_index); if (TrySaveExtraFolder(lpFolder) == FALSE) AddGame(lpFolder,driver_index); // undo on error } }
int land(void) { if (notes[LAUNCHED] && TestBit(location[position].objects, LAND) && location[position].down) { notes[LAUNCHED] = 0; position = location[position].down; SetBit(location[position].objects, VIPER); fuel -= 2; ourtime++; puts("You are down."); return (1); } else puts("You can't land here."); return (0); }
int drive(void) { if (TestBit(location[position].objects, CAR)) { puts("You hop in the car and turn the key. There is a perceptible grating noise,"); puts("and an explosion knocks you unconscious..."); ClearBit(location[position].objects, CAR); SetBit(location[position].objects, CRASH); injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1; ourtime += 15; zzz(); return (0); } else puts("There is nothing to drive here."); return (-1); }
/** * The following fn should only needed this for testing, so it's not in the .h file. * * Prints a representation of a dynamic character as a matrix of bits. */ void printCharBits( dynChar_t* input ) { printf("[\n"); size_t alphLen = input -> alphSize; for( size_t elemNum = 0; elemNum < input -> numElems; elemNum++ ) { for( size_t bitIdx = 0; bitIdx < alphLen; bitIdx++ ) { if( TestBit(input -> dynChar, alphLen * elemNum + bitIdx) ) { // printf("Bit index: %lu\n", alphLen * elemNum + bitIdx ); printf("1,"); } else { printf("0,"); } } printf("\n"); } printf("]\n"); }
void Bert::StopTxBertTest() { ClearBit(m_pcpr, 0); m_board.Write(L_PCPR, 0x11); ClearChannelsMask(); m_board.Write(L_PCPR, m_pcpr); SetChannelsMask(); m_board.MaskClear(L_BC1, 0x80); m_board.MaskSet(L_BC1, 0x80); m_board.Write(L_LBCR, 0x00); byte temp = m_board.Read(L_PCPR); if(!TestBit(temp, 0x4)) m_board.MaskClear(L_BIC, 0x01); }
int launch(void) { if (TestBit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) { if (fuel > 4) { ClearBit(location[position].objects, VIPER); position = location[position].up; notes[LAUNCHED] = 1; ourtime++; fuel -= 4; puts("You climb into the viper and prepare for launch."); puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat."); return (1); } else puts("Not enough fuel to launch."); } else puts("Can't launch."); return (0); }
void drink(void) { int n; if (TestBit(inven, POTION)) { puts("The cool liquid runs down your throat but turns to fire and you choke."); puts("The heat reaches your limbs and tingles your spirit. You feel like falling"); puts("asleep."); ClearBit(inven, POTION); WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; for (n = 0; n < NUMOFINJURIES; n++) injuries[n] = 0; ourtime++; zzz(); } else puts("I'm not thirsty."); }
/* Find next bit that matches 'bSet' * * 'nStartPos' specifies the bit to start search after * 'bSet' specifies to search for a set or unset bit * * Returns -1 if no bits are found */ int FindBit(LPBITS lpBits, int nStartPos, bool bSet) { if (!lpBits || !lpBits->m_nSize || !lpBits->m_lpBits) return -1; UINT end = lpBits->m_nSize << 3; if (nStartPos < 0) nStartPos = 0; for (int i = nStartPos; i < end; i++) { bool res = (TestBit(lpBits, i)) ? true : false; if ((res && bSet) || (!res && !bSet)) return i; } return -1; }
/* Find next bit that matches 'bSet' * * 'nStartPos' specifies the bit to start search after * 'bSet' specifies to search for a set or unset bit * * Returns -1 if no bits are found */ int FindBit(LPBITS lpBits, int nStartPos, BOOL bSet) { UINT i = 0; if (!lpBits || !lpBits->m_nSize || !lpBits->m_lpBits) return -1; UINT end = lpBits->m_nSize << 3; if (nStartPos < 0) nStartPos = 0; for (i = nStartPos; i < end; i++) { BOOL res = (TestBit(lpBits, i)) ? TRUE : FALSE; if ((res && bSet) || (!res && !bSet)) return i; } return -1; }
int jump(void) { int n; switch (position) { default: puts("Nothing happens."); return (-1); case 242: position = 133; break; case 214: case 215: case 162: case 159: position = 145; break; case 232: position = FINAL; break; case 3: position = 1; break; case 172: position = 201; } puts("Ahhhhhhh..."); injuries[12] = injuries[8] = injuries[7] = injuries[6] = 1; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n)) { ClearBit(inven, n); SetBit(location[position].objects, n); } carrying = 0; encumber = 0; return (0); }