BitMapViewer.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include "BitMapViewer.h"
  2. #include "VramBitMappedView.h"
  3. #include "VDPDataStore.h"
  4. #include <QMessageBox>
  5. static const unsigned char defaultPalette[32] = {
  6. // RB G
  7. 0x00, 0,
  8. 0x00, 0,
  9. 0x11, 6,
  10. 0x33, 7,
  11. 0x17, 1,
  12. 0x27, 3,
  13. 0x51, 1,
  14. 0x27, 6,
  15. 0x71, 1,
  16. 0x73, 3,
  17. 0x61, 6,
  18. 0x64, 6,
  19. 0x11, 4,
  20. 0x65, 2,
  21. 0x55, 5,
  22. 0x77, 7,
  23. };
  24. BitMapViewer::BitMapViewer(QWidget* parent)
  25. : QDialog(parent)
  26. , screenMod(0) // avoid UMR
  27. {
  28. setupUi(this);
  29. // hand code entering the actual display widget in the scrollarea With
  30. // the designer-qt4 there is an extra scrollAreaWidget between the
  31. // imageWidget and the QScrollArea so the scrollbars are not correctly
  32. // handled when the image is resized. (since the intermediate widget
  33. // stays the same size). I did not try to have this intermediate widget
  34. // resize and all, since it was superflous anyway.
  35. imageWidget = new VramBitMappedView();
  36. QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed);
  37. sizePolicy1.setHorizontalStretch(0);
  38. sizePolicy1.setVerticalStretch(0);
  39. sizePolicy1.setHeightForWidth(imageWidget->sizePolicy().hasHeightForWidth());
  40. imageWidget->setSizePolicy(sizePolicy1);
  41. imageWidget->setMinimumSize(QSize(256, 212));
  42. scrollArea->setWidget(imageWidget);
  43. useVDP = true;
  44. const unsigned char* vram = VDPDataStore::instance().getVramPointer();
  45. const unsigned char* palette = VDPDataStore::instance().getPalettePointer();
  46. imageWidget->setVramSource(vram);
  47. imageWidget->setVramAddress(0);
  48. imageWidget->setPaletteSource(palette);
  49. //now hook up some signals and slots
  50. connect(&VDPDataStore::instance(), SIGNAL(dataRefreshed()),
  51. this, SLOT(VDPDataStoreDataRefreshed()));
  52. connect(&VDPDataStore::instance(), SIGNAL(dataRefreshed()),
  53. imageWidget, SLOT(refresh()));
  54. connect(refreshButton, SIGNAL(clicked(bool)),
  55. &VDPDataStore::instance(), SLOT(refresh()));
  56. connect(imageWidget, SIGNAL(imagePosition(int,int,int,unsigned int,int)),
  57. this, SLOT(imagePositionUpdate(int,int,int,unsigned int,int)));
  58. connect(imageWidget, SIGNAL(imageClicked (int,int,int,unsigned int,int)),
  59. this, SLOT(imagePositionUpdate(int,int,int,unsigned int,int)));
  60. // and now go fetch the initial data
  61. VDPDataStore::instance().refresh();
  62. }
  63. void BitMapViewer::decodeVDPregs()
  64. {
  65. const unsigned char* regs = VDPDataStore::instance().getRegsPointer();
  66. // Get the number of lines
  67. int v1 = (regs[9] & 128) ? 212 : 192;
  68. printf("\nlines acording to the bits %i,: %i\n", (regs[9] & 128), v1);
  69. linesLabel->setText(QString("%1").arg(v1, 0, 10));
  70. if (useVDP) linesVisible->setCurrentIndex((regs[9] & 128) ? 1 : 0);
  71. // Get the border color
  72. int v2 = regs[7] & 15;
  73. printf("\nborder acording to the regs %i,: %i\n", regs[7], v2);
  74. if (regs[8] & 32) v2 = 0;
  75. printf("\ncolor 0 is pallet regs %i,: %i\n", (regs[8] & 32), v2);
  76. borderLabel->setText(QString("%1").arg(v2, 0, 10));
  77. if (useVDP) bgColor->setValue(v2);
  78. // Get current screenmode
  79. static const int bits_modetxt[128] = {
  80. 1, 3, 0, 255, 2, 255, 255, 255,
  81. 4, 255, 80, 255, 5, 255, 255, 255,
  82. 6, 255, 255, 255, 7, 255, 255, 255,
  83. 255, 255, 255, 255, 8, 255, 255, 255,
  84. 255, 255, 255, 255,255, 255, 255, 255,
  85. 255, 255, 255, 255,255, 255, 255, 255,
  86. 255, 255, 255, 255,255, 255, 255, 255,
  87. 255, 255, 255, 255, 12, 255, 255, 255,
  88. 255, 255, 255, 255,255, 255, 255, 255,
  89. 255, 255, 255, 255,255, 255, 255, 255,
  90. 255, 255, 255, 255,255, 255, 255, 255,
  91. 255, 255, 255, 255,255, 255, 255, 255,
  92. 255, 255, 255, 255,255, 255, 255, 255,
  93. 255, 255, 255, 255,255, 255, 255, 255,
  94. 255, 255, 255, 255,255, 255, 255, 255,
  95. 255, 255, 255, 255, 11, 255, 255, 255,
  96. };
  97. static const int bits_mode[128] = {
  98. 0, 0, 0, 0, 0, 0, 0, 0,
  99. 0, 0, 0, 0, 0, 0, 0, 0,
  100. 1, 0, 0, 0, 2, 0, 0, 0,
  101. 0, 0, 0, 0, 3, 0, 0, 0,
  102. 0, 0, 0, 0, 0, 0, 0, 0,
  103. 0, 0, 0, 0, 0, 0, 0, 0,
  104. 0, 0, 0, 0, 0, 0, 0, 0,
  105. 0, 0, 0, 0, 6, 0, 0, 0,
  106. 0, 0, 0, 0, 0, 0, 0, 0,
  107. 0, 0, 0, 0, 0, 0, 0, 0,
  108. 0, 0, 0, 0, 0, 0, 0, 0,
  109. 0, 0, 0, 0, 0, 0, 0, 0,
  110. 0, 0, 0, 0, 0, 0, 0, 0,
  111. 0, 0, 0, 0, 0, 0, 0, 0,
  112. 0, 0, 0, 0, 0, 0, 0, 0,
  113. 0, 0, 0, 0, 5, 0, 0, 0,
  114. };
  115. int v3 = ((regs[0] & 0x0E) << 1) | ((regs[1] & 0x18) >> 3) | ((regs[25] & 0x18) << 2);
  116. printf("screenMod according to the bits: %i\n", v3);
  117. modeLabel->setText(QString("%1").arg(bits_modetxt[v3], 0, 10));
  118. if (useVDP) screenMode->setCurrentIndex(bits_mode[v3]);
  119. // Get the current visible page
  120. unsigned p = (regs[2] >> 5) & 3;
  121. unsigned q = 1 << 15;
  122. if (bits_modetxt[v3] > 6) {
  123. p &= 1;
  124. q <<= 1;
  125. }
  126. printf("visible page according to the bits: %i\n",p);
  127. setPages();
  128. addressLabel->setText(QString("0x%1").arg(p * q, 5, 16, QChar('0')));
  129. if (useVDP) showPage->setCurrentIndex(p);
  130. }
  131. void BitMapViewer::refresh()
  132. {
  133. // All of the code is in the VDPDataStore;
  134. VDPDataStore::instance().refresh();
  135. }
  136. void BitMapViewer::on_screenMode_currentIndexChanged(const QString& text)
  137. {
  138. screenMod = text.toInt();
  139. printf("\nnew screenMod: %i\n", screenMod);
  140. //change then number of visibe pages when this changes
  141. imageWidget->setVramAddress(0);
  142. // make sure that we are decoding new mode from page 0, imagine viewing
  143. // page 3 of screen5 and then switching to screen 8 without changing the
  144. // starting vram address....
  145. imageWidget->setScreenMode(screenMod);
  146. setPages();
  147. }
  148. void BitMapViewer::setPages()
  149. {
  150. showPage->clear();
  151. showPage->insertItem(0, "0");
  152. showPage->insertItem(1, "1");
  153. if (screenMod < 7 && VDPDataStore::instance().getVRAMSize() > 0x10000) {
  154. showPage->insertItem(2, "2");
  155. showPage->insertItem(3, "3");
  156. }
  157. }
  158. void BitMapViewer::on_showPage_currentIndexChanged(int index)
  159. {
  160. //if this is the consequence of a .clear() in the
  161. // on_screenMode_currentIndexChanged we do nothing!
  162. if (index == -1) return;
  163. static const int m1[4] = { 0x00000, 0x08000, 0x10000, 0x18000 };
  164. printf("\nvoid BitMapViewer::on_showPage_currentIndexChanged( int %i);\n", index);
  165. if (screenMod >= 7) index *= 2;
  166. int vramAddress = m1[index];
  167. printf("vramAddress %i\n", vramAddress);
  168. imageWidget->setVramAddress(vramAddress);
  169. }
  170. void BitMapViewer::on_linesVisible_currentIndexChanged(int index)
  171. {
  172. static const int m[3] = { 192, 212, 256 };
  173. int lines = m[index];
  174. imageWidget->setLines(lines);
  175. }
  176. void BitMapViewer::on_bgColor_valueChanged(int value)
  177. {
  178. imageWidget->setBorderColor(value);
  179. }
  180. void BitMapViewer::on_useVDPRegisters_stateChanged(int state)
  181. {
  182. useVDP = state;
  183. screenMode->setEnabled(!state);
  184. linesVisible->setEnabled(!state);
  185. showPage->setEnabled(!state);
  186. bgColor->setEnabled(!state);
  187. decodeVDPregs();
  188. imageWidget->refresh();
  189. }
  190. void BitMapViewer::on_zoomLevel_valueChanged(double d)
  191. {
  192. imageWidget->setZoom(float(d));
  193. }
  194. void BitMapViewer::on_saveImageButton_clicked(bool checked)
  195. {
  196. QMessageBox::information(
  197. this,
  198. "Not yet implemented",
  199. "Sorry, the save image dialog is not yet implemented");
  200. }
  201. void BitMapViewer::on_editPaletteButton_clicked(bool checked)
  202. {
  203. useVDPPalette->setChecked(false);
  204. QMessageBox::information(
  205. this,
  206. "Not yet implemented",
  207. "Sorry, the palette editor is not yet implemented, "
  208. "only disabling 'Use VDP palette registers' for now");
  209. }
  210. void BitMapViewer::on_useVDPPalette_stateChanged(int state)
  211. {
  212. if (state) {
  213. const unsigned char* palette = VDPDataStore::instance().getPalettePointer();
  214. imageWidget->setPaletteSource(palette);
  215. } else {
  216. imageWidget->setPaletteSource(defaultPalette);
  217. }
  218. imageWidget->refresh();
  219. }
  220. /*
  221. void BitMapViewer::on_refreshButton_clicked(bool checked)
  222. {
  223. refresh();
  224. decodeVDPregs();
  225. imageWidget->refresh();
  226. }
  227. */
  228. void BitMapViewer::VDPDataStoreDataRefreshed()
  229. {
  230. decodeVDPregs();
  231. }
  232. void BitMapViewer::imagePositionUpdate(
  233. int x, int y, int color, unsigned addr, int byteValue)
  234. {
  235. labelX->setText(QString("%1").arg(x, 3, 10, QChar('0')));
  236. labelY->setText(QString("%1").arg(y, 3, 10, QChar('0')));
  237. labelColor->setText(QString("%1").arg(color, 3, 10, QChar('0')));
  238. labelByte->setText(QString("0x%1").arg(byteValue, 2, 16, QChar('0')));
  239. labelVramAddr->setText(QString("0x%1").arg(addr, 5, 16, QChar('0')));
  240. }