VDPDataStore.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "VDPDataStore.h"
  2. #include "CommClient.h"
  3. class VDPDataStoreVersionCheck : public SimpleCommand
  4. {
  5. public:
  6. VDPDataStoreVersionCheck(VDPDataStore& dataStore_)
  7. : SimpleCommand("debug desc {physical VRAM}")
  8. , dataStore(dataStore_)
  9. {
  10. }
  11. virtual void replyOk(const QString& message)
  12. {
  13. dataStore.debuggableNameVRAM = "physical VRAM";
  14. dataStore.got_version = true;
  15. dataStore.refresh();
  16. delete this;
  17. }
  18. virtual void replyNok(const QString& message)
  19. {
  20. dataStore.debuggableNameVRAM = "VRAM";
  21. dataStore.got_version = true;
  22. dataStore.refresh();
  23. delete this;
  24. }
  25. private:
  26. VDPDataStore& dataStore;
  27. };
  28. class VDPDataStoreVRAMSizeCheck : public SimpleCommand
  29. {
  30. public:
  31. VDPDataStoreVRAMSizeCheck(VDPDataStore& dataStore_)
  32. : SimpleCommand("debug size {" + QString::fromStdString(dataStore_.debuggableNameVRAM) + "}")
  33. , dataStore(dataStore_)
  34. {
  35. }
  36. virtual void replyOk(const QString& message)
  37. {
  38. dataStore.vramSize = message.toInt();
  39. dataStore.refresh2();
  40. delete this;
  41. }
  42. virtual void replyNok(const QString& message)
  43. {
  44. delete this;
  45. }
  46. private:
  47. VDPDataStore& dataStore;
  48. };
  49. static const unsigned MAX_VRAM_SIZE = 0x30000;
  50. static const unsigned MAX_TOTAL_SIZE = MAX_VRAM_SIZE + 32 + 16 + 64 + 2;
  51. VDPDataStore::VDPDataStore()
  52. {
  53. vram = new unsigned char[MAX_TOTAL_SIZE];
  54. memset(vram, 0x00, MAX_TOTAL_SIZE);
  55. got_version = false;
  56. CommClient::instance().sendCommand(new VDPDataStoreVersionCheck(*this));
  57. }
  58. VDPDataStore::~VDPDataStore()
  59. {
  60. delete[] vram;
  61. }
  62. VDPDataStore& VDPDataStore::instance()
  63. {
  64. static VDPDataStore oneInstance;
  65. return oneInstance;
  66. }
  67. void VDPDataStore::refresh()
  68. {
  69. if (!got_version) return;
  70. refresh1();
  71. }
  72. void VDPDataStore::refresh1()
  73. {
  74. CommClient::instance().sendCommand(new VDPDataStoreVRAMSizeCheck(*this));
  75. }
  76. void VDPDataStore::refresh2()
  77. {
  78. QString req = QString(
  79. "debug_bin2hex "
  80. "[ debug read_block {" + QString::fromStdString(debuggableNameVRAM) + "} 0 " + QString::number(vramSize) + " ]"
  81. "[ debug read_block {VDP palette} 0 32 ]"
  82. "[ debug read_block {VDP status regs} 0 16 ]"
  83. "[ debug read_block {VDP regs} 0 64 ]"
  84. "[ debug read_block {VRAM pointer} 0 2 ]");
  85. new SimpleHexRequest(req, MAX_TOTAL_SIZE - MAX_VRAM_SIZE + vramSize, vram, *this);
  86. }
  87. void VDPDataStore::DataHexRequestReceived()
  88. {
  89. emit dataRefreshed();
  90. }
  91. const unsigned char* VDPDataStore::getVramPointer() const
  92. {
  93. return vram;
  94. }
  95. const unsigned char* VDPDataStore::getPalettePointer() const
  96. {
  97. return vram + vramSize;
  98. }
  99. const unsigned char* VDPDataStore::getStatusRegsPointer() const
  100. {
  101. return vram + vramSize + 32;
  102. }
  103. const unsigned char* VDPDataStore::getRegsPointer() const
  104. {
  105. return vram + vramSize + 32 + 16;
  106. }
  107. const unsigned char* VDPDataStore::getVdpVramPointer() const
  108. {
  109. return vram + vramSize + 32 + 16 + 64;
  110. }
  111. const size_t VDPDataStore::getVRAMSize() const
  112. {
  113. return vramSize;
  114. }