void SaveWave(void) { Update[SAVE_WAVE_CURVE] = 0; if (SD_Card_ON()) { if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[SAVE_WAVE_CURVE]); if (Open_File("FILE",FileNum,"DAT") == 0) { F_Buff[0] = 0; F_Buff[1] = 0; memcpy(F_Buff + 2, View_Buffer, 300); if (Write_File() == 0) { if (Item_Index[SAVE_WAVE_CURVE] < 255) Item_Index[SAVE_WAVE_CURVE]++; Update[SAVE_WAVE_CURVE] = 1; } else DisplayField(InfoF, WHITE, SD_Msgs[WriteErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); }
void LoadConfig(void) { if (Item_Index[LOAD_PROFILE]) { Update[LOAD_PROFILE] = 0; if (SD_Card_ON()) { if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[LOAD_PROFILE]); if (Open_File("FILE",FileNum,"CFG") == 0) { if (Read_File() == 0) RestoreConfig(); else DisplayField(InfoF, WHITE, SD_Msgs[ReadErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); } else { Read_Parameter(); RestoreConfig(); } }
void LoadWave(void) { Update[LOAD_WAVE_CURVE] = 0; if (SD_Card_ON()) { Hide_Index[REF] = 1; // hide reference waveform Erase_Reference(); if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[LOAD_WAVE_CURVE]); if (Open_File("FILE",FileNum,"DAT") == 0) { if (Read_File() == 0) { memcpy(Ref_Buffer, F_Buff + 2, 300); Hide_Index[REF] = 0; // show new reference waveform Draw_Reference(); Update[LOAD_WAVE_CURVE] = 1; } else DisplayField(InfoF, WHITE, SD_Msgs[ReadErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); }
void RegEdit::OnSocItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { Q_UNUSED(previous); if(current == 0) return; if(current->type() == SocTreeSocType) { SocTreeItem *item = dynamic_cast< SocTreeItem * >(current); DisplaySoc(item->GetRef()); } else if(current->type() == SocTreeDevType) { DevTreeItem *item = dynamic_cast< DevTreeItem * >(current); DisplayDev(item->GetRef()); } else if(current->type() == SocTreeRegType) { RegTreeItem *item = dynamic_cast< RegTreeItem * >(current); DisplayReg(item->GetRef()); } else if(current->type() == SocTreeFieldType) { FieldTreeItem *item = dynamic_cast< FieldTreeItem * >(current); DisplayField(item->GetRef()); } }
void SelectSub(unsigned char pi) { unsigned char t; short y; if ((pi == 255) || (pi < Popup.Sub1)) pi = Popup.Sub2; else if (pi > Popup.Sub2) pi = Popup.Sub1; // remove selection y = Popup.y + Popup.height - 4 - 2 - 14 - 18 * (Popup.Sub - Popup.Sub1); Display_Str(Popup.x + 4, y, WHITE, PRN, Sub[Popup.Sub].Cmd); t = strlen((char const *)Sub[Popup.Sub].Cmd); Fill_Rectangle(Popup.x + 4 + t * 8, y, Popup.width - 8 - t * 8, 14, FRM_COLOR); // add selection Popup.Sub = pi; y = Popup.y + Popup.height - 4 - 2 - 14 - 18 * (Popup.Sub - Popup.Sub1); Display_Str(Popup.x + 4, y, WHITE, INV, Sub[Popup.Sub].Cmd); t = strlen((char const *)Sub[Popup.Sub].Cmd); Fill_Rectangle(Popup.x + 4 + t * 8, y, Popup.width - 8 - t * 8, 14, WHITE); if (Popup.Sub1 == MeFreq) Item_Index[MEASURE_KIND] = Popup.Sub - Popup.Sub1; Menu[CurrentMenu].Sub = Popup.Sub; DisplayField(InfoF, WHITE, Sub[Menu[CurrentMenu].Sub].Cmd); Item_Index[CI] = Sub[Popup.Sub].ci; }
extern void BigGoto( int level ) /**********************************/ { name *reg; if( level != 0 ) { reg = AllocRegName( DisplayReg() ); AddIns( MakeMove( DisplayField( level ), reg, reg->n.name_class ) ); } }
int TestFieldDG(void){ int test = (1==1); Field f; f.model.m=1; // only one conservative variable f.model.NumFlux=TransportNumFlux; f.model.BoundaryFlux=TestTransportBoundaryFlux; f.model.InitData=TestTransportInitData; f.model.ImposedData=TestTransportImposedData; f.varindex=GenericVarindex; f.interp.interp_param[0]=1; // _M f.interp.interp_param[1]=2; // x direction degree f.interp.interp_param[2]=2; // y direction degree f.interp.interp_param[3]=2; // z direction degree f.interp.interp_param[4]=1; // x direction refinement f.interp.interp_param[5]=1; // y direction refinement f.interp.interp_param[6]=1; // z direction refinement ReadMacroMesh(&(f.macromesh),"test/testcube.msh"); BuildConnectivity(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); //AffineMapMacroMesh(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); InitField(&f); CheckMacroMesh(&(f.macromesh),f.interp.interp_param+1); dtField(&f); DisplayField(&f); int yes_compare = 1; int no_compare = 0; PlotField(0,no_compare,&f,"visu.msh"); PlotField(0,yes_compare,&f,"error.msh"); // test the time derivative with the exact solution for(int i=0;i<f.model.m * f.macromesh.nbelems * NPG(f.interp.interp_param+1);i++){ test = test && fabs(4*f.wn[i]-pow(f.dtwn[i],2))<1e-2; assert(test); } return test; };
void SelectMenu(unsigned char mi) { if (mi == 255) mi = N_MENU - 1; else if (mi >= N_MENU) mi = 0; Display_Str(MAX_X + 3, MAX_Y - 17 - CurrentMenu * 20, YEL, PRN, Menu[CurrentMenu].Cmd); Display_Str(MAX_X + 3, MAX_Y - 17 - mi * 20, WHITE, INV, Menu[mi].Cmd); CurrentMenu = mi; DisplayField(InfoF, WHITE, Sub[Menu[CurrentMenu].Sub].Cmd); Item_Index[CI] = Sub[Menu[CurrentMenu].Sub].ci; }
extern name *MakeDisplay( name *op, int level ) /*************************************************/ { name *temp; name *reg; reg = AllocRegName( DisplayReg() ); temp = AllocTemp( U2 ); AddIns( MakeMove( DisplayField( level ), temp, reg->n.name_class ) ); op = AllocIndex( temp, NULL, op->t.location, op->n.name_class ); return( op ); }
void SaveConfig(void) { Update[SAVE_PROFILE] = 0; if (Item_Index[SAVE_PROFILE]) { if (SD_Card_ON()) { if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[SAVE_PROFILE]); if (Open_File("FILE",FileNum,"CFG") == 0) { PutConfig(); if (Write_File() != 0) DisplayField(InfoF, WHITE, SD_Msgs[WriteErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); } else { PutConfig(); if (Write_Parameter() == FLASH_COMPLETE) DisplayField(InfoF, WHITE, SD_Msgs[SaveOk]); else DisplayField(InfoF, WHITE, SD_Msgs[Failed]); } }
void SaveWaveImage(void) { Update[SAVE_WAVE_IMAGE] = 0; if (SD_Card_ON()) { if (FAT_Info() == 0) { Char_to_Str(FileNum, Item_Index[SAVE_WAVE_IMAGE]); if (Open_File("IMAGE",FileNum,"BMP") == 0) { if (Writ_BMP_File() == 0) { if (Item_Index[SAVE_WAVE_IMAGE] < 255) Item_Index[SAVE_WAVE_IMAGE]++; Update[SAVE_WAVE_IMAGE] = 1; } else DisplayField(InfoF, WHITE, SD_Msgs[WriteErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoFile]); } else DisplayField(InfoF, WHITE, SD_Msgs[SDErr]); } else DisplayField(InfoF, WHITE, SD_Msgs[NoCard]); }
/******************************************************************************* Function Name : Update_Item Description : update the items based on Update[x] *******************************************************************************/ void Update_Item(void) { if (Update[SYNC_MODE]) { Update[SYNC_MODE] = 0; DisplayField(SyncModeF, (Item_Index[RUNNING_STATUS] == RUN)?GRN:RED, MODE_Unit[Item_Index[SYNC_MODE]]); } if (Update[Y_SENSITIVITY]) { Update[Y_SENSITIVITY] = 0; DisplayField(VoltageDivF, WHITE, Item_V[Item_Index[Y_SENSITIVITY]]); Set_Range(Item_Index[Y_SENSITIVITY]); //voltage range Set_Y_Pos(Item_Index[Y_SENSITIVITY], Item_Index[V0]); } if (Update[X_SENSITIVITY]) { Update[X_SENSITIVITY] = 0; DisplayField(TimeDivF, YEL, Item_T[Item_Index[X_SENSITIVITY]]); Set_Base(Item_Index[X_SENSITIVITY]); } if (Update[GND_POSITION])// update Y.Position { Update[GND_POSITION] = 0; Set_Y_Pos(Item_Index[Y_SENSITIVITY], Item_Index[V0]); } if (Update[MEASURE_KIND])//measure kind { unsigned char UpdateKind = 1; Update[MEASURE_KIND] = 0; switch (Item_Index[4]) { case 0: // frequency if (MeFr) { Int32String(&Num, Frequency, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, F_Unit[Num.decPos]); UpdateKind = 0; } break; case 1: // duty if (MeFr) { Int32String(&Num, Duty, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, "%"); UpdateKind = 0; } break; case 2: // Vrms if (MeFr) { Int32String(&Num, Vrms, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]); UpdateKind = 0; } break; case 3: // Vavg if (MeFr) { Int32String_sign(&Num, Vavg, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]); UpdateKind = 0; } break; case 4: // Vpp if (MeDC) { Int32String(&Num, Vpp, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]); UpdateKind = 0; } break; case 5: // DCV if (MeDC) { Int32String_sign(&Num, Vdc, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]); UpdateKind = 0; } break; case 6: // Vmin if (MeDC) { Int32String_sign(&Num, Vmin, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]); UpdateKind = 0; } break; case 7: // Vmax if (MeDC) { Int32String_sign(&Num, Vmax, 3); DisplayFieldEx(MeasureF, WHITE, 0, (unsigned const char *)Num.str, V_Unit[Num.decPos]); UpdateKind = 0; } break; } if (UpdateKind) DisplayField(MeasureF, WHITE, Sub[MeFreq + Item_Index[MEASURE_KIND]].Cmd); if (Popup.Active && (Popup.Sub1 == MeFreq)) { unsigned char Sub = Item_Index[MEASURE_KIND] + Popup.Sub1; if (Popup.Sub != Sub) SelectSub(Sub); else RefreshMeasure(); } if (Item_Index[CI] == MEASURE_KIND) DisplayField(InfoF, WHITE, Sub[MeFreq + Item_Index[MEASURE_KIND]].Cmd); } if (Update[POWER_INFO]) { Update[POWER_INFO] = 0; DisplayField(BatteryInfoF, Battery_Color[Item_Index[POWER_INFO]], Battery_Status[Item_Index[POWER_INFO]]); } if (Update[TRIG_LEVEL]) { Update[TRIG_LEVEL] = 0; Int32String_sign(&Num, (Item_Index[VT] - Item_Index[V0]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3); DisplayFieldEx(TrigLevelF, YEL, "Tr", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } if (Update[TRIG_SENSITIVITY]) { Update[TRIG_SENSITIVITY] = 0; if (Item_Index[CI] == TRIG_SENSITIVITY) { Int32String(&Num, Item_Index[TRIG_SENSITIVITY] * V_Scale[Item_Index[Y_SENSITIVITY]], 3); DisplayFieldEx(InfoF, WHITE, "[S", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } } if (Update[TRIG_SLOPE]) { Update[TRIG_SLOPE] = 0; DisplayField(TrigKindF, YEL, (unsigned const char *)((Item_Index[TRIG_SLOPE] == RISING)?"^":"_")); } if (Update[INPUT_ATTENUATOR]) { Update[INPUT_ATTENUATOR] = 0; if (Item_Index[CI] == INPUT_ATTENUATOR) DisplayField(InfoF, WHITE, (unsigned const char *)((Item_Index[INPUT_ATTENUATOR] == 0)?"Att. x1": "Att. x10")); } if (Update[SAVE_WAVE_IMAGE]) { Update[SAVE_WAVE_IMAGE] = 0; if (Item_Index[CI] == SAVE_WAVE_IMAGE) { Char_to_Str(FileNum, Item_Index[SAVE_WAVE_IMAGE]); DisplayFieldEx(InfoF, WHITE, "S", FileNum, ".BMP"); } } if (Update[SAVE_WAVE_CURVE]) { Update[SAVE_WAVE_CURVE] = 0; if (Item_Index[CI] == SAVE_WAVE_CURVE) { Char_to_Str(FileNum, Item_Index[SAVE_WAVE_CURVE]); DisplayFieldEx(InfoF, WHITE, "S", FileNum, ".DAT"); } } if (Update[LOAD_WAVE_CURVE]) { Update[LOAD_WAVE_CURVE] = 0; if (Item_Index[CI] == LOAD_WAVE_CURVE) { Char_to_Str(FileNum, Item_Index[LOAD_WAVE_CURVE]); DisplayFieldEx(InfoF, WHITE, "L", FileNum, ".DAT"); } } if (Update[SHOW_WAVE_CURVE]) { Update[SHOW_WAVE_CURVE] = 0; if (Item_Index[CI] == SHOW_WAVE_CURVE) { DisplayField(InfoF, WHITE, (unsigned const char *)(Hide_Index[REF]?"Hide Ref": "Show Ref")); } } if (Update[SAVE_PROFILE]) { Update[SAVE_PROFILE] = 0; if (Item_Index[CI] == SAVE_PROFILE) { if (Item_Index[SAVE_PROFILE]) { Char_to_Str(FileNum, Item_Index[SAVE_PROFILE]); DisplayFieldEx(InfoF, WHITE, "S", FileNum, ".CFG"); } else DisplayFieldEx(InfoF, WHITE, "S", "Flash", ""); } } if (Update[LOAD_PROFILE]) { Update[LOAD_PROFILE] = 0; if (Item_Index[CI] == LOAD_PROFILE) { if (Item_Index[LOAD_PROFILE]) { Char_to_Str(FileNum, Item_Index[LOAD_PROFILE]); DisplayFieldEx(InfoF, WHITE, "L", FileNum, ".CFG"); } else DisplayFieldEx(InfoF, WHITE, "L", "Flash", ""); } } if (Update[OUTPUT_FREQUENCY]) { Update[OUTPUT_FREQUENCY] = 0; TIM4_PSC = Fout_PSC[Item_Index[OUTPUT_FREQUENCY]]; TIM4_ARR = Fout_ARR[Item_Index[OUTPUT_FREQUENCY]]; TIM4_CCR1 = (Fout_ARR[Item_Index[OUTPUT_FREQUENCY]] + 1) / 2; if (Item_Index[CI] == OUTPUT_FREQUENCY) DisplayFieldEx(InfoF, WHITE, "Fr.", Item_F[Item_Index[OUTPUT_FREQUENCY]], ""); } if (Update[T2_CURSOR]) { Update[T2_CURSOR] = 0; if (Item_Index[CI] == T2_CURSOR) { unsigned char i = Item_Index[X_SENSITIVITY] / 9; unsigned char j = Item_Index[X_SENSITIVITY] % 9; Int32String_sign(&Num, (Item_Index[T2] - 150 + BUFFER_SIZE - Item_Index[TP]) * T_Scale[j], 3); DisplayFieldEx(InfoF, WHITE, "T2", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); //Draw_Dot_Ti(Item_Index[T1], ADD, LN2_COLOR); } } if (Update[T1_CURSOR]) { Update[T1_CURSOR] = 0; if (Item_Index[CI] == T1_CURSOR) { unsigned char i = Item_Index[X_SENSITIVITY] / 9; unsigned char j = Item_Index[X_SENSITIVITY] % 9; Int32String_sign(&Num, (Item_Index[T1] - 150 + BUFFER_SIZE - Item_Index[TP]) * T_Scale[j], 3); DisplayFieldEx(InfoF, WHITE, "T1", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); //Draw_Dot_Ti(Item_Index[T1], ADD, LN2_COLOR); } } if (Update[TRIG_POS]) { Update[TRIG_POS] = 0; if (Item_Index[CI] == TRIG_POS) { unsigned char i = Item_Index[X_SENSITIVITY] / 9; unsigned char j = Item_Index[X_SENSITIVITY] % 9; Int32String_sign(&Num, (Item_Index[TP] - BUFFER_SIZE) * T_Scale[j], 3); DisplayFieldEx(InfoF, WHITE, "TP", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); } } if (Update[DELTA_T]) { unsigned char i = Item_Index[X_SENSITIVITY] / 9; unsigned char j = Item_Index[X_SENSITIVITY] % 9; Update[DELTA_T] = 0; Int32String(&Num, (Item_Index[T2] - Item_Index[T1]) * T_Scale[j], 3); DisplayFieldEx(DeltaTimeF, YEL, "[T", (unsigned const char *)Num.str, T_Unit[Num.decPos+i]); } if (Update[CALIBRATE_OFFSET]) { Update[CALIBRATE_OFFSET] = 0; if (Item_Index[CI] == CALIBRATE_OFFSET) { Int32String_sign(&Num, V_Scale[Item_Index[Y_SENSITIVITY]] * (Item_Index[CALIBRATE_OFFSET] - 100), 3); DisplayFieldEx(InfoF, WHITE, "Of", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } } if (Update[CALIBRATE_RANGE]) { Update[CALIBRATE_RANGE] = 0; if (Item_Index[CI] == CALIBRATE_RANGE) { PercentString(&Num, Item_Index[CALIBRATE_RANGE] - 100); DisplayFieldEx(InfoF, WHITE, "Ra", (unsigned const char *)Num.str, "%"); } } if (Update[V2_CURSOR]) { Update[V2_CURSOR] = 0; if (Item_Index[CI] == V2_CURSOR) { // V2 voltage Int32String_sign(&Num, (Item_Index[V2] - Item_Index[V0]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3); DisplayFieldEx(InfoF, WHITE, "V2", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } Int32String(&Num, (Item_Index[V1] - Item_Index[V2]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3); DisplayFieldEx(DeltaVoltageF, WHITE, "[V", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } if (Update[V1_CURSOR]) { Update[V1_CURSOR] = 0; if (Item_Index[CI] == V1_CURSOR) { // V1 voltage Int32String_sign(&Num, (Item_Index[V1] - Item_Index[V0]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3); DisplayFieldEx(InfoF, WHITE, "V1", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } Int32String(&Num, (Item_Index[V1] - Item_Index[V2]) * V_Scale[Item_Index[Y_SENSITIVITY]], 3); DisplayFieldEx(DeltaVoltageF, WHITE, "[V", (unsigned const char *)Num.str, V_Unit[Num.decPos]); } if (Update[CURSORS]) { Update[CURSORS] = 0; Tp = MIN_X + 150 + Item_Index[TP] - BUFFER_SIZE; if (Tp >= MAX_X) Tp = MAX_X; else if (Tp <= MIN_X) Tp = MIN_X; else { Draw_Ti_Line(Tp, Hide_Index[TP]?ERASE:ADD, CH2_COLOR); Draw_Ti_Mark(Tp, ADD, CH2_COLOR); } if (Item_Index[CI] == TRIG_POS) Draw_Trig_Pos(); else Erase_Trig_Pos(); // draw Gnd position Draw_Vi_Mark(Item_Index[V0], ADD, WAV_COLOR); // draw T cursors Draw_Ti_Line(Item_Index[T1], Hide_Index[T1]?ERASE:ADD, LN2_COLOR); Draw_Ti_Line(Item_Index[T2], Hide_Index[T2]?ERASE:ADD, LN2_COLOR); Draw_Ti_Mark(Item_Index[T1], ADD, LN2_COLOR); Draw_Ti_Mark(Item_Index[T2], ADD, LN2_COLOR); // draw V cursors Draw_Vi_Line(Item_Index[V1], Hide_Index[V1]?ERASE:ADD, LN2_COLOR); Draw_Vi_Line(Item_Index[V2], Hide_Index[V2]?ERASE:ADD, LN2_COLOR); Draw_Vi_Mark(Item_Index[V1], ADD, LN2_COLOR); Draw_Vi_Mark(Item_Index[V2], ADD, LN2_COLOR); // draw trigger level/sensitivity if (!Hide_Index[VT]) { Draw_Vt_Line(Item_Index[VT], ADD, LN1_COLOR); Draw_Vi_Mark(Item_Index[VT], ADD, LN1_COLOR); } else if (!Hide_Index[VS]) { Draw_Vt_Line(Item_Index[VT] + Item_Index[VS], ADD, LN1_COLOR); Draw_Vt_Line(Item_Index[VT] - Item_Index[VS], ADD, LN1_COLOR); Draw_Vi_Mark(Item_Index[VT] + Item_Index[VS], ADD, LN1_COLOR); Draw_Vi_Mark(Item_Index[VT] - Item_Index[VS], ADD, LN1_COLOR); } } }
void Life(void) { int Running=0; int ViewStep=10; unsigned key; OwDisplay(Root); OwDisplay(StatusWin); Center(); DisplayField(); do { MoveCursor((unsigned)(PosX-ShiftX),(unsigned)(PosY-ShiftY)); CursorType(C_NORMAL); if(Running) { if(KeyPressed()) key=ReadKey(); else key=' '; } else key=ReadKey(); switch(key) { case('!'): SuspendInterface(); #ifndef MSDOS /* system("exec $SHELL");*/ #else system(getenv("COMSPEC")); #endif ResumeInterface(); continue; case(K_F2): SaveField(); continue; case('c'): case('C'): /* clear field */ Running=0; FreeField(); Center(); break; case(' '): Step(); break; case('\t'): ChangeCell(PosX,PosY,REV); break; case(M_BUTTON): switch(I_LastButton) { case(LEFT_BUTTON): ChangeCell(ShiftX+I_MouseX,ShiftY+I_MouseY,REV); break; case(RIGHT_BUTTON): ShiftX+=I_MouseX-(int)(I_ScreenWidth>>1); ShiftY+=I_MouseY-(int)(I_ScreenHeight>>1); break; default: continue; } break; case(M_MOVE): if(I_Buttons&LEFT_BUTTON) ChangeCell(ShiftX+I_MouseX,ShiftY+I_MouseY,REV); else continue; break; case('4'): ShiftX-=ViewStep; break; case(K_LEFT): PosX--; if(PosX<ShiftX) ShiftX-=ViewStep; else { StatusLine(); continue; } break; case('8'): ShiftY-=ViewStep; break; case(K_UP): PosY--; if(PosY<ShiftY) ShiftY-=ViewStep; else { StatusLine(); continue; } break; case('6'): ShiftX+=ViewStep; break; case(K_RIGHT): PosX++; if(PosX>=ShiftX+(int)I_ScreenWidth) ShiftX+=ViewStep; else { StatusLine(); continue; } break; case('2'): ShiftY+=ViewStep; break; case(K_DOWN): PosY++; if(PosY>=ShiftY+(int)I_ScreenHeight) ShiftY+=ViewStep; else { StatusLine(); continue; } break; case('5'): Center(); break; case('3'): ShiftY+=ViewStep; ShiftX+=ViewStep; break; case('1'): ShiftY+=ViewStep; ShiftX-=ViewStep; break; case('7'): ShiftY-=ViewStep; ShiftX-=ViewStep; break; case('9'): ShiftY-=ViewStep; ShiftX+=ViewStep; break; case('\r'): Running=!Running; break; case('q'): case('Q'): case(27): return; default: continue; } if(PosY<ShiftY) PosY+=(ShiftY-PosY+ViewStep-1)/ViewStep*ViewStep; if(PosX<ShiftX) PosX+=(ShiftX-PosX+ViewStep-1)/ViewStep*ViewStep; if(PosY>=ShiftY+(int)I_ScreenHeight) PosY-=(PosY-ShiftY-(int)I_ScreenHeight+ViewStep)/ViewStep*ViewStep; if(PosX>=ShiftX+(int)I_ScreenWidth) PosX-=(PosX-ShiftX-(int)I_ScreenWidth+ViewStep)/ViewStep*ViewStep;; DisplayField(); } while(1); }
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 ); }