disassembler.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. MSP430 Emulator
  3. Copyright (C) 2020 Rudolf Geosits (rgeosits@live.esu.edu)
  4. "MSP430 Emulator" is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. "MSP430 Emulator" is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "disassembler.h"
  16. void disassemble(Emulator *emu, uint16_t start_addr, uint8_t times)
  17. {
  18. Cpu *cpu = emu->cpu;
  19. Debugger *debugger = emu->debugger;
  20. uint16_t saved_pc = cpu->pc, opcode;
  21. uint32_t i;
  22. debugger->disassemble_mode = true;
  23. cpu->pc = start_addr;
  24. for (i = 0;i < times;i++)
  25. {
  26. char addr_str[32] = {0};
  27. sprintf(addr_str, "0x%04X:\t", cpu->pc);
  28. printf("%s", addr_str);
  29. if (debugger->web_interface)
  30. print_console(emu, addr_str);
  31. opcode = fetch(emu);
  32. decode(emu, opcode, DISASSEMBLE);
  33. }
  34. debugger->disassemble_mode = false;
  35. cpu->pc = saved_pc; // Restore PC
  36. }