pasc.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "pasc.h"
  22. PasCDisassembler::PasCDisassembler(InstVec &insts) : ::SimpleDisassembler(insts) {
  23. }
  24. void PasCDisassembler::doDisassemble(){
  25. START_OPCODES;
  26. //Basic machine operations
  27. OPCODE(0x00, "PUSH", PasCFakeInstruction, 0, "i");
  28. OPCODE(0x01, "POP", PasCFakeInstruction, 0, "i");
  29. OPCODE(0x02, "CALL", PasCFakeInstruction, 0, "d");
  30. OPCODE(0x03, "RETURN", PasCFakeInstruction, 0, "");
  31. OPCODE(0x04, "HALT", PasCFakeInstruction, 0, "");
  32. //Jumps
  33. OPCODE(0x10, "JUMP", PasCFakeInstruction, 0, "a");
  34. OPCODE(0x11, "JEQ", PasCFakeInstruction, 0, "a");
  35. OPCODE(0x12, "JAEQ", PasCFakeInstruction, 0, "a");
  36. OPCODE(0x13, "JGT", PasCFakeInstruction, 0, "a");
  37. OPCODE(0x14, "JLT", PasCFakeInstruction, 0, "a");
  38. OPCODE(0x15, "JALT", PasCFakeInstruction, 0, "a");
  39. OPCODE(0x16, "JAGT", PasCFakeInstruction, 0, "a");
  40. //Boolean operations
  41. OPCODE(0x20, "OR", PasCFakeInstruction, -1, "");
  42. OPCODE(0x21, "AND", PasCFakeInstruction, -1, "");
  43. OPCODE(0x22, "XOR", PasCFakeInstruction, -1, "");
  44. OPCODE(0x23, "NOT", PasCFakeInstruction, -1, "");
  45. //Padding instructions (smaller integer -> larger integer)
  46. OPCODE(0x30, "SPAD", PasCFakeInstruction, 0, "B");
  47. OPCODE(0x31, "UPAD", PasCFakeInstruction, 0, "B");
  48. //32-bit operations
  49. OPCODE(0x80, "IADD", PasCFakeInstruction, -4, "");
  50. OPCODE(0x81, "ISUB", PasCFakeInstruction, -4, "");
  51. OPCODE(0x82, "IMULT", PasCFakeInstruction, -4, "");
  52. OPCODE(0x83, "IDIV", PasCFakeInstruction, -4, "");
  53. OPCODE(0x84, "IMOD", PasCFakeInstruction, -4, "");
  54. OPCODE(0x85, "ISHL", PasCFakeInstruction, -4, "");
  55. OPCODE(0x86, "ISHR", PasCFakeInstruction, -4, "");
  56. OPCODE(0x87, "ISTOREA [SB]", PasCFakeInstruction, -4, "i");
  57. OPCODE(0x88, "ISTOREL [SB]", PasCFakeInstruction, 0, "ii");
  58. OPCODE(0x89, "ILOADA [SB]", PasCFakeInstruction, 4, "i");
  59. OPCODE(0x8A, "ISTOREA", PasCFakeInstruction, -4, "d");
  60. OPCODE(0x8B, "ISTOREL", PasCFakeInstruction, 0, "di");
  61. OPCODE(0x8C, "ILOADA", PasCFakeInstruction, 4, "d");
  62. OPCODE(0x8D, "ILOADL", PasCFakeInstruction, 0, "i");
  63. OPCODE(0x8E, "ICMP", PasCFakeInstruction, -8, "");
  64. OPCODE(0x8F, "UICMP", PasCFakeInstruction, -8, "");
  65. OPCODE(0x90, "IDUP", PasCFakeInstruction, 4, "");
  66. OPCODE(0x91, "IPRINT", PasCFakeInstruction, -4, "");
  67. OPCODE(0x92, "UIPRINT", PasCFakeInstruction, -4, "");
  68. OPCODE(0x96, "ISTORE [SB]", PasCFakeInstruction, -8, "");
  69. OPCODE(0x97, "ISTORE", PasCFakeInstruction, -8, "");
  70. OPCODE(0x98, "ILOAD [SB]", PasCFakeInstruction, -8, "");
  71. OPCODE(0x99, "ILOAD", PasCFakeInstruction, -8, "");
  72. //16-bit operations
  73. OPCODE(0xA0, "SADD", PasCFakeInstruction, -2, "");
  74. OPCODE(0xA1, "SSUB", PasCFakeInstruction, -2, "");
  75. OPCODE(0xA2, "SMULT", PasCFakeInstruction, -2, "");
  76. OPCODE(0xA3, "SDIV", PasCFakeInstruction, -2, "");
  77. OPCODE(0xA4, "SMOD", PasCFakeInstruction, -2, "");
  78. OPCODE(0xA5, "SSHL", PasCFakeInstruction, -2, "");
  79. OPCODE(0xA6, "SSHR", PasCFakeInstruction, -2, "");
  80. OPCODE(0xA7, "SSTOREA [SB]", PasCFakeInstruction, -2, "i");
  81. OPCODE(0xA8, "SSTOREL [SB]", PasCFakeInstruction, 0, "is");
  82. OPCODE(0xA9, "SLOADA [SB]", PasCFakeInstruction, 2, "i");
  83. OPCODE(0xAA, "SSTOREA", PasCFakeInstruction, -2, "d");
  84. OPCODE(0xAB, "SSTOREL", PasCFakeInstruction, 0, "ds");
  85. OPCODE(0xAC, "SLOADA", PasCFakeInstruction, 2, "d");
  86. OPCODE(0xAD, "SLOADL", PasCFakeInstruction, 0, "s");
  87. OPCODE(0xAE, "SCMP", PasCFakeInstruction, -4, "");
  88. OPCODE(0xAF, "USCMP", PasCFakeInstruction, -4, "");
  89. OPCODE(0xB0, "SDUP", PasCFakeInstruction, 2, "");
  90. OPCODE(0xB1, "SPRINT", PasCFakeInstruction, -2, "");
  91. OPCODE(0xB2, "USPRINT", PasCFakeInstruction, -2, "");
  92. OPCODE(0xB6, "SSTORE [SB]", PasCFakeInstruction, -6, "");
  93. OPCODE(0xB7, "SSTORE", PasCFakeInstruction, -6, "");
  94. OPCODE(0xB8, "SLOAD [SB]", PasCFakeInstruction, -6, "");
  95. OPCODE(0xB9, "SLOAD", PasCFakeInstruction, -6, "");
  96. //8-bit operations
  97. OPCODE(0xC0, "BADD", PasCFakeInstruction, -1, "");
  98. OPCODE(0xC1, "BSUB", PasCFakeInstruction, -1, "");
  99. OPCODE(0xC2, "BMULT", PasCFakeInstruction, -1, "");
  100. OPCODE(0xC3, "BDIV", PasCFakeInstruction, -1, "");
  101. OPCODE(0xC4, "BMOD", PasCFakeInstruction, -1, "");
  102. OPCODE(0xC5, "BSHL", PasCFakeInstruction, -1, "");
  103. OPCODE(0xC6, "BSHR", PasCFakeInstruction, -1, "");
  104. OPCODE(0xC7, "BSTOREA [SB]", PasCFakeInstruction, -1, "i");
  105. OPCODE(0xC8, "BSTOREL [SB]", PasCFakeInstruction, 0, "iB");
  106. OPCODE(0xC9, "BLOADA [SB]", PasCFakeInstruction, 1, "i");
  107. OPCODE(0xCA, "BSTOREA", PasCFakeInstruction, -1, "d");
  108. OPCODE(0xCB, "BSTOREL", PasCFakeInstruction, 0, "dB");
  109. OPCODE(0xCC, "BLOADA", PasCFakeInstruction, 1, "d");
  110. OPCODE(0xCD, "BLOADL", PasCFakeInstruction, 0, "B");
  111. OPCODE(0xCE, "SBCMP", PasCFakeInstruction, -2, "");
  112. OPCODE(0xCF, "BCMP", PasCFakeInstruction, -2, "");
  113. OPCODE(0xD0, "BDUP", PasCFakeInstruction, 1, "");
  114. OPCODE(0xD1, "SBPRINT", PasCFakeInstruction, -1, "");
  115. OPCODE(0xD2, "BPRINT", PasCFakeInstruction, -1, "");
  116. OPCODE(0xD3, "CPRINT", PasCFakeInstruction, -1, "");
  117. OPCODE(0xD6, "BSTORE [SB]", PasCFakeInstruction, -5, "");
  118. OPCODE(0xD7, "BSTORE", PasCFakeInstruction, -5, "");
  119. OPCODE(0xD8, "BLOAD [SB]", PasCFakeInstruction, -5, "");
  120. OPCODE(0xD9, "BLOAD", PasCFakeInstruction, -5, "");
  121. END_OPCODES;
  122. }
  123. ValuePtr PasCDisassembler::readParameter(InstPtr inst, std::string type)
  124. {
  125. ValuePtr retval = NULL;
  126. if (type == "a")
  127. {
  128. retval = new AddressValue(stream_->ReadU32());
  129. address_ += 4;
  130. }
  131. else
  132. {
  133. // Defer handling to parent implementation
  134. retval = SimpleDisassembler::readParameter(inst, type);
  135. }
  136. return retval;
  137. }