VDPStatusRegViewer.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include "VDPStatusRegViewer.h"
  2. #include "VramBitMappedView.h"
  3. #include "VDPDataStore.h"
  4. #include "InteractiveLabel.h"
  5. #include <QMessageBox>
  6. #include <QPalette>
  7. highlightDispatcher::highlightDispatcher()
  8. {
  9. counter = 0;
  10. }
  11. void highlightDispatcher::receiveState(bool state)
  12. {
  13. if (state) {
  14. if (counter == 0) {
  15. emit dispatchState(true);
  16. }
  17. ++counter;
  18. } else {
  19. --counter;
  20. if (counter == 0) {
  21. emit dispatchState(false);
  22. }
  23. }
  24. }
  25. VDPStatusRegViewer::VDPStatusRegViewer(QWidget* parent)
  26. : QDialog(parent)
  27. {
  28. setupUi(this);
  29. //statusregs = VDPDataStore::instance().getStatusRegsPointer();
  30. statusregs = new unsigned char[16];
  31. // now hook up some signals and slots
  32. connectHighLights();
  33. // get initiale data
  34. refresh();
  35. }
  36. VDPStatusRegViewer::~VDPStatusRegViewer()
  37. {
  38. delete[] statusregs;
  39. }
  40. void VDPStatusRegViewer::decodeVDPStatusRegs()
  41. {
  42. // first update all hex values
  43. label_val_0->setText(QString("%1").arg(statusregs[0],2,16,QChar('0')).toUpper());
  44. label_val_1->setText(QString("%1").arg(statusregs[1],2,16,QChar('0')).toUpper());
  45. label_val_2->setText(QString("%1").arg(statusregs[2],2,16,QChar('0')).toUpper());
  46. label_val_3->setText(QString("%1").arg(statusregs[3],2,16,QChar('0')).toUpper());
  47. label_val_4->setText(QString("%1").arg(statusregs[4],2,16,QChar('0')).toUpper());
  48. label_val_5->setText(QString("%1").arg(statusregs[5],2,16,QChar('0')).toUpper());
  49. label_val_6->setText(QString("%1").arg(statusregs[6],2,16,QChar('0')).toUpper());
  50. label_val_7->setText(QString("%1").arg(statusregs[7],2,16,QChar('0')).toUpper());
  51. label_val_8->setText(QString("%1").arg(statusregs[8],2,16,QChar('0')).toUpper());
  52. label_val_9->setText(QString("%1").arg(statusregs[9],2,16,QChar('0')).toUpper());
  53. // update all the individual bits
  54. for (int r = 0; r <= 9; ++r) {
  55. for (int b = 7; b >= 0; --b) {
  56. QString name = QString("label_%1_%2").arg(r).arg(b);
  57. InteractiveLabel* l = findChild<InteractiveLabel*>(name);
  58. l->setText((statusregs[r] & (1 << b)) ? "1" : "0");
  59. }
  60. }
  61. // Start the interpretation
  62. label_I_0_7->setText((statusregs[0] & 128) ? "Interrupt" : "No int");
  63. label_I_0_6->setText((statusregs[0] & 64) ? "5th sprite" : "No 5th");
  64. label_I_0_5->setText((statusregs[0] & 32) ? "Collision" : "No collision");
  65. label_I_0_0->setText(QString("sprnr:%1").arg(statusregs[0] & 31));
  66. label_I_1_7->setText((statusregs[1] & 128) ? "Light" : "No light");
  67. label_I_1_6->setText((statusregs[1] & 64) ? "switch on" : "Switch off");
  68. label_I_1_0->setText((statusregs[1] & 1) ? "hor scanline int" : "no hor int");
  69. QString id;
  70. switch (statusregs[1] & 62) {
  71. case 0:
  72. id = QString("v9938");
  73. break;
  74. case 2:
  75. id = QString("v9948");
  76. break;
  77. case 4:
  78. id = QString("v9958");
  79. break;
  80. default:
  81. id = QString("unknown VDP");
  82. }
  83. label_I_1_1->setText(id);
  84. label_I_2_7->setText((statusregs[2] & 128) ? "Transfer ready" : "Transfering");
  85. label_I_2_6->setText((statusregs[2] & 64) ? "Vertical scanning" : "Not vert scan");
  86. label_I_2_5->setText((statusregs[2] & 32) ? "Horizontal scanning" : "Not hor scan");
  87. label_I_2_4->setText((statusregs[2] & 16) ? "Boundary color detected" : "BC not deteced");
  88. label_I_2_1->setText((statusregs[2] & 2) ? "First field" : "Second field");
  89. label_I_2_0->setText((statusregs[2] & 1) ? "Command execution" : "No command exec");
  90. label_I_3->setText(QString("Column: %1").arg(statusregs[3] | ((statusregs[4] & 1) << 8)));
  91. label_I_5->setText(QString("Row: %1").arg(statusregs[5] | ((statusregs[6] & 3) << 8)));
  92. label_I_7->setText(QString("Color: %1").arg(statusregs[7]));
  93. label_I_8->setText(QString("Border X: %1").arg(statusregs[8] | ((statusregs[9] & 1) << 8)));
  94. }
  95. void VDPStatusRegViewer::doConnect(InteractiveLabel* lab, highlightDispatcher* dis)
  96. {
  97. connect(lab, SIGNAL(mouseOver(bool)), dis, SLOT(receiveState(bool)));
  98. connect(dis, SIGNAL(dispatchState(bool)), lab, SLOT(highlight(bool)));
  99. }
  100. void VDPStatusRegViewer::makeGroup(QList<InteractiveLabel*> list, InteractiveLabel* explained)
  101. {
  102. // First "steal" the Tooltip of the explained widget.
  103. InteractiveLabel* item;
  104. foreach (item, list) {
  105. item->setToolTip(explained->toolTip());
  106. }
  107. // now create a dispatcher and connect all to them
  108. list << explained;
  109. highlightDispatcher* dispat = new highlightDispatcher();
  110. foreach (item, list) {
  111. doConnect(item, dispat);
  112. }
  113. }
  114. void VDPStatusRegViewer::connectHighLights()
  115. {
  116. QList<InteractiveLabel*> list;
  117. list.clear();
  118. list << label_0_7;
  119. makeGroup(list, label_I_0_7);
  120. list.clear();
  121. list << label_0_6;
  122. makeGroup(list, label_I_0_6);
  123. list.clear();
  124. list << label_0_5;
  125. makeGroup(list, label_I_0_5);
  126. list.clear();
  127. list << label_0_4 << label_0_3 << label_0_2 << label_0_1 << label_0_0;
  128. makeGroup(list, label_I_0_0);
  129. list.clear();
  130. list << label_1_7;
  131. makeGroup(list, label_I_1_7);
  132. list.clear();
  133. list << label_1_6;
  134. makeGroup(list, label_I_1_6);
  135. list.clear();
  136. list << label_1_4 << label_1_3 << label_1_2 << label_1_1;
  137. makeGroup(list, label_I_1_1);
  138. list.clear();
  139. list << label_1_0;
  140. makeGroup(list, label_I_1_0);
  141. list.clear();
  142. list << label_2_7;
  143. makeGroup(list, label_I_2_7);
  144. list.clear();
  145. list << label_2_6;
  146. makeGroup(list, label_I_2_6);
  147. list.clear();
  148. list << label_2_5;
  149. makeGroup(list, label_I_2_5);
  150. list.clear();
  151. list << label_2_4;
  152. makeGroup(list, label_I_2_4);
  153. list.clear();
  154. list << label_2_1;
  155. makeGroup(list, label_I_2_1);
  156. list.clear();
  157. list << label_2_0;
  158. makeGroup(list, label_I_2_0);
  159. list.clear();
  160. list << label_2_0;
  161. makeGroup(list, label_I_2_0);
  162. list.clear();
  163. list << label_3_7 << label_3_6 << label_3_5 << label_3_4;
  164. list << label_3_3 << label_3_2 << label_3_1 << label_3_0;
  165. list << label_4_7 << label_4_6 << label_4_5 << label_4_4;
  166. list << label_4_3 << label_4_2 << label_4_1 << label_4_0;
  167. makeGroup(list, label_I_3);
  168. list.clear();
  169. list << label_5_7 << label_5_6 << label_5_5 << label_5_4;
  170. list << label_5_3 << label_5_2 << label_5_1 << label_5_0;
  171. list << label_6_7 << label_6_6 << label_6_5 << label_6_4;
  172. list << label_6_3 << label_6_2 << label_6_1 << label_6_0;
  173. makeGroup(list, label_I_5);
  174. list.clear();
  175. list << label_7_7 << label_7_6 << label_7_5 << label_7_4;
  176. list << label_7_3 << label_7_2 << label_7_1 << label_7_0;
  177. makeGroup(list, label_I_7);
  178. list.clear();
  179. list << label_8_7 << label_8_6 << label_8_5 << label_8_4;
  180. list << label_8_3 << label_8_2 << label_8_1 << label_8_0;
  181. list << label_9_7 << label_9_6 << label_9_5 << label_9_4;
  182. list << label_9_3 << label_9_2 << label_9_1 << label_9_0;
  183. makeGroup(list, label_I_8);
  184. }
  185. void VDPStatusRegViewer::refresh()
  186. {
  187. new SimpleHexRequest("{VDP status regs}", 0, 16, statusregs, *this);
  188. }
  189. void VDPStatusRegViewer::DataHexRequestReceived()
  190. {
  191. decodeVDPStatusRegs();
  192. }