register_display.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "register_display.h"
  16. /* Display all 16 registers
  17. * - Toggle between Common mode and Specific mode
  18. * (Common: Display all as R0 - R15)
  19. * (Specific: Display Register usages like PC, SR, etc.)
  20. */
  21. void display_registers(Emulator *emu)
  22. {
  23. Cpu *cpu = emu->cpu;
  24. Debugger *debugger = emu->debugger;
  25. typedef enum {UNDEF, LINUX, WINDOWS} System_t;
  26. System_t this_system;
  27. uint16_t r2 = sr_to_value(emu);
  28. char full[1000] = {0};
  29. #ifdef __linux
  30. this_system = LINUX;
  31. #else
  32. this_system = UNDEF;
  33. #endif
  34. char *v_flag, *n_flag, *z_flag, *c_flag;
  35. char *red, *green, *cyan, *clear, *blue, *white, *yellow;
  36. char *reg_col, *spec_reg_col, *decor_col, *value_col;
  37. const char *r0_name = "PC";
  38. const char *r1_name = "SP";
  39. const char *r2_name = "SR";
  40. const char *r3_name = "CG2";
  41. const char *r4_name = "R4";
  42. const char *r5_name = "R5";
  43. const char *r6_name = "R6";
  44. const char *r7_name = "R7";
  45. const char *r8_name = "R8";
  46. const char *r9_name = "R9";
  47. const char *r10_name = "R10";
  48. const char *r11_name = "R11";
  49. const char *r12_name = "R12";
  50. const char *r13_name = "R13";
  51. const char *r14_name = "R14";
  52. const char *r15_name = "R15";
  53. if (debugger->console_interface) {
  54. red = (char*)"\x1b[31;1m";
  55. green = (char*)"\x1b[32;1m";
  56. cyan = (char*)"\x1b[36;1m";
  57. blue = (char*)"\x1b[34;1m";
  58. white = (char*)"\x1b[37;1m";
  59. yellow = (char*)"\x1b[33;1m";
  60. clear = (char*)"";
  61. reg_col = blue;
  62. value_col = white;
  63. spec_reg_col = red;
  64. decor_col = green;
  65. v_flag = (char*)"V\x1b[0m";
  66. n_flag = (char*)"\x1b[36;1mN\x1b[0m";
  67. z_flag = (char*)"\x1b[36;1mZ\x1b[0m";
  68. c_flag = (char*)"\x1b[36;1mC\x1b[0m";
  69. }
  70. else {
  71. red = (char*)"";
  72. green = (char*)"";
  73. cyan = (char*)"";
  74. blue = (char*)"";
  75. white = (char*)"";
  76. yellow = (char*)"";
  77. clear = (char*)"";
  78. reg_col = (char*)"";
  79. value_col = (char*)"";
  80. spec_reg_col = (char*)"";
  81. decor_col = (char*)"";
  82. v_flag = (char*)"V";
  83. n_flag = (char*)"N";
  84. z_flag = (char*)"Z";
  85. c_flag = (char*)"C";
  86. }
  87. sprintf(full,
  88. "\n%s%s%s: %s%04X "\
  89. "%s%s%s: %s%04X " \
  90. "%s%s%s: %s%04X "\
  91. "%s%s%s: %s%04X "\
  92. "%s%s%s: %s%d\n"\
  93. "%s%%%s%s%s: %s%04X "\
  94. "%s%%%s%s%s: %s%04X "\
  95. "%s%%%s%s%s: %s%04X "\
  96. "%s%%%s%s%s: %s%04X "\
  97. "%s%s%s: %s%d\n"\
  98. "%s%%%s%s%s: %s%04X "\
  99. "%s%%%s%s%s: %s%04X "\
  100. "%s%%%s%s%s: %s%04X "\
  101. "%s%%%s%s%s: %s%04X "\
  102. "%s%s%s: %s%d\n"\
  103. "%s%%%s%s%s: %s%04X "\
  104. "%s%%%s%s%s: %s%04X "\
  105. "%s%%%s%s%s: %s%04X "\
  106. "%s%%%s%s%s: %s%04X "\
  107. "%s%s%s: %s%d\n\n",
  108. red, r0_name, decor_col, value_col, (uint16_t)cpu->pc,
  109. red, r1_name, decor_col, value_col, (uint16_t)cpu->sp,
  110. red, r2_name, decor_col, value_col, (uint16_t)r2,
  111. red, r3_name, decor_col, value_col, (uint16_t)cpu->cg2,
  112. cyan, c_flag, decor_col, value_col, cpu->sr.carry,
  113. decor_col, reg_col, r4_name, decor_col, value_col, (uint16_t)cpu->r4,
  114. decor_col, reg_col, r5_name, decor_col, value_col, (uint16_t)cpu->r5,
  115. decor_col, reg_col, r6_name, decor_col, value_col, (uint16_t)cpu->r6,
  116. decor_col, reg_col, r7_name, decor_col, value_col, (uint16_t)cpu->r7,
  117. cyan, z_flag, decor_col, value_col, cpu->sr.zero,
  118. decor_col, reg_col, r8_name, decor_col,value_col, (uint16_t)cpu->r8,
  119. decor_col, reg_col, r9_name, decor_col,value_col, (uint16_t)cpu->r9,
  120. decor_col, reg_col, r10_name, decor_col,value_col,(uint16_t)cpu->r10,
  121. decor_col, reg_col, r11_name, decor_col,value_col,(uint16_t)cpu->r11,
  122. cyan, n_flag, decor_col, value_col, cpu->sr.negative,
  123. decor_col, reg_col, r12_name, decor_col,value_col,(uint16_t)cpu->r12,
  124. decor_col, reg_col, r13_name, decor_col,value_col,(uint16_t)cpu->r13,
  125. decor_col, reg_col, r14_name, decor_col,value_col,(uint16_t)cpu->r14,
  126. decor_col, reg_col, r15_name, decor_col,value_col,(uint16_t)cpu->r15,
  127. cyan, v_flag, decor_col, value_col, cpu->sr.overflow);
  128. printf("%s", full);
  129. print_console(emu, full);
  130. }