disassembler_test.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* ScummVM Tools
  2. *
  3. * ScummVM Tools is the legal property of its developers, whose
  4. * names are too numerous to list here. Please refer to the
  5. * COPYRIGHT file distributed with this source distribution.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #include "disassembler/pasc.h"
  22. #include "disassembler/subopcode.h"
  23. #include "decompiler/scummv6/disassembler.h"
  24. #include <gmock/gmock.h>
  25. TEST(Disassembler, testDisassembly) {
  26. try {
  27. InstVec insts;
  28. PasCDisassembler p(insts);
  29. p.open("decompiler/test/hanoi20.pasb");
  30. p.disassemble();
  31. ASSERT_EQ(insts[0]->_address, 0);
  32. ASSERT_EQ(insts[0]->_opcode, 0x00);
  33. ASSERT_EQ(insts[0]->_name, "PUSH");
  34. ASSERT_EQ(insts[0]->_stackChange, 0);
  35. ASSERT_TRUE(insts[0]->_params[0]->isInteger());
  36. ASSERT_EQ(insts[0]->_params[0]->getSigned(), 0x60);
  37. }
  38. catch (UnknownOpcodeException &uoe) {
  39. printf("Exception message: %s\n", uoe.what());
  40. ASSERT_TRUE(false);
  41. }
  42. catch (std::exception &ex) {
  43. printf("Exception message: %s\n", ex.what());
  44. ASSERT_TRUE(false);
  45. }
  46. }
  47. TEST(Disassembler, testSubOpcodeDisassembly) {
  48. InstVec insts;
  49. SubOpcodeDisassembler s(insts);
  50. s.open("decompiler/test/subopcode_test.bin");
  51. s.disassemble();
  52. ASSERT_TRUE(insts[0]->_name == "FOO");
  53. ASSERT_TRUE(insts[0]->_opcode == 0xFFFF);
  54. }
  55. TEST(Disassembler, testUnknownOpcodeException) {
  56. try {
  57. InstVec insts;
  58. SubOpcodeDisassembler s(insts);
  59. s.open("decompiler/test/unknownopcode_test.bin");
  60. s.disassemble();
  61. ASSERT_TRUE(false);
  62. }
  63. catch (UnknownOpcodeException) {
  64. ASSERT_TRUE(true);
  65. }
  66. }
  67. // This test requires script-15.dmp from Sam & Max: Hit The Road.
  68. // 1ab08298c9c8fb4c77953756989c7449 *script-15.dmp
  69. // Disabled as mentioned file is copyrighted
  70. TEST(Disassembler, DISABLED_testScummv6DisassemblerScript15) {
  71. InstVec insts;
  72. Scumm::v6::Scummv6Disassembler s(insts);
  73. s.open("decompiler/test/script-15.dmp");
  74. s.disassemble();
  75. ASSERT_TRUE(insts.size() == 11);
  76. ASSERT_TRUE(insts[0]->_address == 0);
  77. ASSERT_TRUE(insts[0]->_opcode == 0x03);
  78. ASSERT_TRUE(insts[0]->_name == "pushWordVar");
  79. ASSERT_TRUE(insts[0]->_params[0]->getUnsigned() == 16384);
  80. ASSERT_TRUE(insts[1]->_address == 3);
  81. ASSERT_TRUE(insts[1]->_opcode == 0x43);
  82. ASSERT_TRUE(insts[1]->_name == "writeWordVar");
  83. ASSERT_TRUE(insts[1]->_params[0]->getUnsigned() == 197);
  84. ASSERT_TRUE(insts[2]->_address == 6);
  85. ASSERT_TRUE(insts[2]->_opcode == 0x01);
  86. ASSERT_TRUE(insts[2]->_name == "pushWord");
  87. ASSERT_TRUE(insts[2]->_params[0]->getSigned() == 0);
  88. ASSERT_TRUE(insts[3]->_address == 9);
  89. ASSERT_TRUE(insts[3]->_opcode == 0x01);
  90. ASSERT_TRUE(insts[3]->_name == "pushWord");
  91. ASSERT_TRUE(insts[3]->_params[0]->getSigned() == 11);
  92. ASSERT_TRUE(insts[4]->_address == 12);
  93. ASSERT_TRUE(insts[4]->_opcode == 0x01);
  94. ASSERT_TRUE(insts[4]->_name == "pushWord");
  95. ASSERT_TRUE(insts[4]->_params[0]->getSigned() == 0);
  96. ASSERT_TRUE(insts[5]->_address == 15);
  97. ASSERT_TRUE(insts[5]->_opcode == 0x5E);
  98. ASSERT_TRUE(insts[5]->_name == "startScript");
  99. ASSERT_TRUE(insts[6]->_address == 16);
  100. ASSERT_TRUE(insts[6]->_opcode == 0x01);
  101. ASSERT_TRUE(insts[6]->_name == "pushWord");
  102. ASSERT_TRUE(insts[6]->_params[0]->getSigned() == 0);
  103. ASSERT_TRUE(insts[7]->_address == 19);
  104. ASSERT_TRUE(insts[7]->_opcode == 0x01);
  105. ASSERT_TRUE(insts[7]->_name == "pushWord");
  106. ASSERT_TRUE(insts[7]->_params[0]->getSigned() == 14);
  107. ASSERT_TRUE(insts[8]->_address == 22);
  108. ASSERT_TRUE(insts[8]->_opcode == 0x01);
  109. ASSERT_TRUE(insts[8]->_name == "pushWord");
  110. ASSERT_TRUE(insts[8]->_params[0]->getSigned() == 0);
  111. ASSERT_TRUE(insts[9]->_address == 25);
  112. ASSERT_TRUE(insts[9]->_opcode == 0x5E);
  113. ASSERT_TRUE(insts[9]->_name == "startScript");
  114. ASSERT_TRUE(insts[10]->_address == 26);
  115. ASSERT_TRUE(insts[10]->_opcode == 0x66);
  116. ASSERT_TRUE(insts[10]->_name == "stopObjectCodeB");
  117. }
  118. // This test requires script-31.dmp from Sam & Max: Hit The Road.
  119. // f75f7ce110f378735d449f8eeb4a68e5 *script-31.dmp
  120. // Disabled as mentioned file is copyrighted
  121. TEST(Disassembler, DISABLED_testScummv6DisassemblerScript31) {
  122. InstVec insts;
  123. Scumm::v6::Scummv6Disassembler s(insts);
  124. s.open("decompiler/test/script-31.dmp");
  125. s.disassemble();
  126. ASSERT_TRUE(insts.size() == 5);
  127. ASSERT_TRUE(insts[0]->_address == 0);
  128. ASSERT_TRUE(insts[0]->_opcode == 0x01);
  129. ASSERT_TRUE(insts[0]->_name == "pushWord");
  130. ASSERT_TRUE(insts[0]->_params[0]->getSigned() == 0);
  131. ASSERT_TRUE(insts[1]->_address == 3);
  132. ASSERT_TRUE(insts[1]->_opcode == 0x43);
  133. ASSERT_TRUE(insts[1]->_name == "writeWordVar");
  134. ASSERT_TRUE(insts[1]->_params[0]->getUnsigned() == 180);
  135. ASSERT_TRUE(insts[2]->_address == 6);
  136. ASSERT_TRUE(insts[2]->_opcode == 0x01);
  137. ASSERT_TRUE(insts[2]->_name == "pushWord");
  138. ASSERT_TRUE(insts[2]->_params[0]->getSigned() == 0);
  139. ASSERT_TRUE(insts[3]->_address == 9);
  140. ASSERT_TRUE(insts[3]->_opcode == 0x43);
  141. ASSERT_TRUE(insts[3]->_name == "writeWordVar");
  142. ASSERT_TRUE(insts[3]->_params[0]->getUnsigned() == 181);
  143. ASSERT_TRUE(insts[4]->_address == 12);
  144. ASSERT_TRUE(insts[4]->_opcode == 0x66);
  145. ASSERT_TRUE(insts[4]->_name == "stopObjectCodeB");
  146. }
  147. // This test requires script-33.dmp from Sam & Max: Hit The Road.
  148. // 9f09418bf34abbdec0ec54f388d8dca4 *script-33.dmp
  149. // Disabled as mentioned file is copyrighted
  150. TEST(Disassembler, DISABLED_testScummv6DisassemblerScript33) {
  151. InstVec insts;
  152. Scumm::v6::Scummv6Disassembler s(insts);
  153. s.open("decompiler/test/script-33.dmp");
  154. s.disassemble();
  155. ASSERT_TRUE(insts.size() == 10);
  156. ASSERT_TRUE(insts[0]->_address == 0);
  157. ASSERT_TRUE(insts[0]->_opcode == 0x01);
  158. ASSERT_TRUE(insts[0]->_name == "pushWord");
  159. ASSERT_TRUE(insts[0]->_params[0]->getSigned() == 0);
  160. ASSERT_TRUE(insts[1]->_address == 3);
  161. ASSERT_TRUE(insts[1]->_opcode == 0x43);
  162. ASSERT_TRUE(insts[1]->_name == "writeWordVar");
  163. ASSERT_TRUE(insts[1]->_params[0]->getUnsigned() == 71);
  164. ASSERT_TRUE(insts[2]->_address == 6);
  165. ASSERT_TRUE(insts[2]->_opcode == 0x03);
  166. ASSERT_TRUE(insts[2]->_name == "pushWordVar");
  167. ASSERT_TRUE(insts[2]->_params[0]->getUnsigned() == 177);
  168. ASSERT_TRUE(insts[3]->_address == 9);
  169. ASSERT_TRUE(insts[3]->_opcode == 0x43);
  170. ASSERT_TRUE(insts[3]->_name == "writeWordVar");
  171. ASSERT_TRUE(insts[3]->_params[0]->getUnsigned() == 173);
  172. ASSERT_TRUE(insts[4]->_address == 12);
  173. ASSERT_TRUE(insts[4]->_opcode == 0x01);
  174. ASSERT_TRUE(insts[4]->_name == "pushWord");
  175. ASSERT_TRUE(insts[4]->_params[0]->getSigned() == 874);
  176. ASSERT_TRUE(insts[5]->_address == 15);
  177. ASSERT_TRUE(insts[5]->_opcode == 0x43);
  178. ASSERT_TRUE(insts[5]->_name == "writeWordVar");
  179. ASSERT_TRUE(insts[5]->_params[0]->getUnsigned() == 177);
  180. ASSERT_TRUE(insts[6]->_address == 18);
  181. ASSERT_TRUE(insts[6]->_opcode == 0x03);
  182. ASSERT_TRUE(insts[6]->_name == "pushWordVar");
  183. ASSERT_TRUE(insts[6]->_params[0]->getUnsigned() == 177);
  184. ASSERT_TRUE(insts[7]->_address == 21);
  185. ASSERT_TRUE(insts[7]->_opcode == 0x01);
  186. ASSERT_TRUE(insts[7]->_name == "pushWord");
  187. ASSERT_TRUE(insts[7]->_params[0]->getSigned() == 93);
  188. ASSERT_TRUE(insts[8]->_address == 24);
  189. ASSERT_TRUE(insts[8]->_opcode == 0x6B99);
  190. ASSERT_TRUE(insts[8]->_name == "cursorCommand.setCursorImg");
  191. ASSERT_TRUE(insts[9]->_address == 26);
  192. ASSERT_TRUE(insts[9]->_opcode == 0x66);
  193. ASSERT_TRUE(insts[9]->_name == "stopObjectCodeB");
  194. }
  195. // This test requires room-9-202.dmp from Sam & Max: Hit The Road.
  196. // f010dc659264674a2b6da298acd0b88b *room-9-202.dmp
  197. TEST(Disassembler, DISABLED_testScummv6StackChangeFixRoom9202) {
  198. InstVec insts;
  199. Scumm::v6::Scummv6Disassembler s(insts);
  200. s.open("decompiler/test/room-9-202.dmp");
  201. s.disassemble();
  202. InstIterator it = insts.end();
  203. it -= 8;
  204. ASSERT_TRUE((*it)->_stackChange == -3);
  205. }
  206. // This test requires script-30.dmp from Sam & Max: Hit The Road.
  207. // 6e48faca13e1f6df9341567608962744 *script-30.dmp
  208. TEST(Disassembler, DISABLED_testScummv6StackChangeFixScript30) {
  209. InstVec insts;
  210. Scumm::v6::Scummv6Disassembler s(insts);
  211. s.open("decompiler/test/script-30.dmp");
  212. s.disassemble();
  213. InstIterator it = insts.end();
  214. it -= 3;
  215. ASSERT_TRUE((*it)->_stackChange == -6);
  216. }