// Rabin-Miller method for finding a strong pseudo-prime // Preconditions: High bit and low bit of n = 1 bool RabinMillerPrimeTest( IRandom *prng, const u32 *n, // Number to check for primality int limbs, // Number of limbs in n u32 k) // Confidence level (40 is pretty good) { // n1 = n - 1 u32 *n1 = (u32 *)alloca(limbs*4); Set(n1, limbs, n); Subtract32(n1, limbs, 1); // d = n1 u32 *d = (u32 *)alloca(limbs*4); Set(d, limbs, n1); // remove factors of two from d while (!(d[0] & 1)) ShiftRight(limbs, d, d, 1); u32 *a = (u32 *)alloca(limbs*4); u32 *t = (u32 *)alloca(limbs*4); u32 *p = (u32 *)alloca((limbs*2)*4); u32 n_inv = MonReducePrecomp(n[0]); // iterate k times while (k--) { do prng->Generate(a, limbs*4); while (GreaterOrEqual(a, limbs, n, limbs)); // a = a ^ d (Mod n) ExpMod(a, limbs, d, limbs, n, limbs, n_inv, a); Set(t, limbs, d); while (!Equal(limbs, t, n1) && !Equal32(a, limbs, 1) && !Equal(limbs, a, n1)) { // TODO: verify this is actually working // a = a^2 (Mod n), non-critical path Square(limbs, p, a); Modulus(p, limbs*2, n, limbs, a); // t <<= 1 ShiftLeft(limbs, t, t, 1); } if (!Equal(limbs, a, n1) && !(t[0] & 1)) return false; } return true; }
void ConditionalSquareGradientSum(const uint8_t * src, size_t srcStride, size_t width, size_t height, const uint8_t * mask, size_t maskStride, uint8_t value, uint64_t * sum) { assert(width >= A + 2 && height >= 3); if (align) assert(Aligned(src) && Aligned(srcStride) && Aligned(mask) && Aligned(maskStride)); src += srcStride; mask += maskStride; height -= 2; size_t bodyWidth = Simd::AlignLo(width - 1, A); v128_u8 noseMask = ShiftRight(K8_FF, 1); v128_u8 tailMask = ShiftLeft(K8_FF, A - width + 1 + bodyWidth); size_t alignedWidth = Simd::AlignLo(bodyWidth - A, DA); v128_u8 _value = SetU8(value); *sum = 0; for (size_t row = 0; row < height; ++row) { v128_u32 sums[4] = { K32_00000000, K32_00000000, K32_00000000, K32_00000000 }; { const v128_u8 _mask = vec_and(Compare8u<compareType>(Load<false>(mask + 1), _value), noseMask); AddSquareDifference<false>(src + 1, 1, _mask, sums[0]); AddSquareDifference<false>(src + 1, srcStride, _mask, sums[1]); } size_t col = A; for (; col < alignedWidth; col += DA) { ConditionalSquareGradientSum<align, compareType>(src, srcStride, mask, col, _value, sums); ConditionalSquareGradientSum<align, compareType>(src, srcStride, mask, col + A, _value, sums + 2); } for (; col < bodyWidth; col += A) ConditionalSquareGradientSum<align, compareType>(src, srcStride, mask, col, _value, sums); if (bodyWidth != width - 1) { size_t offset = width - A - 1; const v128_u8 _mask = vec_and(Compare8u<compareType>(Load<false>(mask + offset), _value), tailMask); AddSquareDifference<false>(src + offset, 1, _mask, sums[0]); AddSquareDifference<false>(src + offset, srcStride, _mask, sums[1]); } sums[0] = vec_add(vec_add(sums[0], sums[1]), vec_add(sums[2], sums[3])); *sum += ExtractSum(sums[0]); src += srcStride; mask += maskStride; } }
void AnimateHorizontal(uint8_t prev, uint8_t gear) { prev += SYMBOL_GEAR_NUMBER; gear += SYMBOL_GEAR_NUMBER; for(uint8_t i=0;i<=8;i++) { if( gear > prev ) ShiftLeft(i, (PGM_P)FONTTAB+prev*8, (PGM_P)FONTTAB+gear*8 ); else ShiftRight(i, (PGM_P)FONTTAB+prev*8, (PGM_P)FONTTAB+gear*8 ); _delay_ms(GEAR_ANIM_DELAY); } ledPutc(gear); }
bool StateGrid::MoveForward(int32_t id) { int32_t collideId = m_horses[id].Collide(); if(collideId >= 0) { // try shift right if(m_shifted[collideId] || !ShiftRight(collideId)) { // try shift left if(!ShiftLeft(collideId)) { // try move forward } } } }
void PlayGame() { char userChoice = 'k'; printf("Going to start game. Use AD for left, right. WS for up, down.\n"); printf("k to kill game.\n"); InitTiles(); NextStep(); do{ if(!NextStep()){ break; } PrintTiles(); refresh(); // printing on screen - via ncurses. userChoice = getch(); // if(userChoice=='\n') userChoice = getchar(); switch(userChoice){ case 'a': case 'A': MergeLeft(); ShiftLeft(); break; case 'd': case 'D': MergeRight(); ShiftRight(); break; case 'w': case 'W': MergeUp(); ShiftUp(); break; case 's': case 'S': MergeDown(); ShiftDown(); break; } clear(); } while(SpaceAvailable() && userChoice != 'k'); printf("\nGame over.\n"); }
static void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, short data[2][512], float rapport, int drawit, TentacleFXData *fx_data) { int tmp; int tmp2; int color; int colorlow; float dist,dist2,rotangle; if ((!drawit) && (fx_data->ligs>0.0f)) fx_data->ligs = -fx_data->ligs; fx_data->lig += fx_data->ligs; if (fx_data->lig > 1.01f) { if ((fx_data->lig>10.0f) | (fx_data->lig<1.1f)) fx_data->ligs = -fx_data->ligs; if ((fx_data->lig<6.3f)&&(goom_irand(goomInfo->gRandom,30)==0)) fx_data->dstcol=goom_irand(goomInfo->gRandom,NB_TENTACLE_COLORS); fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff,0x01); fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff00,0x0100); fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff0000,0x010000); fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff000000,0x01000000); color = fx_data->col; colorlow = fx_data->col; lightencolor(&color,fx_data->lig * 2.0f + 2.0f); lightencolor(&colorlow,(fx_data->lig/3.0f)+0.67f); rapport = 1.0f + 2.0f * (rapport - 1.0f); rapport *= 1.2f; if (rapport > 1.12f) rapport = 1.12f; pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data); for (tmp=0;tmp<nbgrid;tmp++) { for (tmp2=0;tmp2<definitionx;tmp2++) { float val = (float)(ShiftRight(data[0][goom_irand(goomInfo->gRandom,511)],10)) * rapport; fx_data->vals[tmp2] = val; } grid3d_update (fx_data->grille[tmp], rotangle, fx_data->vals, dist2); } fx_data->cycle+=0.01f; for (tmp=0;tmp<nbgrid;tmp++) grid3d_draw (goomInfo, fx_data->grille[tmp],color,colorlow,dist,buf,back,W,H); } else { fx_data->lig = 1.05f; if (fx_data->ligs < 0.0f) fx_data->ligs = -fx_data->ligs; pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data); fx_data->cycle+=0.1f; if (fx_data->cycle > 1000) fx_data->cycle = 0; } }
uint GetString( uint FieldRow, uint FieldCol, uint length, uint displen, uint *cursor, uchar *pInbuf, uint InFlags, POPUPSHELL *pShell) { /***************************************************************************/ /* Diagram to explain local variables. */ /* */ /* 0 ... 10 ... 40 ... 200 */ /* */ /* +-------------------------------+ */ /* +----------| |---------------------+ */ /* | | Portion of the string shown | | */ /* | | in the screen. | | */ /* +----------| |---------------------+ */ /* +-------------------------------+ */ /* |<---- Display Length --------->| */ /* */ /* |<------------ length (length of the entire buffer) ------------>| */ /* */ /* In the above example: */ /* */ /* length ===> 200 */ /* DisplayLength ===> 30 */ /* DisplayOffset ===> 10 */ /* */ /***************************************************************************/ uint key; int n, i; ushort rc; int voff; uint IsInsertMode = 0, scratch, BufLen; uint DisplayOffset; uint CursorRow, CursorCol; int FirstKeyEntry = TRUE; /*910*/ uint flags = InFlags; /*910*/ int state = MOU_STATE_UP; /* assume this! */ /*910*/ int NextState = 0; /*910*/ BUTTON *pButtonDown = NULL; /*910*/ /***************************************************************************/ /* */ /* flags - Flags which indicate type of the field. */ /* (AUTOEXIT / HEXONLY / BINONLY) */ /***************************************************************************/ if(pShell) flags = pShell->Flags; /*910*/ /***************************************************************************/ /* - Set keyboard flush buffer flag to indiacte not to flush the keyboard */ /* buffer while we are in getstring. */ /* - Initialise the local variables. */ /***************************************************************************/ SetFlushBufferFlag( NOFLUSHNOW ); /*820*/ FieldDisplayLength = displen; DisplayOffset = 0; CursorRow = FieldRow; CursorCol = ( *cursor > displen ) ? FieldCol : FieldCol + *cursor; #ifdef MSH if(iview) { CursorRow+=RowStart; FieldRow+=RowStart; CursorCol+=ColStart; FieldCol+=ColStart; } #endif /***************************************************************************/ /* Allocate memory for the local buffer. */ /***************************************************************************/ Buffer = (uchar *)Talloc( (length+1) * sizeof( uchar ) ); memset( Buffer, '\0', length+1 ); if(!iview) { /***************************************************************************/ /* Adjust display length if the length specified by the caller goes out of */ /* the screen. */ /***************************************************************************/ if( FieldCol + FieldDisplayLength > VideoCols ) FieldDisplayLength = VideoCols - FieldCol; /***************************************************************************/ /* Check to see if the field would over lap some other window, if so adjust*/ /* the display length accordingly. */ /***************************************************************************/ if( FieldDisplayLength + FieldCol > BoundPtr[FieldRow] ) FieldDisplayLength = BoundPtr[FieldRow] - FieldCol; } else { #ifdef MSH if( FieldDisplayLength + FieldCol - ColStart> VideoWidth ) FieldDisplayLength = VideoWidth - FieldCol + ColStart; #endif }/* End if*/ /***************************************************************************/ /* RightScrollOffset is the amount of scrolling to be done when the user */ /* goes out of the display length. It is 2/3 rds of the display length. */ /***************************************************************************/ RightScrollOffset = (FieldDisplayLength * 2)/3; LeftScrollOffset = FieldDisplayLength - RightScrollOffset; FieldBase = (uchar *)Sel2Flat( HiFlat(VideoPtr) ) + ( voff = 2*(FieldRow*VideoCols + FieldCol) ); FieldType = flags; /***************************************************************************/ /* Depending on the type of the string copy the initial string to the local*/ /* buffer. Display the string. */ /***************************************************************************/ if( (FieldType & HEXONLY) || (FieldType & BINONLY) ) { for( i = 0; i < length; i++ ) Buffer[i] = FieldBase[i*2]; } else strcpy( Buffer, pInbuf ); DisplayField( DisplayOffset ); VioShowBuf( (ushort)voff,(ushort) (2*FieldDisplayLength), 0 ); VioSetCurType( &NormalCursor, 0 ); for(;;) { VioSetCurPos( (ushort)CursorRow, (ushort)CursorCol, 0 ); Event = GetEvent( SEM_INDEFINITE_WAIT ); switch( Event->Type ) { case TYPE_MOUSE_EVENT: /*910*/ { /*910*/ /******************************************************************910*/ /* Test for mouse event between the string brackets. 910*/ /******************************************************************910*/ if( ( Event->Row == (ushort)FieldRow ) && /*910*/ ( Event->Col >= (ushort)FieldCol ) && /*910*/ ( Event->Col <= ((ushort)FieldCol+(ushort)FieldDisplayLength-1)) ) /*910*/ { /*910*/ /*****************************************************************910*/ /* - If it's a button down event then set the cursor at the 910*/ /* end of the string or on the character that was clicked on. 910*/ /*****************************************************************910*/ if( Event->Value == EVENT_BUTTON_1_DOWN) /*910*/ { /*910*/ BufLen = strlen( Buffer ); /*910*/ if( (DisplayOffset + (Event->Col - FieldCol)) > BufLen ) /*910*/ { /*910*/ keybeep(); /*910*/ CursorCol = FieldCol + (BufLen - DisplayOffset); /*910*/ } /*910*/ else /*910*/ CursorCol = (uint)Event->Col; /*910*/ } /*910*/ /*****************************************************************910*/ /* - Ignore events between the brackets that are not button 910*/ /* down events. 910*/ /* - Any mouse event between []s turns off the erasure of a 910*/ /* cursor sensitive prompt. 910*/ /*****************************************************************910*/ FieldType &= ~CLEAR1ST; /*910*/ continue; /*910*/ } /*910*/ /*910*/ /**********************************************************************/ /* - handle strings that are not in the context of a popup. */ /**********************************************************************/ if(pShell == NULL ) /*910*/ { /*910*/ NextState = GetMouseState( Event ); /*910*/ if( (state == MOU_STATE_UP) && /*910*/ (NextState == MOU_STATE_DOWN) /*910*/ ) /*910*/ { /*910*/ key = LEFTMOUSECLICK; /*910*/ break; /*910*/ } /*910*/ /*910*/ state = NextState; /*910*/ continue; /*910*/ } /*910*/ /******************************************************************910*/ /* - Now, handle mouse events outside the []s within the context 910*/ /* of a popup. 910*/ /* 910*/ /* - Button events are valid on the release event. 910*/ /* 910*/ /* - Transitions from up to down "outside" the <>s and []s 910*/ /* are returned to the caller as a LEFTMOUSECLICK. 910*/ /* 910*/ /* ------------------------ 910*/ /* | | 910*/ /* | ----------- 910*/ /* | <------------| |<---------------- 910*/ /* | | ----------- | 910*/ /* | ---- ---- 910*/ /* | | |--- ---| |--- 910*/ /* | | UP | | BU,BUM BD,BDM | | DN | | 910*/ /* | | |<-- -->| |<-- 910*/ /* | ---- ---- 910*/ /* | | | 910*/ /* | | | 910*/ /* | | ----------- | 910*/ /* | ------------>| |----------------> 910*/ /* | ----------- 910*/ /* | | 910*/ /* | | 910*/ /* | BU - Button up event. | 910*/ /* | BUM - Button up move event. -(1) If BD or BDM event 910*/ /* | BD - Button down event. occurs in a button(<>s), 910*/ /* | BDM - Button down move event. then set pButtonDown 910*/ /* | to point to the BUTTON 910*/ /* | structure. This is 910*/ /* | effectively a "pending" 910*/ /* ----(1) If BU or BUM event button event. If the 910*/ /* && if the event occurs up event occurs within 910*/ /* in the same button as the same <>s, then we've 910*/ /* a "pending" button got ourselves a valid 910*/ /* then we have a button button event. 910*/ /* event. 910*/ /* (2) If BD or BDM do not 910*/ /* occur within a button, 910*/ /* then set pButtonDown=NULL 910*/ /* and go back to the 910*/ /* caller with a 910*/ /* LEFTMOUSECLICK. 910*/ /* 910*/ /******************************************************************910*/ NextState = GetMouseState( Event ); /*910*/ if( (state == MOU_STATE_DOWN) && /*910*/ (NextState == MOU_STATE_UP) && /*910*/ (pButtonDown != NULL) && /*910*/ (pButtonDown == GetButtonPtr(pShell,Event)) /*910*/ ) /*910*/ { /*910*/ key = pButtonDown->Key; /*910*/ break; /*910*/ } /*910*/ /*910*/ if( (state == MOU_STATE_UP) && /*910*/ (NextState == MOU_STATE_DOWN) /*910*/ ) /*910*/ { /*910*/ pButtonDown = GetButtonPtr( pShell,Event); /*910*/ if( pButtonDown == NULL ) /*910*/ { /*910*/ key = LEFTMOUSECLICK; /*910*/ break; /*910*/ } /*910*/ } /*910*/ /*910*/ state = NextState; /*910*/ continue; /*910*/ } case TYPE_KBD_EVENT: { key = Event->Value; break; } } if( (FieldType & CLEAR1ST) && (FirstKeyEntry == TRUE) ) /*910*/ FirstKeyEntry = FALSE; /*910*/ switch( key ) { case F1: case ESC: case ENTER: case UP: case DOWN: case A_ENTER: case MOUSECLICK: /***********************************************************************/ /* - these keys are specific to the watchpoint dialog. 910*/ /***********************************************************************/ case TYNEXT: /* watchpoint type button. 910*/ case SPNEXT: /* watchpoint scope button. 910*/ case SZNEXT: /* watchpoint size button. 910*/ case STNEXT: /* watchpoint status button. 910*/ { /*********************************************************************/ /* All the above keys cannot be proccessed by getstring, so return */ /* the key to the caller. */ /*********************************************************************/ rc = RCBREAK; break; } case C_HOME: { /*********************************************************************/ /* Control-Home takes you to the start of the string. */ /*********************************************************************/ DisplayOffset = 0; CursorCol = FieldCol; rc = RCREDRAW; break; } case C_END: { /*********************************************************************/ /* Control-End takes you to the end of the string (to the last char */ /* the user has types in). */ /*********************************************************************/ BufLen = strlen( Buffer ); if( BufLen > FieldDisplayLength ) { DisplayOffset = BufLen - FieldDisplayLength; CursorCol = FieldCol + FieldDisplayLength - 1; } else { DisplayOffset = 0; CursorCol = FieldCol + BufLen; } rc = RCREDRAW; break; } case TAB: case S_TAB: { /*********************************************************************/ /* If the user has keyed in a tab and the field type is AUTOEXIT, */ /* return to the caller. */ /*********************************************************************/ if( FieldType & AUTOEXIT ) rc = RCBREAK; else { keybeep(); rc = 0; } break; } case LEFT: { /*********************************************************************/ /* The user has pressed the left arrow key. */ /* - If the cursor is not in the starting column move the cursor */ /* one column to the left. */ /*********************************************************************/ if( CursorCol > FieldCol ) { CursorCol--; rc = 0; } else { /*******************************************************************/ /* If the cursor is in the starting column, a non zero value in the*/ /* display offset would indicate we have some characters to the */ /* left to be displayed (see diagram above). If you have enough */ /* characters to scroll to LeftScrollOffset amount, do so. If not */ /* scroll to the start of the string. */ /*******************************************************************/ if( DisplayOffset ) { if( (int)(DisplayOffset - LeftScrollOffset) >= 0 ) { DisplayOffset -= LeftScrollOffset; CursorCol += (LeftScrollOffset - 1); } else { CursorCol += DisplayOffset; DisplayOffset = 0; } rc = RCREDRAW; } else { if( FieldType & AUTOEXIT ) rc = RCBREAK; else { keybeep(); rc = 0; } } } break; } case RIGHT: { /*********************************************************************/ /* The user has pressed the right arrow key. */ /* - If the cursor is not in the ending column of display and not */ /* end of the string, move the cursor one column to the right. */ /*********************************************************************/ BufLen = strlen( Buffer ); if( CursorCol < ( FieldCol + FieldDisplayLength - 1 ) ) { if( (DisplayOffset + (CursorCol - FieldCol)) < BufLen ) { CursorCol++; rc = 0; } else { keybeep(); rc = 0; } } else { /*******************************************************************/ /* If the cursor is at the ending column of display, check to see */ /* if we are within the buffer length. If we have enough space to */ /* scroll by RightScrollOffset amount do so, if not scroll till the*/ /* end of the string. */ /*******************************************************************/ if( DisplayOffset + FieldDisplayLength < BufLen ) { DisplayOffset += (FieldDisplayLength - RightScrollOffset); if( (DisplayOffset + (CursorCol - FieldCol)) > BufLen ) CursorCol = FieldCol + (BufLen - DisplayOffset); else CursorCol = FieldCol + RightScrollOffset; rc = RCREDRAW; } else { /*****************************************************************/ /* If we reached the ending column and the end of the buffer, if */ /* the field type is AUTOEXIT return to the caller. */ /*****************************************************************/ if( FieldType & AUTOEXIT ) rc = RCBREAK; else { keybeep(); rc = 0; } } } break; } case HOME: { /*********************************************************************/ /* Home takes to the starting column of the string. */ /*********************************************************************/ CursorCol = FieldCol; break; } case END: { /*********************************************************************/ /* End takes you to the ending column of the string. If the string */ /* is not long enough till the ending column of the display, End */ /* takes you to the end of the string. */ /*********************************************************************/ CursorCol = FieldCol + FieldDisplayLength - 1; scratch = DisplayOffset + ( CursorCol - FieldCol ); BufLen = strlen( Buffer ); if( scratch > BufLen ) CursorCol = FieldCol + (BufLen - DisplayOffset); break; } case INS: { /*********************************************************************/ /* Insert key is pressed. This toggles the InsertMode flag. If the */ /* current length of the string is less than the buffer length, */ /* InsertMode could be allowed. Set the cusror type accordingly. */ /*********************************************************************/ if( IsInsertMode ) { IsInsertMode = 0; VioSetCurType( &NormalCursor, 0 ); } else { if( length != strlen( Buffer ) ) { IsInsertMode = 1 - IsInsertMode; IsInsertMode ? VioSetCurType( &InsertCursor, 0 ) : VioSetCurType( &NormalCursor, 0 ); } else /* Display proper error message... */ keybeep(); } break; } case DEL: { /*********************************************************************/ /* Delete the current character. The rest of the string is shifted */ /* left. */ /*********************************************************************/ scratch = DisplayOffset + ( CursorCol - FieldCol ); ( scratch < strlen( Buffer ) ) ? ShiftLeft( scratch ) : keybeep(); rc = RCREDRAW; break; } case BACKSPACE: { /*********************************************************************/ /* The previous character to the cursor is deleted. By default the */ /* string is shifted left by one character. But if the cursor is on */ /* the starting column then the string is shifted by LeftScrollOffset*/ /* amount. */ /*********************************************************************/ scratch = DisplayOffset + (CursorCol - FieldCol); if( scratch ) { ShiftLeft( scratch - 1 ); CursorCol--; if( CursorCol < FieldCol ) { if( (int)(DisplayOffset - LeftScrollOffset) >= 0 ) { DisplayOffset -= LeftScrollOffset; CursorCol += LeftScrollOffset; } else { CursorCol += (DisplayOffset + 1); DisplayOffset = 0; } } } else keybeep(); rc = RCREDRAW; break; } default: { /*********************************************************************/ /* Any other character key is pressed. Verify the validity of the */ /* character depending on the type of the string (HEX/BIN). */ /*********************************************************************/ key &= 0xFF; if( key != 0x15 ) if( (key < 0x20) || (key > 0x7E) ) { rc = RCBREAK; break; } if( FieldType & HEXONLY ) { if( (key < '0') || (key > '9') ) { key &= 0xDF; if( (key < 'A') || (key > 'F') ) { keybeep(); rc = 0; break; } } } if( FieldType & BINONLY ) { if( (key != '0') && (key != '1') ) { keybeep(); rc = 0; break; } } if( FieldType & CLEAR1ST ) /*910*/ { /*910*/ memset(Buffer,'\0',strlen(Buffer) ); /*910*/ *cursor = 0; /*910*/ CursorCol = (*cursor > displen)?FieldCol : FieldCol + *cursor; /*910*/ } /*910*/ /*********************************************************************/ /* Scratch gives you the exact number of characters so far typed in */ /* by the user. Accept the last character only if scratch is less */ /* than the total length of the string. */ /*********************************************************************/ scratch = DisplayOffset + ( CursorCol - FieldCol ); if( scratch < length ) { if( IsInsertMode ) { if( (strlen( Buffer ) + 1) > length ) { keybeep(); rc = 0; break; /* reject */ } else ShiftRight( scratch ); } Buffer[scratch] = ( uchar )key; /*******************************************************************/ /* Adjust the cursor position accordingly so that it stays ahead */ /* of the last character. */ /*******************************************************************/ if( CursorCol >= (FieldCol + FieldDisplayLength) ) { DisplayOffset += (FieldDisplayLength - RightScrollOffset - 1); CursorCol = FieldCol + RightScrollOffset + 2; } else CursorCol++; /*******************************************************************/ /* It the type of the field is AUTOEXIT return to the caller once */ /* the buffer is full. */ /*******************************************************************/ BufLen = strlen( Buffer ); if( (BufLen == length) && (FieldType & AUTOEXIT) && ((CursorCol - FieldCol) == FieldDisplayLength) ) rc = RCREDRAW + RCBREAK + RCDATAXT; else rc = RCREDRAW; break; } else { keybeep(); rc = 0; break; } } } /*************************************************************************/ /* - Turn off the clear field flag after any event. */ /*************************************************************************/ FieldType &= ~CLEAR1ST; /*910*/ if( rc & RCREDRAW ) { DisplayField( DisplayOffset ); VioShowBuf( (ushort)voff, (ushort)( 2 * FieldDisplayLength ), 0 ); } if( rc & RCBREAK ) break; } /* end of for loop to handle keystrks*/ VioSetCurType( &HiddenCursor, 0 ); /*************************************************************************/ /* - Copy the local buffer to the caller supplied buffer. */ /* - Free the local buffer. */ /* - Reset the keyboard buffer flush flag. */ /*************************************************************************/ for( n = 0; n < strlen( Buffer ); n++ ) *pInbuf++ = Buffer[n]; *pInbuf = 0; *cursor = CursorCol; Tfree( Buffer ); ResetFlushBufferFlag(); /*820*/ return( (rc & RCDATAXT) ? DATAKEY : key ); }
void tentacle_update(int *buf, int *back, int W, int H, short data[2][512], float rapport, int drawit) { int tmp; int tmp2; static int colors[] = { (0x18<<(ROUGE*8))|(0x4c<<(VERT*8))|(0x2f<<(BLEU*8)), (0x48<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x6f<<(BLEU*8)), (0x58<<(ROUGE*8))|(0x3c<<(VERT*8))|(0x0f<<(BLEU*8))}; static int col = (0x28<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x5f<<(BLEU*8)); static int dstcol = 0; static float lig = 1.15f; static float ligs = 0.1f; int color; int colorlow; float dist,dist2,rotangle; if ((!drawit) && (ligs>0.0f)) ligs = -ligs; lig += ligs; if (lig > 1.01f) { if ((lig>10.0f) | (lig<1.1f)) ligs = -ligs; if ((lig<6.3f)&&(iRAND(30)==0)) dstcol=iRAND(3); col = evolutecolor(col,colors[dstcol],0xff,0x01); col = evolutecolor(col,colors[dstcol],0xff00,0x0100); col = evolutecolor(col,colors[dstcol],0xff0000,0x010000); col = evolutecolor(col,colors[dstcol],0xff000000,0x01000000); color = col; colorlow = col; lightencolor(&color,lig * 2.0f + 2.0f); lightencolor(&colorlow,(lig/3.0f)+0.67f); rapport = 1.0f + 2.0f * (rapport - 1.0f); rapport *= 1.2f; if (rapport > 1.12f) rapport = 1.12f; pretty_move (cycle,&dist,&dist2,&rotangle); for (tmp=0;tmp<nbgrid;tmp++) { for (tmp2=0;tmp2<definitionx;tmp2++) { float val = (float)(ShiftRight(data[0][iRAND(511)],10)) * rapport; vals[tmp2] = val; } grid3d_update (grille[tmp],rotangle, vals, dist2); } cycle+=0.01f; for (tmp=0;tmp<nbgrid;tmp++) grid3d_draw (grille[tmp],color,colorlow,dist,buf,back,W,H); } else { lig = 1.05f; if (ligs < 0.0f) ligs = -ligs; pretty_move (cycle,&dist,&dist2,&rotangle); cycle+=0.1f; if (cycle > 1000) cycle = 0; } }