@@ -53,6 +53,11 @@ MainWindow::MainWindow(const std::shared_ptr<QStringList> _log_messages, QWidget
53
53
this ->hex_widget ->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
54
54
container_layout->addWidget (this ->hex_widget );
55
55
56
+ this ->button_reload_file = new QPushButton (" Reload file" );
57
+ container_layout->addWidget (this ->button_reload_file );
58
+ this ->button_reload_file ->setEnabled (false );
59
+ connect (this ->button_reload_file , SIGNAL (released ()), this , SLOT (slot_reload_file ()));
60
+
56
61
// create central widget for writing data
57
62
QScrollArea *scroll_area = new QScrollArea ();
58
63
layout->addWidget (scroll_area);
@@ -569,9 +574,10 @@ void MainWindow::slot_open() {
569
574
return ;
570
575
}
571
576
572
- file.open (QIODevice::ReadOnly);
573
577
if (file.exists ()) {
578
+ file.open (QIODevice::ReadOnly);
574
579
QByteArray data = file.readAll ();
580
+ this ->current_filename = file.fileName ();
575
581
int filesize = data.size ();
576
582
577
583
// ask the user whether they want to expand the image
@@ -582,11 +588,15 @@ void MainWindow::slot_open() {
582
588
" be used as a cartridge, would you like to to expand it "
583
589
" to 16kb by padding the data with 0x00?" , QMessageBox::Yes|QMessageBox::No);
584
590
if (reply == QMessageBox::Yes) {
591
+ this ->current_file_expanded = true ;
585
592
resize_qbytearray (&data, 0x4000 );
593
+ } else {
594
+ this ->current_file_expanded = false ;
586
595
}
587
596
}
588
597
589
598
this ->hex_widget ->set_data (data);
599
+ this ->button_reload_file ->setEnabled (true );
590
600
591
601
QByteArray hash = QCryptographicHash::hash (data, QCryptographicHash::Md5);
592
602
QFileInfo finfo (file);
@@ -607,6 +617,46 @@ void MainWindow::slot_open() {
607
617
}
608
618
}
609
619
620
+ /* *
621
+ * @brief MainWindow::reload a file
622
+ */
623
+ void MainWindow::slot_reload_file () {
624
+ QFile file (this ->current_filename );
625
+
626
+ if (file.exists ()) {
627
+ file.open (QIODevice::ReadOnly);
628
+ QByteArray data = file.readAll ();
629
+ this ->current_filename = file.fileName ();
630
+ int filesize = data.size ();
631
+
632
+ // ask the user whether they want to expand the image
633
+ if (data.size () < 0x4000 && this ->current_file_expanded ) {
634
+ resize_qbytearray (&data, 0x4000 );
635
+ }
636
+
637
+ this ->hex_widget ->set_data (data);
638
+
639
+ QByteArray hash = QCryptographicHash::hash (data, QCryptographicHash::Md5);
640
+ QFileInfo finfo (file);
641
+
642
+ QString usage;
643
+ if (data.size () == 0x4000 ) {
644
+ usage = QString (" | %1 kb / %2 kb (%3 %)" )
645
+ .arg (QString::number ((float )filesize/(float )1024 , ' f' , 1 ))
646
+ .arg (QString::number (16 , ' f' , 1 ))
647
+ .arg ((float )filesize/(float )(16 * 1024 ) * 100 , 0 , ' f' , 1 );
648
+ }
649
+
650
+ this ->label_data_descriptor ->setText (QString (" <b>%1</b> | Size: %2 kb | MD5: %3" + usage)
651
+ .arg (finfo.fileName ())
652
+ .arg (data.size () / 1024 )
653
+ .arg (QString (hash.toHex ()))
654
+ );
655
+
656
+ statusBar ()->showMessage (tr (" Reloaded %1 from drive." ).arg (this ->current_filename ));
657
+ }
658
+ }
659
+
610
660
/* *
611
661
* @brief Open a binary file
612
662
*/
@@ -741,6 +791,7 @@ void MainWindow::load_default_image() {
741
791
if (timer.isActive ()) {
742
792
QByteArray data = fd->downloadedData ();
743
793
this ->hex_widget ->set_data (data);
794
+ this ->button_reload_file ->setEnabled (false );
744
795
745
796
QString rom_name = image.split (QChar (' /' )).back ();
746
797
@@ -870,6 +921,7 @@ void MainWindow::read_rom() {
870
921
connect (this ->readerthread .get (), SIGNAL (read_result_ready ()), this , SLOT (read_result_ready ()));
871
922
connect (this ->readerthread .get (), SIGNAL (read_block_start (uint ,uint )), this , SLOT (read_block_start (uint ,uint )));
872
923
connect (this ->readerthread .get (), SIGNAL (read_block_done (uint ,uint )), this , SLOT (read_block_done (uint ,uint )));
924
+ connect (this ->readerthread .get (), SIGNAL (thread_abort (const QString&)), this , SLOT (thread_abort (const QString&)));
873
925
this ->readerthread ->start ();
874
926
}
875
927
@@ -899,6 +951,7 @@ void MainWindow::read_cartridge() {
899
951
connect (this ->cartridgereaderthread .get (), SIGNAL (read_result_ready ()), this , SLOT (read_result_ready ()));
900
952
connect (this ->cartridgereaderthread .get (), SIGNAL (read_block_start (uint ,uint )), this , SLOT (read_block_start (uint ,uint )));
901
953
connect (this ->cartridgereaderthread .get (), SIGNAL (read_block_done (uint ,uint )), this , SLOT (read_block_done (uint ,uint )));
954
+ connect (this ->readerthread .get (), SIGNAL (thread_abort (const QString&)), this , SLOT (thread_abort (const QString&)));
902
955
this ->cartridgereaderthread ->start ();
903
956
}
904
957
@@ -955,7 +1008,17 @@ void MainWindow::flash_rom() {
955
1008
956
1009
// verify whether the chip is correct
957
1010
qDebug () << " Verifying chip" ;
958
- this ->verify_chip ();
1011
+ try {
1012
+ this ->verify_chip ();
1013
+ } catch (const std::exception & e) {
1014
+ this ->raise_error_window (QMessageBox::Critical,
1015
+ " Cannot flash this ROM to bank due to a problem with "
1016
+ " with the CHIP id. Please carefully check the chip and "
1017
+ " whether it is properly inserted into the socket."
1018
+ " \n\n Error message: " + QString (e.what ())
1019
+ );
1020
+ return ;
1021
+ }
959
1022
960
1023
if ((this ->num_blocks * 256 ) < this ->flash_data .size ()) {
961
1024
@@ -984,7 +1047,7 @@ void MainWindow::flash_rom() {
984
1047
connect (this ->flashthread .get (), SIGNAL (flash_result_ready ()), this , SLOT (flash_result_ready ()));
985
1048
connect (this ->flashthread .get (), SIGNAL (flash_sector_start (uint ,uint )), this , SLOT (flash_sector_start (uint ,uint )));
986
1049
connect (this ->flashthread .get (), SIGNAL (flash_sector_done (uint ,uint )), this , SLOT (flash_sector_done (uint ,uint )));
987
- connect (this ->flashthread .get (), SIGNAL (flash_chip_id_error ( uint )), this , SLOT (flash_chip_id_error ( uint )));
1050
+ connect (this ->readerthread .get (), SIGNAL (thread_abort ( const QString& )), this , SLOT (thread_abort ( const QString& )));
988
1051
flashthread->start ();
989
1052
990
1053
// disable all buttons
@@ -1011,7 +1074,17 @@ void MainWindow::flash_bank() {
1011
1074
this ->flash_data = this ->hex_widget ->get_data ();
1012
1075
1013
1076
// verify whether the chip is correct
1014
- this ->verify_chip ();
1077
+ try {
1078
+ this ->verify_chip ();
1079
+ } catch (const std::exception & e) {
1080
+ this ->raise_error_window (QMessageBox::Critical,
1081
+ " Cannot flash this ROM to bank due to a problem with "
1082
+ " with the CHIP id. Please carefully check the chip and "
1083
+ " whether it is properly inserted into the socket."
1084
+ " \n\n Error message: " + QString (e.what ())
1085
+ );
1086
+ return ;
1087
+ }
1015
1088
1016
1089
if (this ->flash_data .size () > 16 * 1024 ) {
1017
1090
this ->raise_error_window (QMessageBox::Critical,
@@ -1034,7 +1107,7 @@ void MainWindow::flash_bank() {
1034
1107
connect (this ->flashthread .get (), SIGNAL (flash_result_ready ()), this , SLOT (flash_result_ready ()));
1035
1108
connect (this ->flashthread .get (), SIGNAL (flash_sector_start (uint ,uint )), this , SLOT (flash_sector_start (uint ,uint )));
1036
1109
connect (this ->flashthread .get (), SIGNAL (flash_sector_done (uint ,uint )), this , SLOT (flash_sector_done (uint ,uint )));
1037
- connect (this ->flashthread .get (), SIGNAL (flash_chip_id_error ( uint )), this , SLOT (flash_chip_id_error ( uint )));
1110
+ connect (this ->readerthread .get (), SIGNAL (thread_abort ( const QString& )), this , SLOT (thread_abort ( const QString& )));
1038
1111
flashthread->start ();
1039
1112
1040
1113
// disable all buttons
@@ -1045,6 +1118,19 @@ void MainWindow::flash_bank() {
1045
1118
* @brief Put rom on flash cartridge
1046
1119
*/
1047
1120
void MainWindow::erase_chip () {
1121
+ // verify whether the chip is correct
1122
+ try {
1123
+ this ->verify_chip ();
1124
+ } catch (const std::exception & e) {
1125
+ this ->raise_error_window (QMessageBox::Critical,
1126
+ " Cannot flash this ROM to bank due to a problem with "
1127
+ " with the CHIP id. Please carefully check the chip and "
1128
+ " whether it is properly inserted into the socket."
1129
+ " \n\n Error message: " + QString (e.what ())
1130
+ );
1131
+ return ;
1132
+ }
1133
+
1048
1134
QMessageBox::StandardButton reply;
1049
1135
reply = QMessageBox::question (this , " Wipe chip?" , " Are you sure you want to completely wipe the chip?" , QMessageBox::Yes|QMessageBox::No);
1050
1136
if (reply != QMessageBox::Yes) {
@@ -1079,6 +1165,7 @@ void MainWindow::scan_chip() {
1079
1165
connect (this ->readerthread .get (), SIGNAL (read_result_ready ()), this , SLOT (scan_chip_result_ready ()));
1080
1166
connect (this ->readerthread .get (), SIGNAL (read_block_start (uint ,uint )), this , SLOT (read_block_start (uint ,uint )));
1081
1167
connect (this ->readerthread .get (), SIGNAL (read_block_done (uint ,uint )), this , SLOT (read_block_done (uint ,uint )));
1168
+ connect (this ->readerthread .get (), SIGNAL (thread_abort (const QString&)), this , SLOT (thread_abort (const QString&)));
1082
1169
this ->readerthread ->start ();
1083
1170
}
1084
1171
@@ -1126,6 +1213,7 @@ void MainWindow::flash_result_ready() {
1126
1213
connect (this ->readerthread .get (), SIGNAL (read_result_ready ()), this , SLOT (verify_result_ready ()));
1127
1214
connect (this ->readerthread .get (), SIGNAL (read_block_start (uint ,uint )), this , SLOT (verify_block_start (uint ,uint )));
1128
1215
connect (this ->readerthread .get (), SIGNAL (read_block_done (uint ,uint )), this , SLOT (verify_block_done (uint ,uint )));
1216
+ connect (this ->readerthread .get (), SIGNAL (thread_abort (const QString&)), this , SLOT (thread_abort (const QString&)));
1129
1217
this ->readerthread ->start ();
1130
1218
}
1131
1219
@@ -1193,3 +1281,29 @@ void MainWindow::verify_result_ready() {
1193
1281
// this->enable_all_buttons();
1194
1282
this ->progress_bar_load ->reset ();
1195
1283
}
1284
+
1285
+ void MainWindow::thread_abort (const QString& error) {
1286
+ // clean up threads
1287
+ if (this ->readerthread ) {
1288
+ while (!this ->readerthread ->isFinished ()) {}
1289
+ this ->readerthread .reset (); // delete object
1290
+ }
1291
+
1292
+ if (this ->flashthread ) {
1293
+ while (!this ->flashthread ->isFinished ()) {}
1294
+ this ->flashthread .reset (); // delete object
1295
+ }
1296
+
1297
+ if (this ->cartridgereaderthread ) {
1298
+ while (!this ->cartridgereaderthread ->isFinished ()) {}
1299
+ this ->cartridgereaderthread .reset (); // delete object
1300
+ }
1301
+
1302
+ // throw error message
1303
+ this ->raise_error_window (QMessageBox::Critical,
1304
+ " Operation terminated unexpectedly. Please carefully "
1305
+ " check all settings and verify that the chip is "
1306
+ " properly inserted into the socket."
1307
+ " \n\n Error message: " + error
1308
+ );
1309
+ }
0 commit comments