dis_asm.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*******************************************************************************
  2. * Emu51
  3. * dis_asm.cpp:
  4. * Created by mlt on 22/03/23.
  5. ******************************************************************************/
  6. #include <emu51.h>
  7. #include <code_51.h>
  8. #include <dis_asm.h>
  9. dis_asm::dis_asm(uint8_t *tmpB, BITMAP *tmp_buf)
  10. {
  11. frame = 2;
  12. left = 12;
  13. changed = true;
  14. ram = tmpB;
  15. buf = tmp_buf;
  16. surface = create_bitmap(300, 500);
  17. clear(surface);
  18. }
  19. void dis_asm::hexoutB(int x, int y, int color, uint8_t numb)
  20. {
  21. if ( numb > 0x10 )
  22. {
  23. textprintf(surface, mainf, x, y, color, "%2x", numb);
  24. }
  25. else
  26. {
  27. textprintf(surface, mainf, x, y, color, "%2x", numb);
  28. textprintf(surface, mainf, x, y, color, "0");
  29. }
  30. }
  31. void dis_asm::draw(uint16_t adress)
  32. {
  33. int red = makecol(255, 0, 0);
  34. int white = makecol(255, 255, 255);
  35. int lblue = makecol(0, 128, 255);
  36. int color = white;
  37. int colPC = white;
  38. int c, cnt;
  39. clear(surface);
  40. for ( c = 20 ; c < surface->h - 10 ; c += 10 )
  41. {
  42. if ( PC == adress )
  43. {
  44. color = red;
  45. }
  46. else
  47. {
  48. color = white;
  49. }
  50. asm51[ram[adress]].make_ds(adress);
  51. if ( asm51[ram[adress]].code == ram[adress] )
  52. {
  53. textprintf(surface, mainf, left, c, color, "%4x:", adress);
  54. for ( cnt = 0 ; cnt < asm51[ram[adress]].length ; cnt++ )
  55. {
  56. if ( PC == ( adress + cnt ))
  57. {
  58. colPC = lblue;
  59. }
  60. else
  61. {
  62. colPC = color;
  63. }
  64. hexoutB(left + 50 + cnt * 24, c, colPC, ram[adress + cnt]);
  65. }
  66. textprintf(surface, mainf, left + 144, c, color, "%s", asm51[ram[adress]].display_string);
  67. adress += asm51[ram[adress]].length;
  68. }
  69. else
  70. {
  71. textprintf(surface, mainf, left, c, color, "%4x: ", adress);
  72. if ( PC == adress )
  73. {
  74. colPC = lblue;
  75. }
  76. else
  77. {
  78. colPC = color;
  79. }
  80. hexoutB(left + 50, c, colPC, ram[adress]);
  81. textprintf(surface, mainf, left + 144, c, color, "???");
  82. adress++;
  83. }
  84. }
  85. hline(surface, frame, surface->h - frame, surface->w - frame, white);
  86. vline(surface, frame, frame, surface->h - frame, white);
  87. vline(surface, surface->w - frame, frame, surface->h - frame, white);
  88. for ( c = frame ; c <= frame + 10 ; c += 2 )
  89. {
  90. hline(surface, frame, c, surface->w - frame, white);
  91. }
  92. textprintf_centre(surface, mainf, surface->w / 2, frame + 2, white, " Disassembler ");
  93. }
  94. void dis_asm::blit_it(int x, int y)
  95. {
  96. blit(surface, buf, 0, 0, x, y, surface->w, surface->h);
  97. }
  98. dis_asm::~dis_asm(void)
  99. {
  100. }