📄 gui.c
字号:
{ ClearHelpMenus(); popUpWidget(blankHelpMenu);}void configBitsHelpCB(SDL_Event *event){ ClearHelpMenus(); popUpWidget(configBitsHelpMenu);}void IdHelpCB(SDL_Event *event){ ClearHelpMenus(); popUpWidget(IdHelpMenu);}void DisasmHelpCB(SDL_Event *event){ ClearHelpMenus(); popUpWidget(DisasmHelpMenu);}void DisplayModeHelpCB(SDL_Event *event){ ClearHelpMenus(); popUpWidget(DisplayHelpMenu);}void enableButtonCB(SDL_Event *event){ char *cptr; popUpWidget(connectWin); updateScreen(); warpFWversion[0] = '\0'; if (issueCommand(PICP_COMMAND_GET_VERSION)) { if (getCommandResponse(PICP_COMMAND_GET_VERSION)) { strcpy(picFWversionString, commandResponse); strcat(picFWversionString, warpFWversion); cptr = commandResponse; while (*cptr && !isdigit(*cptr)) // skip to version number cptr++; picFWversion = atoi(cptr) << 16; while (*cptr && isdigit(*cptr)) cptr++; cptr++; picFWversion |= (atoi(cptr) << 8); while (*cptr && isdigit(*cptr)) cptr++; cptr++; picFWversion |= atoi(cptr); if (picFWversion < MINFWVERSION) oldFirmware = TRUE; else oldFirmware = FALSE; } } else connectFailAlert(); pushDownWidget(connectWin);}//////////////////////////////////////////////// Put ascii hex data into binary array//////////////////////////////////////////////void getcode(char *from, byte *loc){ byte c, i; c = *from++ - 0x30; c = (c > 10) ? c - 7 : c; i = c << 4; c = *from++ - 0x30; c = (c > 10) ? c - 7 : c; *loc = i | c;}// Read hex file into buffer array.// Return TRUE if successfully loaded.bool loadHexFile(char *fname){ int i; byte *buffer; FILE *fp; struct stat filestat; extendedAddress = 0; recordType = 0; if (programDisplayFlag) buffer = picProgramData; else buffer = picDataBuffer; fp = fopen(fname, "r"); if (fp) { recordCount = 0; if (programDisplayFlag) // clear old program/data before loading new file { for (i=0; i<PIC_PROGRAM_SIZE; i++) { if (i & 1) picProgramData[i] = dataWidthHi; else picProgramData[i] = dataWidthLo; } } else { for (i=0; i<MAX_EEPROM_DATA_SIZE; i++) picDataBuffer[i] = 0xff; } while (!feof(fp)) // until end of file... { *linebuffer = '\0'; // clear previous line fgets(linebuffer, 127, fp); // read one line recordCount++; if (!parseHexLine(linebuffer, buffer)) { fclose(fp); fp = NULL; break; } } if (fp) fclose(fp); if (programDisplayFlag) strcpy(programFileStr, fileStr); else strcpy(dataFileStr, fileStr); filelabel->text = (char *) &fileStr; saveButton->fg = black; saveAsButton->fg = black; if (programDisplayFlag) { picProgramPC = 0; makeSegmentList(); } else picDataPC = 0; disVSlider->offset = 0; disVSlider->position = 0; disVSlider->pc = 0; showProgram(); i = stat(fname, &filestat); file_mtime = filestat.st_mtime; return TRUE; } popUpWidget(fileErrorAlert); fileButtonActive = FALSE; return FALSE;}// Open and read hex file selected by the uservoid openButtonCB(SDL_Event *event, MENU *m){ int i; char *cptr; if (!selectedPicDevice) { sprintf(alertMessage, " No PIC device selected "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); fileButtonActive = FALSE; pushDownWidget(fileMenu); return; } if (!fileButtonActive || fileSelectionActive) return; if (event->type == SDL_MOUSEBUTTONDOWN) { outputWin->xoffset = 0; fileSelectionActive = TRUE; cptr = fileSelect(loadFileTypes, NULL); fileSelectionActive = FALSE; if (cptr == (char *) -1) appQuit = TRUE; else if (cptr) { strcpy(fileStr, cptr); cptr = strrchr(cptr, '.'); // get file extension strcpy(src, fileStr); // init filenames i = strlen(fileStr) - strlen(cptr); strcpy(fileExt, (char *) &src[i]); src[i] = '\0'; fileName[0] = '\0'; while (--i) { if (src[i] == '/') { i++; strcpy(fileName, (char *) &src[i]); break; } } loadHexFile(fileStr); } fileButtonActive = FALSE; pushDownWidget(fileMenu); }}char convertToAscii(byte code){ code &= 0x7f; if (code < ' ') return '.'; if (code > '~') return '.'; return code;}void portButtonCB(SDL_Event *event){ if (!portButtonActive) { portButtonActive = TRUE; popUpWidget(portMenu); } else { portButtonActive = FALSE; pushDownWidget(portMenu); }}void port0ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[0]); portButtonActive = FALSE; pushDownWidget(portMenu);}void port1ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[1]); portButtonActive = FALSE; pushDownWidget(portMenu);}void port2ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[2]); portButtonActive = FALSE; pushDownWidget(portMenu);}void port3ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[3]); portButtonActive = FALSE; pushDownWidget(portMenu);}void portUSB0ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[4]); portButtonActive = FALSE; pushDownWidget(portMenu);}void portUSB1ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[5]); portButtonActive = FALSE; pushDownWidget(portMenu);}void portUSB2ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[6]); portButtonActive = FALSE; pushDownWidget(portMenu);}void portUSB3ButtonCB(SDL_Event *event){ strcpy(serialPort, serialPortNames[7]); portButtonActive = FALSE; pushDownWidget(portMenu);}void closePortMenuCB(SDL_Event *event){ portButtonActive = FALSE; pushDownWidget(portMenu);}bool checkPicDevice(void){ if (!selectedPicDevice) { sprintf(alertMessage, " No PIC device selected "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); return FALSE; } if (!picFWversion) { waitForAlertResponse(connectAlert); return FALSE; } return TRUE;}void readPicProgram(void){ int i; if (!checkPicDevice()) return; setMemoryDisplay(TRUE); for (i=0; i<PIC_PROGRAM_SIZE; i++) // clear program space before reading from PS+ { if (i & 1) picProgramData[i] = dataWidthHi; else picProgramData[i] = dataWidthLo; } moveVMenu(readingWin, 280, 30); popUpWidget(readingWin); updateScreen(); if (issueCommand(PICP_COMMAND_READ_PGM)) { if (!getCommandResponse(PICP_COMMAND_READ_PGM)) { sprintf(alertMessage, " Read PIC program failed! "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } else { picProgramPC = 0; disVSlider->offset = 0; disVSlider->position = 0; disVSlider->pc = 0; saveAsButton->fg = black; makeSegmentList(); } } showProgram(); pushDownWidget(readingWin);}void verifyPicProgram(void){ int i; bool fail = FALSE; if (!checkPicDevice()) return; setMemoryDisplay(TRUE); for (i=0; i<PIC_PROGRAM_SIZE; i++) // clear program space before reading from PS+ { if (i & 1) picProgramTemp[i] = dataWidthHi; else picProgramTemp[i] = dataWidthLo; } moveVMenu(readingWin, 80, 30); popUpWidget(readingWin); updateScreen(); if (issueCommand(PICP_COMMAND_VERIFY_PGM)) { if (!getCommandResponse(PICP_COMMAND_VERIFY_PGM)) { sprintf(alertMessage, " Read PIC program failed! "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); fail = TRUE; } else { picProgramPC = 0; disVSlider->offset = 0; disVSlider->position = 0; disVSlider->pc = 0; saveAsButton->fg = black; } } else fail = TRUE; showProgram(); pushDownWidget(readingWin); if (fail) return; fail = FALSE; for (i=0; i<PIC_PROGRAM_SIZE; i++) // clear program space before reading from PS+ { if (picProgramData[i] != picProgramTemp[i]) { fail = TRUE; break; } } if (fail) { sprintf(alertMessage, " PIC program data does NOT match buffer!\n"); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } else { sprintf(noticeMessage, " Verify OK \n"); popUpWidget(verifyResultWin); }}void writePicProgram(void){ int i; time_t mtime; struct stat filestat; if (!checkPicDevice()) return; setMemoryDisplay(TRUE); if (file_mtime) // if file has been opened, { i = stat(fileStr, &filestat); // get current timestamp if (i > -1) // file exists { mtime = filestat.st_mtime; if (mtime > file_mtime) // file has been modified since reading { strcpy(alertMessage, " File has changed since it was opened. \n Reopen it? "); errorAlert->x = 4; errorAlert->w = 40 * FONT_WIDTH; i = waitForAlertResponse(errorAlert); if (i != ALERT_OK) { strcpy(alertMessage, " Write old program data anyway? \n "); i = waitForAlertResponse(errorAlert); if (i != ALERT_OK) return; } else loadHexFile(fileStr); } } } if (waitForAlertResponse(confirmAlert) != ALERT_OK) return; popUpWidget(writingWin); updateScreen(); saveFile(tempFileName); if (issueCommand(PICP_COMMAND_WRITE_PGM)) getCommandResponse(PICP_COMMAND_WRITE_PGM);// remove(tempFileName); showProgram(); pushDownWidget(writingWin);}// Copy a string not including any trailing newlinevoid stringcopy(char *dst, char *src){ while (*src && *src != '\n') *dst++ = *src++; *dst = '\0';}void readPicId(void){ char *cptr; if (!checkPicDevice()) return; moveVMenu(readingWin, 280, 30); popUpWidget(readingWin); updateScreen(); if (issueCommand(PICP_COMMAND_READ_ID)) { if (getCommandResponse(PICP_COMMAND_READ_ID)) { cptr = (char *) &commandResponse; while (*cptr && !isdigit(*cptr)) cptr++; stringcopy(IdText, cptr); } else { sprintf(alertMessage, " Read PIC ID failed!\n "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } else connectFailAlert(); pushDownWidget(readingWin);}// Case insensitive compare of strings not including any trailing newline.// Return TRUE only if they are equal.bool stringcompare(char *s1, char *s2){ bool match = TRUE; while (*s1 && *s1 != '\n' && *s2 && *s2 != '\n') { if (toupper(*s1) != toupper(*s2)) { match = FALSE; break; } s1++; s2++; } if (match) // check for end at both strings { if (*s1 || *s2) // not at end of one of them... { if (*s1 && *s1 != '\n') match = FALSE; if (*s2 && *s2 != '\n') match = FALSE; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -