📄 gui.c
字号:
return match;}void verifyPicId(void){ char *cptr; if (!checkPicDevice()) return; moveVMenu(readingWin, 80, 30); popUpWidget(readingWin); updateScreen(); if (issueCommand(PICP_COMMAND_VERIFY_ID)) { if (getCommandResponse(PICP_COMMAND_VERIFY_ID)) { cptr = (char *) &commandResponse; while (*cptr && !isdigit(*cptr)) cptr++; if (stringcompare(IdText, cptr)) { sprintf(noticeMessage, " Verify OK \n"); popUpWidget(verifyResultWin); } else { sprintf(alertMessage, " PIC ID data does NOT match!\n"); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } 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);}void writePicId(void){ if (!checkPicDevice()) return; if (waitForAlertResponse(confirmAlert) != ALERT_OK) return; popUpWidget(writingWin); updateScreen(); if (issueCommand(PICP_COMMAND_WRITE_ID)) { if (!getCommandResponse(PICP_COMMAND_WRITE_ID)) { sprintf(alertMessage, " Write PIC ID failed!\n "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } else connectFailAlert(); pushDownWidget(writingWin);}void readPicConfig(void){ char *cptr; if (!checkPicDevice()) return; moveVMenu(readingWin, 280, 30); popUpWidget(readingWin); updateScreen(); if (issueCommand(PICP_COMMAND_READ_CFG)) { if (getCommandResponse(PICP_COMMAND_READ_CFG)) { cptr = (char *) &commandResponse; while (*cptr && !isdigit(*cptr)) cptr++; stringcopy(configText, cptr); } else { sprintf(alertMessage, " Read PIC configuration bits failed!\n "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } else connectFailAlert(); pushDownWidget(readingWin);}void verifyPicConfig(void){ char *cptr; if (!checkPicDevice()) return; moveVMenu(readingWin, 80, 30); popUpWidget(readingWin); updateScreen(); if (issueCommand(PICP_COMMAND_VERIFY_CFG)) { if (getCommandResponse(PICP_COMMAND_VERIFY_CFG)) { cptr = (char *) &commandResponse; while (*cptr && !isdigit(*cptr)) cptr++; if (stringcompare(configText, cptr)) { sprintf(noticeMessage, " Verify OK \n"); popUpWidget(verifyResultWin); } else { sprintf(alertMessage, " PIC configuration data does NOT match!\n"); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } else { sprintf(alertMessage, " Read PIC configuration bits failed!\n "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } else connectFailAlert(); pushDownWidget(readingWin);}void writePicConfig(void){ if (!checkPicDevice()) return; if (waitForAlertResponse(confirmAlert) != ALERT_OK) return; popUpWidget(writingWin); updateScreen(); if (issueCommand(PICP_COMMAND_WRITE_CFG)) { if (!getCommandResponse(PICP_COMMAND_WRITE_CFG)) { sprintf(alertMessage, " Write configuration bits failed! \n "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } } else connectFailAlert(); pushDownWidget(writingWin);}void selectDeviceCB(SDL_Event *event){ char *device; device = deviceSelect(); if (device && device != (char *) -1) setSelectedDevice(device); else if (device == (char *) -1) appQuit = TRUE;}void setSelectedDevice(char *dname){ int i, len, size; bool deviceFound = FALSE; PIC_DEFINITION *device; char temp[16]; strcpy(deviceType, dname); i = 0; setMemoryDisplay(TRUE); while (deviceList[i]) { device = (PIC_DEFINITION *) deviceList[i]; i++; len = strlen(device->name); if (!strncmp(deviceType, device->name, len)) // found the desired pic type { selectedPicDevice = device; dataWidthHi = selectedPicDevice->def[PD_DATA_WIDTHH]; dataWidthLo = selectedPicDevice->def[PD_DATA_WIDTHL]; size = (int) ((selectedPicDevice->def[PD_PGM_SIZEH] & 0xff) << 8); size |= (int) (selectedPicDevice->def[PD_PGM_SIZEL] & 0xff); if (size & 0xff) size++; picProgramSize = size; disVSlider->range = size / 8 - DISPLAY_LINES; disVSlider->offset = 0; disVSlider->position = 0; disVSlider->pc = 0; picProgramPC = 0; picDataPC = 0; deviceFound = TRUE; picName = (char *) &device->name; showProgram(); len = (int) GetConfigSize(device); // len in words sprintf(configText, "0x%02x%02x", device->defx[0], device->defx[1]); for (i=1; i<len; i++) { sprintf(temp, " 0x%02x%02x", device->defx[2 * i + 0], device->defx[2 * i + 1]); strcat(configText, temp); } len = (int) GetIDSize(device); // len in words sprintf(IdText, "0x%02x%02x", dataWidthHi, dataWidthLo); for (i=1; i<len; i++) { sprintf(temp, " 0x%02x%02x", dataWidthHi, dataWidthLo); strcat(IdText, temp); } for (i=0; i<PIC_PROGRAM_SIZE; i++) { if (i & 1) picProgramData[i] = dataWidthHi; else picProgramData[i] = dataWidthLo; } size = (int) selectedPicDevice->def[PD_DATA_SIZEH] * 256 + selectedPicDevice->def[PD_DATA_SIZEL]; if (size & 0xff) size++; picDataSize = size; if (size) // device has data memory { regionDataButton->fg = black; eraseRegionDataButton->fg = black; for (i=0; i<MAX_EEPROM_DATA_SIZE; i++) picDataBuffer[i] = 0xff; } else { regionDataButton->fg = gray; eraseRegionDataButton->fg = gray; } IdAddress = GetIDAddr(device) * 2; IdSize = GetIDSize(device) * 2; CfgAddress = GetConfigStart(device) * 2; CfgSize = GetConfigSize(device) * 2; EepromAddress = GetDataStart(device); EepromSize = GetDataSize(device); showProgram(); break; } } if (!deviceFound) { strcpy(deviceType, " none selected "); dataWidthHi = 0xff; dataWidthLo = 0xff; }}void moveVMenu(void *v, int x, int y){ BLIST *list; BUTTON *b; VMENU *m = (VMENU *) v; m->x = x; m->y = y; list = m->list; b = list->thislist.button; while (list) { list->thislist.button->x = x; list->thislist.button->y = y; list = list->next; y += FONT_HEIGHT + 2; }}void readButtonCB(SDL_Event *event){ connectAlert->x = 250; connectAlert->y = 20; if (!checkPicDevice()) return; strcpy(regionMenu->list->thislist.button->text, " Read select "); PicFunction = PIC_FUNC_READ; pushDownMenus(); moveVMenu(regionMenu, 310, FONT_HEIGHT + 8); popUpWidget(regionMenu);}void programButtonCB(SDL_Event *event){ connectAlert->x = 10; connectAlert->y = 30; if (!checkPicDevice()) return; strcpy(regionMenu->list->thislist.button->text, " Write select "); PicFunction = PIC_FUNC_WRITE; pushDownMenus(); moveVMenu(regionMenu, 10, FONT_HEIGHT * 2 + 8); popUpWidget(regionMenu);}void eraseButtonCB(SDL_Event *event){ connectAlert->x = 20; connectAlert->y = 30; if (!checkPicDevice()) return; pushDownMenus(); popUpWidget(eraseRegionMenu);}void verifyButtonCB(SDL_Event *event){ connectAlert->x = 50; connectAlert->y = 30; if (!checkPicDevice()) return; strcpy(regionMenu->list->thislist.button->text, " Verify select "); PicFunction = PIC_FUNC_VERIFY; pushDownMenus(); moveVMenu(regionMenu, 100, FONT_HEIGHT * 2 + 8); popUpWidget(regionMenu);}void blankButtonCB(SDL_Event *event){ connectAlert->x = 100; connectAlert->y = 30; if (!checkPicDevice()) return; pushDownMenus(); if (issueCommand(PICP_COMMAND_BLANK_CHECK_ALL)) { popUpWidget(checkingWin); updateScreen(); if (getCommandResponse(PICP_COMMAND_BLANK_CHECK_ALL)) { sprintf(noticeMessage, "\n Program memory: "); if (blankCheckBits & BLANK_PROGRAM) strcat(noticeMessage, "blank"); else strcat(noticeMessage, "not blank"); strcat(noticeMessage, "\n Configuration bits: "); if (blankCheckBits & BLANK_CFGBITS) strcat(noticeMessage, "blank"); else strcat(noticeMessage, "not blank"); strcat(noticeMessage, "\n ID Locations: "); if (blankCheckBits & BLANK_IDLOC) strcat(noticeMessage, "blank"); else strcat(noticeMessage, "not blank"); strcat(noticeMessage, "\n Data memory: "); if (blankCheckBits & BLANK_DATA) strcat(noticeMessage, "blank\n"); else strcat(noticeMessage, "not blank\n"); blankCheckResultWin->w = 35 * FONT_WIDTH; popUpWidget(blankCheckResultWin); } pushDownWidget(checkingWin); } else connectFailAlert();}void idSelectCB(SDL_Event *event){ switch (PicFunction) { case PIC_FUNC_READ: readPicId(); break; case PIC_FUNC_WRITE: writePicId(); break; case PIC_FUNC_VERIFY: verifyPicId(); break; } pushDownWidget(regionMenu);}void configSelectCB(SDL_Event *event){ switch (PicFunction) { case PIC_FUNC_READ: readPicConfig(); break; case PIC_FUNC_WRITE: writePicConfig(); break; case PIC_FUNC_VERIFY: verifyPicConfig(); break; } pushDownWidget(regionMenu);}void readPicData(void){ int size; size = picDataSize; if (size) { moveVMenu(readingWin, 280, 30); popUpWidget(readingWin); updateScreen(); setMemoryDisplay(FALSE); if (issueCommand(PICP_COMMAND_READ_DATA)) { if (!getCommandResponse(PICP_COMMAND_READ_DATA)) { sprintf(alertMessage, " Read PIC data memory failed! "); errorAlert->x = 20; errorAlert->y = 10; errorAlert->w = (strlen(alertMessage) + 4) * FONT_WIDTH; waitForAlertResponse(errorAlert); } else { picDataPC = 0; disVSlider->offset = 0; disVSlider->position = 0; disVSlider->pc = 0; saveAsButton->fg = black; } } pushDownWidget(readingWin); showProgram(); }}void writePicData(void){ int i; time_t mtime; struct stat filestat; if (!checkPicDevice()) return; setMemoryDisplay(FALSE); 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_DATA)) getCommandResponse(PICP_COMMAND_WRITE_DATA); remove(tempFileName); showProgram(); pushDownWidget(writingWin);}void verifyPicData(void){ int i, size; bool fail = FALSE; if (!checkPicDevice()) return; size = picDataSize; if (size) { for (i=0; i<size; i++) // clear data space before reading from PS+ picDataTemp[i] = 0xff; setMemoryDisplay(FALSE); moveVMenu(readingWin, 80, 30); popUpWidget(readingWin); updateScreen(); if (is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -