@@ -298,27 +298,31 @@ void MainWindow::build_operations_menu(QVBoxLayout* target_layout) {
298298 this ->button_read_cartridge = new QPushButton (" Read P2000T Cartridge" );
299299 this ->button_flash_rom = new QPushButton (" Write ROM" );
300300 this ->button_flash_bank = new QPushButton (" Write ROM to bank" );
301+ this ->button_scan_slots = new QPushButton (" Scan slots" );
301302
302303 layout->addWidget (this ->button_identify_chip );
303304 layout->addWidget (this ->button_read_rom );
304305 layout->addWidget (this ->button_read_cartridge );
305306 layout->addWidget (this ->button_flash_rom );
306307 layout->addWidget (this ->button_flash_bank );
307308 layout->addWidget (this ->button_erase_chip );
309+ layout->addWidget (this ->button_scan_slots );
308310
309311 this ->button_identify_chip ->setEnabled (false );
310312 this ->button_erase_chip ->setEnabled (false );
311313 this ->button_read_cartridge ->setEnabled (false );
312314 this ->button_read_rom ->setEnabled (false );
313315 this ->button_flash_rom ->setEnabled (false );
314316 this ->button_flash_bank ->setEnabled (false );
317+ this ->button_scan_slots ->setEnabled (false );
315318
316319 connect (this ->button_read_rom , SIGNAL (released ()), this , SLOT (read_rom ()));
317320 connect (this ->button_read_cartridge , SIGNAL (released ()), this , SLOT (read_cartridge ()));
318321 connect (this ->button_flash_rom , SIGNAL (released ()), this , SLOT (flash_rom ()));
319322 connect (this ->button_identify_chip , SIGNAL (released ()), this , SLOT (read_chip_id ()));
320323 connect (this ->button_flash_bank , SIGNAL (released ()), this , SLOT (flash_bank ()));
321324 connect (this ->button_erase_chip , SIGNAL (released ()), this , SLOT (erase_chip ()));
325+ connect (this ->button_scan_slots , SIGNAL (released ()), this , SLOT (scan_chip ()));
322326
323327 target_layout->addWidget (container);
324328 this ->progress_bar_load = new QProgressBar ();
@@ -682,6 +686,36 @@ void MainWindow::slot_update_settings() {
682686 this ->hex_widget ->viewport ()->repaint ();
683687}
684688
689+ /* *
690+ * @brief Convenience function on completing a chip scan
691+ */
692+ void MainWindow::parse_chip_read_results () {
693+ this ->progress_bar_load ->setValue (this ->progress_bar_load ->maximum ());
694+
695+ QByteArray data;
696+ if (this ->readerthread ) {
697+ data = this ->readerthread ->get_data ();
698+ this ->readerthread .reset (); // delete object
699+ } else if (this ->cartridgereaderthread ) {
700+ data = this ->cartridgereaderthread ->get_data ();
701+ this ->readerthread .reset (); // delete object
702+ } else {
703+ qDebug () << " This function should not have been called." ;
704+ }
705+
706+ qDebug () << " Read " << data.size () << " bytes from chip." ;
707+ this ->hex_widget ->set_data (data);
708+
709+ QByteArray hash = QCryptographicHash::hash (data, QCryptographicHash::Md5);
710+ this ->label_data_descriptor ->setText (QString (" <b>%1</b> | Size: %2 kb | MD5: %3" )
711+ .arg (" ROM data" )
712+ .arg (data.size () / 1024 )
713+ .arg (QString (hash.toHex ()))
714+ );
715+
716+ statusBar ()->showMessage (QString (" Done reading chip in %1 seconds." ).arg (this ->timer1 .elapsed () / 1000 .f ));
717+ }
718+
685719/* *
686720 * @brief Close the application
687721 */
@@ -804,6 +838,7 @@ void MainWindow::read_chip_id() {
804838 this ->button_flash_rom ->setEnabled (true );
805839 this ->button_flash_bank ->setEnabled (true );
806840 this ->button_erase_chip ->setEnabled (true );
841+ this ->button_scan_slots ->setEnabled (true );
807842 } catch (const std::exception& e) {
808843 QMessageBox msg_box;
809844 msg_box.setIcon (QMessageBox::Warning);
@@ -892,30 +927,18 @@ void MainWindow::read_block_done(unsigned int block_id, unsigned int nr_blocks)
892927 * @brief Signal that a read operation is finished
893928 */
894929void MainWindow::read_result_ready () {
895- this ->progress_bar_load ->setValue (this ->progress_bar_load ->maximum ());
896-
897- QByteArray data;
898- if (this ->readerthread ) {
899- data = this ->readerthread ->get_data ();
900- this ->readerthread .reset (); // delete object
901- } else if (this ->cartridgereaderthread ) {
902- data = this ->cartridgereaderthread ->get_data ();
903- this ->readerthread .reset (); // delete object
904- } else {
905- qDebug () << " This function should not have been called." ;
906- }
907-
908- qDebug () << " Read " << data.size () << " bytes from chip." ;
909- this ->hex_widget ->set_data (data);
930+ this ->parse_chip_read_results ();
931+ }
910932
911- QByteArray hash = QCryptographicHash::hash (data, QCryptographicHash::Md5);
912- this ->label_data_descriptor ->setText (QString (" <b>%1</b> | Size: %2 kb | MD5: %3" )
913- .arg (" ROM data" )
914- .arg (data.size () / 1024 )
915- .arg (QString (hash.toHex ()).toUpper ())
916- );
933+ /*
934+ * @brief Signal that a scan chip operation is finished
935+ */
936+ void MainWindow::scan_chip_result_ready () {
937+ this ->parse_chip_read_results ();
917938
918- statusBar ()->showMessage (QString (" Done reading chip in %1 seconds." ).arg (this ->timer1 .elapsed () / 1000 .f ));
939+ // at this point, the chip has been scanned and we can process the results
940+ BankViewer bankviewer (this ->num_blocks / BLOCKSPERBANK, this ->hex_widget ->get_data (), this );
941+ bankviewer.exec ();
919942}
920943
921944/* ***************************************************************************
@@ -1035,6 +1058,30 @@ void MainWindow::erase_chip() {
10351058 QMessageBox::information (this , " Chip erased." , " Done erasing the chip. All bytes are set of 0xFF." );
10361059}
10371060
1061+ /* *
1062+ * @brief MainWindow::Scan the ROMs on the chip
1063+ */
1064+ void MainWindow::scan_chip () {
1065+ // ask where to store file
1066+ statusBar ()->showMessage (" Reading from chip, please wait..." );
1067+ this ->label_data_descriptor ->clear ();
1068+
1069+ // dispatch thread
1070+ this ->timer1 .start ();
1071+
1072+ // disable all buttons so that the user cannot interrupt this task
1073+ // this->disable_all_buttons();
1074+
1075+ // dispatch thread
1076+ // this->operation = "Reading"; // message for statusbar
1077+ this ->readerthread = std::make_unique<ReadThread>(this ->serial_interface );
1078+ this ->readerthread ->set_serial_port (this ->combobox_serial_ports ->currentText ().toStdString ());
1079+ connect (this ->readerthread .get (), SIGNAL (read_result_ready ()), this , SLOT (scan_chip_result_ready ()));
1080+ connect (this ->readerthread .get (), SIGNAL (read_block_start (uint,uint)), this , SLOT (read_block_start (uint,uint)));
1081+ connect (this ->readerthread .get (), SIGNAL (read_block_done (uint,uint)), this , SLOT (read_block_done (uint,uint)));
1082+ this ->readerthread ->start ();
1083+ }
1084+
10381085/* *
10391086 * @brief Slot to indicate that a sector is about to be written
10401087 */
0 commit comments