Subversion Repositories Kolibri OS

Rev

Rev 4904 | Rev 4906 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.  
  5. macro DrawRectangle x, y, w, h, color
  6. {
  7.         mcall 13, x shl 16 + w,     y shl 16 + 1,     color   ; top
  8.         mcall   , x shl 16 + 1,     y shl 16 + h,     color   ; left
  9.         mcall   , (x+w) shl 16 +1,  y shl 16 + (h+1), color   ; right
  10.         mcall   , x shl 16 + w,   (y+h) shl 16 + 1,   color   ; bottom
  11. }
  12.  
  13. ;-----------------------------------------------------------------------------
  14. ;                             Color scheme
  15.  
  16. BLACK_ON_WHITE  equ 0
  17. MOVIEOS         equ 1
  18. WHITE_ON_BLACK  equ 2
  19.  
  20. ;                         format - 0xRRGGBB
  21. if COLOR_THEME eq MOVIEOS
  22.  
  23.         COLOR_BG_NORMAL           = 0x1d272f
  24.         COLOR_BG_BREAKPOINT       = 0x0000aa
  25.         COLOR_BG_SELECTED         = 0xec9300
  26.         COLOR_LINE                = 0x00b9a0
  27.         COLOR_TXT_NORMAL          = 0xffffff
  28.         COLOR_TXT_INACTIVE        = 0x8f7948
  29.         COLOR_TXT_CHANGED         = 0xec9300
  30.         COLOR_TXT_LABEL           = 0x22b14c
  31.         COLOR_TXT_SELECTED        = 0x1d272f
  32.         COLOR_TXT_HEX             = 0xec9300
  33.         COLOR_TXT_BREAKPOINT      = 0xec9300
  34.  
  35. else if COLOR_THEME eq WHITE_ON_BLACK
  36.  
  37.         COLOR_BG_NORMAL           = 0x101010 ; dark grey
  38.         COLOR_BG_BREAKPOINT       = 0xFF0000 ; red
  39.         COLOR_BG_SELECTED         = 0x0000FF ; blue
  40.         COLOR_LINE                = 0xFFFFFF ; white
  41.         COLOR_TXT_NORMAL          = 0xFFFFFF ; white
  42.         COLOR_TXT_INACTIVE        = 0x808080 ; grey
  43.         COLOR_TXT_CHANGED         = 0x00AA00 ; green
  44.         COLOR_TXT_LABEL           = COLOR_TXT_NORMAL
  45.         COLOR_TXT_SELECTED        = 0xFFFFFF ; white
  46.         COLOR_TXT_HEX             = COLOR_TXT_NORMAL
  47.         COLOR_TXT_BREAKPOINT      = COLOR_TXT_NORMAL
  48.  
  49. else  ; BLACK ON WHITE
  50.  
  51.         COLOR_BG_NORMAL           = 0xffffff ; white
  52.         COLOR_BG_BREAKPOINT       = 0xFF0000 ; red
  53.         COLOR_BG_SELECTED         = 0x0000FF ; blue
  54.         COLOR_LINE                = 0x000000 ; black
  55.         COLOR_TXT_NORMAL          = 0x000000 ; black
  56.         COLOR_TXT_INACTIVE        = 0x808080 ; grey
  57.         COLOR_TXT_CHANGED         = 0x00AA00 ; green
  58.         COLOR_TXT_LABEL           = COLOR_TXT_NORMAL
  59.         COLOR_TXT_SELECTED        = 0xFFFFFF ; white
  60.         COLOR_TXT_HEX             = COLOR_TXT_NORMAL
  61.         COLOR_TXT_BREAKPOINT      = COLOR_TXT_NORMAL
  62.  
  63. end if
  64.  
  65. ;-----------------------------------------------------------------------------
  66.  
  67. data_width      equ 80
  68. data_x_pos      equ 12
  69. data_x_size     equ data_width*6
  70.  
  71. title_x_pos     equ 30
  72. title_y_pos     equ 32
  73. title_y_size    equ 10
  74.  
  75. ;dump_y_pos      equ (registers_y_pos + registers_y_size + 5)
  76. dump_y_pos      equ (title_y_pos + title_y_size)
  77. dump_height     equ 6
  78. dump_y_size     equ (dump_height*10)
  79.  
  80. disasm_y_pos    equ (dump_y_pos + dump_y_size + 4)
  81. disasm_height   equ 18
  82. disasm_y_size   equ (disasm_height*10)
  83.  
  84. messages_width  equ data_width
  85. messages_height equ 8
  86. messages_x_pos  equ data_x_pos
  87. messages_y_pos  equ (disasm_y_pos + disasm_y_size + 4)
  88. messages_x_size equ messages_width*6
  89. messages_y_size equ messages_height*10
  90.  
  91. cmdline_width   equ data_width
  92. cmdline_x_pos   equ data_x_pos
  93. cmdline_y_pos   equ (messages_y_pos + messages_y_size + 4)
  94. cmdline_x_size  equ messages_x_size
  95. cmdline_y_size  equ 10
  96.  
  97. registers_x_pos equ (data_x_pos + messages_x_size + 4)
  98. registers_y_pos equ (title_y_pos + title_y_size - 3)
  99. registers_x_size equ 134
  100. registers_y_size equ (cmdline_y_pos + cmdline_y_size - registers_y_pos+1)
  101.  
  102. wnd_x_size      equ (data_x_pos + messages_x_size + data_x_pos + registers_x_size+3)
  103. wnd_y_size      equ (cmdline_y_pos + cmdline_y_size + data_x_pos)
  104.  
  105. ;-----------------------------------------------------------------------------
  106. ;                          Entry point
  107.  
  108. ; TODO: split all gui part in independent function, move entry point into mtdbg.asm
  109.  
  110. start:
  111.         ; initialize process heap
  112.         mcall   68, 11
  113.  
  114.         push    eax
  115.         fstcw   word [esp]
  116.         or      word [esp], 3 shl 10    ; set round-to-zero mode
  117.         fldcw   word [esp]
  118.         pop     eax
  119.  
  120.         mov     edi, messages
  121.         mov     ecx, messages_width*messages_height
  122.         mov     al, ' '
  123.         rep stosb
  124.         xor     eax, eax
  125.         mov     [messages_pos], eax
  126.         mov     [cmdline_len], eax
  127.         mov     [cmdline_pos], eax
  128.         mov     edi, needzerostart
  129.         mov     ecx, (needzeroend-needzerostart+3)/4
  130.         rep stosd
  131.         mov     esi, begin_str
  132.         call    put_message_nodraw
  133.         ; set event mask - default events and debugging events
  134.         mcall   40, 0x107
  135.         ; set debug messages buffer
  136.         mov     ecx, dbgbufsize
  137.         mov     dword [ecx], 256
  138.         xor     ebx, ebx
  139.         mov     [ecx+4], ebx
  140.         mov     al, 69
  141.         mcall
  142.         mov     esi, i_param
  143.         call    get_arg.skip_spaces
  144.         test    al, al
  145.         jz      dodraw
  146.         push    esi
  147.         call    draw_window
  148.         pop     esi
  149.         call    OnLoadInit
  150.         jmp     waitevent
  151.  
  152. dodraw:
  153.         call    draw_window
  154.  
  155. waitevent:
  156.         mcall   10
  157.         cmp     al, 9
  158.         jz      debugmsg
  159.         dec     eax
  160.         jz      dodraw
  161.         dec     eax
  162.         jz      keypressed
  163.         dec     eax
  164.         jnz     waitevent
  165.         ; button pressed - we have only one button (close)
  166.         mcall   -1
  167.  
  168. ; TODO: split in more independent function
  169. keypressed:
  170.         mov     al, 2
  171.         mcall
  172.         shr     eax, 8
  173.         cmp     al, 8
  174.         jz      .backspace
  175.         cmp     al, 0xB0
  176.         jz      .left
  177.         cmp     al, 0xB3
  178.         jz      .right
  179.         cmp     al, 0x0D
  180.         jz      .enter
  181.         cmp     al, 0xB6
  182.         jz      .del
  183.         cmp     al, 0xB4
  184.         jz      .home
  185.         cmp     al, 0xB5
  186.         jz      .end
  187.         cmp     al, 0xB1
  188.         jz      .down
  189.         cmp     al, 0xB2
  190.         jz      .up
  191.         cmp     ah, 0x41
  192.         jz      F7
  193.         cmp     ah, 0x42
  194.         jz      F8
  195.         cmp     [cmdline_len], cmdline_width
  196.         jae     waitevent
  197.         push    eax
  198.         call    clear_cmdline_end
  199.         pop     eax
  200.         mov     edi, cmdline
  201.         mov     ecx, [cmdline_len]
  202.         add     edi, ecx
  203.         lea     esi, [edi-1]
  204.         sub     ecx, [cmdline_pos]
  205.         std
  206.         rep movsb
  207.         cld
  208.         stosb
  209.         inc     [cmdline_len]
  210.         call    draw_cmdline_end
  211.         inc     [cmdline_pos]
  212.         call    draw_cursor
  213.         jmp     waitevent
  214.  
  215.     .backspace:
  216.         cmp     [cmdline_pos], 0
  217.         jz      waitevent
  218.         dec     [cmdline_pos]
  219.  
  220.     .delchar:
  221.         call    clear_cmdline_end
  222.         mov     edi, [cmdline_pos]
  223.         dec     [cmdline_len]
  224.         mov     ecx, [cmdline_len]
  225.         sub     ecx, edi
  226.         add     edi, cmdline
  227.         lea     esi, [edi+1]
  228.         rep movsb
  229.         call    draw_cmdline_end
  230.         call    draw_cursor
  231.         jmp     waitevent
  232.  
  233.     .del:
  234.         mov     eax, [cmdline_pos]
  235.         cmp     eax, [cmdline_len]
  236.         jae     waitevent
  237.         jmp     .delchar
  238.  
  239.     .left:
  240.         cmp     [cmdline_pos], 0
  241.         jz      waitevent
  242.         call    hide_cursor
  243.         dec     [cmdline_pos]
  244.         call    draw_cursor
  245.         jmp     waitevent
  246.  
  247.     .right:
  248.         mov     eax, [cmdline_pos]
  249.         cmp     eax, [cmdline_len]
  250.         jae     waitevent
  251.         call    hide_cursor
  252.         inc     [cmdline_pos]
  253.         call    draw_cursor
  254.         jmp     waitevent
  255.  
  256.     .home:
  257.         call    hide_cursor
  258.         and     [cmdline_pos], 0
  259.         call    draw_cursor
  260.         jmp     waitevent
  261.  
  262.     .end:
  263.         call    hide_cursor
  264.         mov     eax, [cmdline_len]
  265.         mov     [cmdline_pos], eax
  266.         call    draw_cursor
  267.  
  268.     .up:
  269.     .down:
  270.         jmp     waitevent
  271.  
  272.         ; We also trying to execute previous command, if empty command_line
  273.     .enter:
  274.         mov     ecx, [cmdline_len]
  275.         test    ecx, ecx
  276.         jnz     .exec_cur
  277.         mov     cl, byte [cmdline_prev]
  278.         cmp     cl, 0
  279.         jz      waitevent
  280.  
  281.     .exec_prev:
  282.         mov     esi, cmdline_prev
  283.         jmp     .exec
  284.  
  285.     .exec_cur:
  286.         mov     esi, cmdline
  287.  
  288.     .exec:
  289.         mov     byte [esi+ecx], 0
  290.         and     [cmdline_pos], 0
  291.         push    esi
  292.         call    clear_cmdline_end
  293.         call    draw_cursor
  294.         pop     esi
  295.         and     [cmdline_len], 0
  296.         ; skip leading spaces
  297.         call    get_arg.skip_spaces
  298.         cmp     al, 0
  299.         jz      waitevent
  300.         ; now esi points to command
  301.         push    esi
  302.         mov     esi, prompt
  303.         call    put_message_nodraw
  304.         pop     esi
  305.         push    esi
  306.         call    put_message_nodraw
  307.  
  308. ; TODO: add meaningful name
  309. z1:
  310.         mov     esi, newline
  311.         call    put_message
  312.         pop     esi
  313.         push    esi
  314.         call    get_arg
  315.         mov     [curarg], esi
  316.         pop     edi
  317.         mov     esi, commands
  318.         call    find_cmd
  319.         mov     eax, aUnknownCommand
  320.         jc      .x11
  321.  
  322.         ; check command requirements
  323.         ; flags field:
  324.         ; &1: command may be called without parameters
  325.         ; &2: command may be called with parameters
  326.         ; &4: command may be called without loaded program
  327.         ; &8: command may be called with loaded program
  328.         mov     eax, [esi+8]
  329.         mov     ecx, [curarg]
  330.         cmp     byte [ecx], 0
  331.         jz      .noargs
  332.         test    byte [esi+16], 2
  333.         jz      .x11
  334.         jmp     @f
  335.  
  336.     .noargs:
  337.         test    byte [esi+16], 1
  338.         jz      .x11
  339.  
  340.     @@:
  341.         cmp     [debuggee_pid], 0
  342.         jz      .nodebuggee
  343.         mov     eax, aAlreadyLoaded
  344.         test    byte [esi+16], 8
  345.         jz      .x11
  346.         jmp     .x9
  347.  
  348.     .nodebuggee:
  349.         mov     eax, need_debuggee
  350.         test    byte [esi+16], 4
  351.         jnz     .x9
  352.  
  353.     .x11:
  354.         xchg    esi, eax
  355.         call    put_message
  356.  
  357.         ; store cmdline for repeating
  358.     .x10:
  359.         mov     esi, cmdline
  360.         mov     ecx, [cmdline_len]
  361.  
  362.     @@:
  363.         cmp     ecx, 0
  364.         jle     .we
  365.         mov     al, [esi + ecx]
  366.         mov     [cmdline_prev + ecx], al
  367.         dec     ecx
  368.         jmp     @b
  369.  
  370.     .we:
  371.         mov     [cmdline_len], 0
  372.         jmp     waitevent
  373.  
  374.     .x9:
  375.         call    dword [esi+4]
  376.         jmp     .x10
  377.  
  378. ;-----------------------------------------------------------------------------
  379. ;                            Cmdline handling
  380.  
  381. clear_cmdline_end:
  382.         mov     ebx, [cmdline_pos]
  383.         mov     ecx, [cmdline_len]
  384.         sub     ecx, ebx
  385.         imul    ebx, 6
  386.         imul    ecx, 6
  387.         inc     ecx
  388.         add     ebx, cmdline_x_pos
  389.         shl     ebx, 16
  390.         or      ebx, ecx
  391.         mov     ecx, cmdline_y_pos*10000h + cmdline_y_size
  392.         mov     edx, COLOR_BG_NORMAL
  393.         ; draw container rectangle/box for cmdline
  394.         mcall   13
  395.         ret
  396.  
  397. draw_cmdline:
  398.         xor     ebx, ebx
  399.         jmp     @f
  400.  
  401. ; TODO: make it local
  402. draw_cmdline_end:
  403.         mov     ebx, [cmdline_pos]
  404.  
  405.     @@:
  406.         mov     esi, [cmdline_len]
  407.         sub     esi, ebx
  408.  
  409.         mov     ecx, COLOR_TXT_NORMAL
  410.         lea     edx, [cmdline+ebx]
  411.         imul    ebx, 6
  412.         add     ebx, cmdline_x_pos
  413.         shl     ebx, 16
  414.         or      ebx, cmdline_y_pos+1
  415.         ; draw a text string in the window
  416.         mcall   4
  417.         ret
  418.  
  419. ;-----------------------------------------------------------------------------
  420. ;                        Working with messages
  421. ; in: esi->ASCIIZ message
  422. put_message_nodraw:
  423.         mov     edx, [messages_pos]
  424.  
  425.     .m:
  426.         lea     edi, [messages+edx]
  427.  
  428.     .l:
  429.         lodsb
  430.         cmp     al, 0
  431.         jz      .done
  432.         call    test_scroll
  433.         cmp     al, 10
  434.         jz      .newline
  435.         cmp     al, '%'
  436.         jnz     @f
  437.         cmp     dword [esp], z1
  438.         jnz     .format
  439.  
  440.     @@:
  441.         stosb
  442.         inc     edx
  443.         jmp     .l
  444.  
  445.     .newline:
  446.         push    edx
  447.         mov     ecx, messages_width
  448.         xor     eax, eax
  449.         xchg    eax, edx
  450.         div     ecx
  451.         xchg    eax, edx
  452.         pop     edx
  453.         test    eax, eax
  454.         jz      .m
  455.         sub     edx, eax
  456.         add     edx, ecx
  457.         jmp     .m
  458.  
  459.     .done:
  460.         mov     [messages_pos], edx
  461.         ret
  462.  
  463.         ; at this moment all format specs must be %<digit>X
  464.     .format:
  465.         lodsb   ; get <digit>
  466.         sub     al, '0'
  467.         movzx   ecx, al
  468.         lodsb
  469.         pop     eax
  470.         pop     ebp
  471.         push    eax
  472.         ; write number in ebp with ecx digits
  473.         dec     ecx
  474.         shl     ecx, 2
  475.  
  476.     .writenibble:
  477.         push    ecx
  478.         call    test_scroll
  479.         pop     ecx
  480.         mov     eax, ebp
  481.         shr     eax, cl
  482.         and     al, 0xF
  483.         cmp     al, 10
  484.         sbb     al, 69h
  485.         das
  486.         stosb
  487.         inc     edx
  488.         sub     ecx, 4
  489.         jns     .writenibble
  490.         jmp     .l
  491.  
  492. test_scroll:
  493.         cmp     edx, messages_width*messages_height
  494.         jnz     .ret
  495.         push    esi
  496.         mov     edi, messages
  497.         lea     esi, [edi+messages_width]
  498.         mov     ecx, (messages_height-1)*messages_width/4
  499.         rep movsd
  500.         push    eax
  501.         mov     al, ' '
  502.         push    edi
  503.         push    messages_width
  504.         pop     ecx
  505.         sub     edx, ecx
  506.         rep stosb
  507.         pop     edi
  508.         pop     eax
  509.         pop     esi
  510.  
  511.     .ret:
  512.         ret
  513.  
  514. ;-----------------------------------------------------------------------------
  515.  
  516. put_message:
  517.         call    put_message_nodraw
  518.  
  519. draw_messages:
  520.         ; draw container rectangle/box
  521.         mcall   13, messages_x_pos*10000h+messages_x_size, messages_y_pos*10000h+messages_y_size, COLOR_BG_NORMAL
  522.         mov     edx, messages
  523.         push    messages_width
  524.         pop     esi
  525.         mov     ecx, COLOR_TXT_NORMAL
  526.         mov     ebx, messages_x_pos*10000h+messages_y_pos
  527.  
  528.     @@:
  529.         ; display text string in the window
  530.         mcall   4
  531.         add     edx, esi
  532.         add     ebx, 10
  533.         cmp     edx, messages+messages_width*messages_height
  534.         jb      @b
  535.         ret
  536.  
  537. ;-----------------------------------------------------------------------------
  538. ;                     Show/hide cursor in command line
  539.  
  540. ; TODO: make it cursor.draw and cursor.hide ???
  541. draw_cursor:
  542.         mov     ecx, cmdline_y_pos*10001h+cmdline_y_size-1
  543.         mov     ebx, [cmdline_pos]
  544.         imul    ebx, 6
  545.         add     ebx, cmdline_x_pos
  546.         mov     edx, ebx
  547.         shl     ebx, 16
  548.         or      ebx, edx
  549.         mov     edx, COLOR_TXT_NORMAL
  550.         ; draw line
  551.         mcall   38
  552.         ret
  553.  
  554. hide_cursor:
  555.         mov     ebx, [cmdline_pos]
  556.         imul    ebx, 6
  557.         add     ebx, cmdline_x_pos
  558.         shl     ebx, 16
  559.         inc     ebx
  560.         mov     ecx, cmdline_y_pos*10000h + cmdline_y_size
  561.         mov     edx, COLOR_BG_NORMAL
  562.         ; draw container rectangle/box
  563.         mcall   13
  564.         mov     ebx, [cmdline_pos]
  565.         cmp     ebx, [cmdline_len]
  566.         jae     .ret
  567.         ; setting up text color scheme and attributes
  568.         mov     ecx, COLOR_TXT_NORMAL
  569.         lea     edx, [cmdline+ebx]
  570.         imul    ebx, 6
  571.         add     ebx, cmdline_x_pos
  572.         shl     ebx, 16
  573.         or      ebx, cmdline_y_pos+1
  574.         push    1
  575.         pop     esi
  576.         ; draw text string in the window
  577.         mcall   4
  578.  
  579.     .ret:
  580.         ret
  581.  
  582. ;-----------------------------------------------------------------------------
  583. ;                       Draw program window title
  584.  
  585. ; FIXME: something wrong here
  586. redraw_title:
  587.         ; draw container rectangle/box
  588.         mcall   13, title_x_pos*10000h+data_x_pos+data_x_size-title_x_pos, title_y_pos*10000h+title_y_size, COLOR_BG_NORMAL
  589.  
  590. draw_title:
  591.         mcall   38, (data_x_pos-2)*10000h+title_x_pos-5, (title_y_pos+5)*10001h, COLOR_LINE
  592.         push    NoPrgLoaded_len
  593.         pop     esi
  594.         cmp     [debuggee_pid], 0
  595.         jz      @f
  596.         mov     esi, [prgname_len]
  597.  
  598.     @@:
  599.         imul    ebx, esi, 6
  600.         add     ebx, title_x_pos+4
  601.         shl     ebx, 16
  602.         mov     bx, data_x_pos+data_x_size-10-5-6*7
  603.         cmp     [bSuspended], 0
  604.         jz      @f
  605.         add     ebx, 6
  606.  
  607.     @@:
  608.         ; draw line with COLOR_LINE (in edx)
  609.         mcall
  610.         mov     ebx, (data_x_pos+data_x_size-10+4)*0x10000 + data_x_pos+data_x_size+2
  611.         ; draw line with COLOR_LINE (in edx)
  612.         mcall
  613.         mov     al, 4
  614.         mov     ebx, title_x_pos*10000h+title_y_pos
  615.         ; setting up text color scheme and attributes
  616.         mov     ecx, COLOR_TXT_NORMAL
  617.         mov     edx, NoPrgLoaded_str
  618.         cmp     [debuggee_pid], 0
  619.         jz      @f
  620.         mov     edx, [prgname_ptr]
  621.  
  622.     @@:
  623.         ; draw text string in the window
  624.         mcall
  625.         cmp     [debuggee_pid], 0
  626.         jz      .nodebuggee
  627.         mov     ebx, (data_x_pos+data_x_size-10-6*7)*10000h + title_y_pos
  628.         mov     edx, aRunning
  629.         push    7
  630.         pop     esi
  631.         cmp     [bSuspended], 0
  632.         jz      @f
  633.         add     ebx, 6*10000h
  634.         mov     edx, aPaused
  635.         dec     esi
  636.  
  637.     @@:
  638.         ; draw line with COLOR_LINE (in edx) in one case
  639.         ; and draw text string with color COLOR_TXT_NORMAL (in ecx) in another
  640.         mcall
  641.         ret
  642.  
  643.     .nodebuggee:
  644.         mov     al, 38
  645.         mov     ebx, (data_x_pos+data_x_size-10-6*7-5)*0x10000 + data_x_pos+data_x_size+2
  646.         mov     ecx, (title_y_pos+5)*10001h
  647.         mov     edx, COLOR_LINE
  648.         jmp     @b
  649.  
  650. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  651. ;;;;;;;;;;;;;;;;;;; REGISTERS PANEL ;;;;;;;;;;;;;;;;;;;;;;;;;;
  652. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  653.  
  654. ;-----------------------------------------------------------------------------
  655. ;                      Display common register content
  656.  
  657. ; TODO: add format support (e.g. numerical value, or address offset/pointer)
  658.  
  659. ; in: esi->value, edx->string, ecx = string length, ebx = coord
  660. draw_register:
  661.         push    edx
  662.         push    ecx
  663.         push    esi
  664.         mov     eax, esi
  665.         mov     esi, ecx
  666.  
  667.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  668.         cmp     [debuggee_pid], 0
  669.         jz      .cd
  670.         cmp     [bSuspended], 0
  671.         jz      .cd
  672.  
  673.         mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
  674.         push    edi
  675.         mov     edi, [eax]
  676.         cmp     dword [eax+oldcontext-context], edi
  677.         pop     edi
  678.         jz      .cd
  679.         mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
  680.  
  681.     .cd:
  682.         ; draw a text string in the window
  683.         mcall   4
  684.         imul    esi, 60000h
  685.         lea     edx, [ebx+esi]
  686.         mov     esi, ecx
  687.         pop     ecx
  688.  
  689.         ; draw a number in the window
  690.         mcall   47, 80101h
  691.         lea     ebx, [edx+60000h*18]
  692.         mov     esi, ecx
  693.         pop     ecx
  694.         pop     edx
  695.         add     edx, ecx
  696.         ret
  697.  
  698. ;-----------------------------------------------------------------------------
  699. ;                  Display FPU register (ST0 - ST7) content
  700. ;
  701. ; in: esi->value, edx->string, ecx = string length, ebx = coord
  702. draw_fpu_register:
  703.         push    ebx
  704.         push    edx
  705.         push    ecx
  706.         push    esi
  707.  
  708.         sub     esp, 8
  709.  
  710.         fld     tword [esi]
  711.         fistp   qword [esp]
  712.  
  713.         mov     eax, esi
  714.         mov     esi, ecx
  715.  
  716.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  717.         cmp     [debuggee_pid], 0
  718.         jz      .cd
  719.         cmp     [bSuspended], 0
  720.         jz      .cd
  721.  
  722.         mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
  723.         push    edi
  724.         mov     edi, [eax]
  725.         cmp     dword [eax+oldcontext-context], edi
  726.         pop     edi
  727.         jnz     .scol
  728.         push    edi
  729.         mov     edi, [eax+4]
  730.         cmp     dword [eax+oldcontext-context+4], edi
  731.         pop     edi
  732.         jz      .cd
  733.  
  734.     .scol:
  735.         mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
  736.  
  737.     .cd:
  738.         ; draw a text string in the window
  739.         mcall   4
  740.         imul    esi, 60000h
  741.         lea     edx, [ebx+esi]
  742.         mov     esi, ecx
  743.  
  744.         mov     ecx, esp
  745.  
  746.         ; draw a number in the window
  747.         ; color is the same as for previous text draw function
  748.         ; ebx : [20] show 16 chars set [30] bit - qword
  749.         mcall   47, 40100101h
  750.         add     esp, 8
  751.         pop     ecx
  752.         lea     ebx, [edx+60000h*18]
  753.         mov     esi, ecx
  754.         pop     ecx
  755.         pop     edx
  756.         pop     ebx
  757.         add     edx, ecx
  758.         ret
  759.  
  760. ;-----------------------------------------------------------------------------
  761. ;                  Display FPU register (ST0 - ST7) content
  762. ;
  763. ; in: esi->value, ebx = coord
  764. draw_fpu_register_2:
  765.  
  766. .str_buf  equ esp
  767. .bcd_man  equ esp+32
  768. .bcd_exp  equ esp+32+12
  769. .exp_v    equ esp+32+12+12
  770.  
  771.         sub     esp, 32+12+12+4
  772.  
  773.         mov     eax, 0x20202020
  774.         mov     edi, .str_buf
  775.         stosd
  776.         stosd
  777.         stosd
  778.         stosd
  779.  
  780.         mov     edx, ebp
  781.         shl     edx, 4
  782.  
  783.         movzx   eax, word [_fsw]
  784.         shr     eax, 11
  785.         add     eax, ebp
  786.         and     eax, 7
  787.  
  788.         bt      dword [_ftw], eax
  789.         jc     .A6M
  790.  
  791.         mov     dword [.str_buf],' emp'
  792.         mov     word [.str_buf+4],'ty'
  793.         jmp     .display
  794.  
  795.         mov     cx, [_st0+edx+8]
  796.         and     cx, 0x7FFF              ;clear sign flag
  797.         jz      .A6M
  798.  
  799.         cmp     cx, 0x7FFF
  800.         jne     .decode
  801.  
  802.         mov     dword [.str_buf], ' inv'
  803.         mov     dword [.str_buf+4], 'alid'
  804.         jmp     .display
  805.  
  806. .A6M:
  807.  
  808.         mov     eax, dword [_st0+edx]
  809.         or      eax, dword [_st0+edx+4]
  810.         jnz     .decode
  811.  
  812.         mov     dword [.str_buf], ' 0.0'
  813.         jmp     .display
  814.  
  815. .decode:
  816.  
  817.         fld     tword [_st0+edx]
  818.         fldlg2
  819.         fld     tword [_st0+edx]
  820.         bt      dword [_st0+edx+8], 15  ;check sign flag
  821.         jnc @f
  822.         fabs
  823. @@:
  824.         fyl2x
  825.         frndint
  826.         fist    dword [.exp_v]
  827.         fld     st0
  828.         fbstp   tword [.bcd_exp]
  829.         fldl2t
  830.         fmulp
  831.         fld     st0
  832.         frndint
  833.         fxch
  834.         fsub    st,st1
  835.  
  836.         f2xm1
  837.         fld1
  838.         faddp
  839.         fscale
  840.         fstp    st1
  841.         fdivp
  842.         fimul   dword [_10000000]
  843.         fbstp   tword [.bcd_man]
  844.  
  845.         lea     esi, [.bcd_man-1]
  846.         mov     edi, .str_buf
  847.  
  848.         mov     ecx, 9
  849.         mov     eax, 0x10000
  850.  
  851.         mov     al, [esi+ecx+1]
  852.         cmp     al, 0x80            ; check for sign
  853.         jne     .mantis_2_str
  854.         mov     al, '-'
  855.         stosb
  856.  
  857. .mantis_2_str:
  858.  
  859.         mov     al, [esi+ecx]
  860.         test    al, al
  861.         jnz     @f
  862.  
  863.         bt      eax, 16
  864.         jc      .skip_lb
  865. @@:
  866.         mov     ah, al
  867.         shr     al, 4
  868.         jnz     .write_h
  869.  
  870.         bt      eax, 16
  871.         jc      .skip_hb
  872.  
  873. .write_h:
  874.         add     al, 0x30
  875.         stosb
  876.         btr     eax, 16
  877.         jnc     .skip_hb
  878.         mov     al, '.'
  879.         stosb
  880.  
  881. .skip_hb:
  882.         mov     al, ah
  883.         and     al, 0x0F
  884.         jnz     .write_lb
  885.  
  886.         bt      eax, 16
  887.         jc      .skip_lb
  888.  
  889. .write_lb:
  890.         add     al,0x30
  891.         stosb
  892.         btr     eax, 16
  893.         jnc     .skip_lb
  894.         mov     al, '.'
  895.         stosb
  896.  
  897. .skip_lb:
  898.         loop    .mantis_2_str
  899.  
  900.         mov     eax, [.exp_v]
  901.         test    eax, eax
  902.         jz      .display
  903.  
  904.         mov     ax, ' e'
  905.         stosw
  906.  
  907.         lea     esi, [.bcd_exp-1]
  908.         mov     ecx, 9
  909.         mov     eax,0x10000
  910.         mov     al, [esi+ecx+1]
  911.         cmp     al, 0x80
  912.         jne     .exp_2_str
  913.         mov     al, '-'
  914.         stosb
  915.  
  916. .exp_2_str:
  917.         mov     al, [esi+ecx]
  918.         test    al, al
  919.         jnz     @f
  920.  
  921.         bt      eax, 16
  922.         jc      .skip_lb2
  923. @@:
  924.         mov     ah, al
  925.         shr     al, 4
  926.         jnz     .write_h2
  927.  
  928.         bt      eax, 16
  929.         jc      .skip_hb2
  930.  
  931. .write_h2:
  932.         add     al, 0x30
  933.         stosb
  934.         btr     eax, 16
  935.         stosb
  936.  
  937. .skip_hb2:
  938.  
  939.         mov     al, ah
  940.         and     al, 0x0F
  941.         jnz     .write_lb2
  942.  
  943.         bt      eax, 16
  944.         jc      .skip_lb2
  945.  
  946. .write_lb2:
  947.  
  948.         add     al, 0x30
  949.         stosb
  950.         btr     eax, 16
  951.  
  952. .skip_lb2:
  953.         loop    .exp_2_str
  954.  
  955. .display:
  956.  
  957.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  958.         cmp     [debuggee_pid], 0
  959.         jz      .do_label
  960.         cmp     [bSuspended], 0
  961.         jz      .do_label
  962.  
  963.         mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
  964.  
  965.         mov     eax, dword [_st0+edx]
  966.         cmp     eax, dword [_st0+(oldcontext-context)+edx]
  967.         jne     .scol
  968.  
  969.         mov     eax, dword [_st0+edx+4]
  970.         cmp     eax, dword [_st0+(oldcontext-context)+edx+4]
  971.         jne     .scol
  972.  
  973.         mov     ax, word [_st0+edx+8]
  974.         cmp     ax, word [_st0+(oldcontext-context)+edx+8]
  975.         je      .do_label
  976.  
  977. .scol:
  978.         mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
  979.  
  980. .do_label:
  981.         ; draw a text string in the window
  982.  
  983.         mov     eax, 4
  984.         mov     esi, eax
  985.         lea     edx, [fpu_strs+ebp*4]
  986.         mov     edi, COLOR_BG_NORMAL
  987.         int     0x40
  988.  
  989.         mov     esi, 16
  990.         mov     edx, .str_buf
  991.         add     ebx, 0x180000
  992.         int     0x40
  993.  
  994.         sub     ebx, 0x180000
  995.         add     esp, 32+12+12+4
  996.  
  997.         ret
  998.  
  999.  
  1000. ;-----------------------------------------------------------------------------
  1001. ;                      Show FPU MMX register content
  1002. ;
  1003. ; in: esi->value, edx->string, ecx = string length, ebx = coord
  1004. draw_mmx_register:
  1005.         push    ebx
  1006.         push    edx
  1007.         push    ecx
  1008.         push    esi
  1009.         mov     eax, esi
  1010.         mov     esi, ecx
  1011.  
  1012.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  1013.         cmp     [debuggee_pid], 0
  1014.         jz      .cd
  1015.         cmp     [bSuspended], 0
  1016.         jz      .cd
  1017.  
  1018.         mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
  1019.         push    edi
  1020.         mov     edi, [eax]
  1021.         cmp     dword [eax+oldcontext-context], edi
  1022.         pop     edi
  1023.         jnz     .scol
  1024.         push    edi
  1025.         mov     edi, [eax+4]
  1026.         cmp     dword [eax+oldcontext-context+4], edi
  1027.         pop     edi
  1028.         jz      .cd
  1029.  
  1030.     .scol:
  1031.         mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
  1032.  
  1033.     .cd:
  1034.         ; draw a text string in the window
  1035.         mcall   4
  1036.  
  1037.         imul    esi, 60000h
  1038.         lea     edx, [ebx+esi]
  1039.         mov     esi, ecx
  1040.         pop     ecx
  1041.         ; draw a number in the window
  1042.         ; color is the same as for previous draw text function
  1043.         ; ebx : [20] show 16 chars set [30] bit - qword
  1044.         mcall   47, 40100101h
  1045.         lea     ebx, [edx+60000h*18]
  1046.         mov     esi, ecx
  1047.         pop     ecx
  1048.         pop     edx
  1049.         pop     ebx
  1050.         add     edx, ecx
  1051.         ret
  1052.  
  1053. ; TODO add SSE registers
  1054. ; TODO add AVX registers
  1055.  
  1056. ;-----------------------------------------------------------------------------
  1057. ;                   Display contents of EFLAGS register
  1058. draw_flag:
  1059.         movzx   edi, byte [edx+7]
  1060.         bt      [_eflags], edi
  1061.         jc      .on
  1062.         or      byte [edx], 20h
  1063.         jmp     .onoff
  1064.  
  1065.     .on:
  1066.         and     byte [edx], not 20h
  1067.  
  1068.     .onoff:
  1069.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  1070.         cmp     [debuggee_pid], 0
  1071.         jz      .doit
  1072.         cmp     [bSuspended], 0
  1073.         jz      .doit
  1074.  
  1075.         mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
  1076.         bt      [_eflags], edi
  1077.         lahf
  1078.         bt      dword [_eflags + oldcontext - context], edi
  1079.         rcl     ah, 1
  1080.         test    ah, 3
  1081.         jp      .doit
  1082.         mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
  1083.  
  1084.     .doit:
  1085.         mov     ah, 0
  1086.         mov     edi, COLOR_BG_NORMAL
  1087.         ; draw a text string in the window in one case
  1088.         ; and a number in another
  1089.         ; color scheme same as for previously called function (was in ecx)
  1090.         mcall
  1091.         ret
  1092.  
  1093. ;-----------------------------------------------------------------------------
  1094. ;                      Draw registers frame title
  1095.  
  1096. ; Also show current register set (common + MMX, SSE or AVX)
  1097. draw_reg_title:
  1098.         mov     edi, COLOR_BG_NORMAL
  1099.         mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
  1100.         mov     esi, 7
  1101.         cmp     [reg_mode], REG_MODE_CPU
  1102.         jz      @f
  1103.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  1104.     @@:
  1105.         mov     edx, aMain
  1106.         ; draw a text string in the window
  1107.         mcall   4, (registers_x_pos+4)*10000h+registers_y_pos+2
  1108.  
  1109.         cmp     [reg_mode], REG_MODE_SSE
  1110.         jz      @f
  1111.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  1112.     @@:
  1113.         mov     edx, aSSE
  1114.         ; draw a text string in the window
  1115.         mcall   4, (registers_x_pos+46)*10000h+registers_y_pos+2
  1116.  
  1117.         cmp     [reg_mode], REG_MODE_AVX
  1118.         jz      @f
  1119.         mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
  1120.     @@:
  1121.         mov     edx, aAVX
  1122.         ; draw a text string in the window
  1123.         mcall   4, (registers_x_pos+88)*10000h+registers_y_pos+2
  1124.         ret
  1125.  
  1126. ;-----------------------------------------------------------------------------
  1127. ;                Display common registers set + MMX + FPU
  1128.  
  1129. draw_main_registers:
  1130. ; TODO: add support for FPU ST0-ST7 registers
  1131.         mov     edi, COLOR_BG_NORMAL
  1132.         mov     esi, _eax
  1133.         push    4
  1134.         pop     ecx
  1135.         mov     edx, regs_strs
  1136.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+22
  1137.         call    draw_register
  1138.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+32
  1139.         add     esi, _ebx-_eax
  1140.         call    draw_register
  1141.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+42
  1142.         add     esi, _ecx-_ebx
  1143.         call    draw_register
  1144.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+52
  1145.         add     esi, _edx-_ecx
  1146.         call    draw_register
  1147.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+62
  1148.         add     esi, _esi-_edx
  1149.         call    draw_register
  1150.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+72
  1151.         add     esi, _edi-_esi
  1152.         call    draw_register
  1153.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+82
  1154.         add     esi, _ebp-_edi
  1155.         call    draw_register
  1156.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+92
  1157.         add     esi, _esp-_ebp
  1158.         call    draw_register
  1159.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+102
  1160.         add     esi, _eip-_esp
  1161.         call    draw_register
  1162.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+112
  1163.  
  1164.         mov     cl, 7
  1165.         add     esi, _eflags-_eip
  1166.         call    draw_register
  1167.         mov     cl, 4
  1168.  
  1169.     ; MMX registers
  1170.  
  1171.         push    ebp
  1172.  
  1173.         push    8
  1174.         mov     edx, mmx_strs
  1175.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+142
  1176.         mov     esi, _mm0
  1177.  
  1178. align 4
  1179. .draw_mmx_regs:
  1180.  
  1181.         call    draw_mmx_register
  1182.         add     ebx, 10
  1183.         add     esi, 16
  1184.         dec     dword [esp]
  1185.         jnz     .draw_mmx_regs
  1186.  
  1187. ;FPU registers
  1188.  
  1189.         ;int3
  1190.         nop
  1191.  
  1192.         mov     [esp], byte 8
  1193.         xor     ebp, ebp
  1194.         mov     ebx, (registers_x_pos+2)*10000h+registers_y_pos+232
  1195.  
  1196. align 4
  1197. .draw_fpu_regs:
  1198.  
  1199.         call    draw_fpu_register_2
  1200.         add     ebx, 10
  1201.         inc     ebp
  1202.         dec     dword [esp]
  1203.         jnz     .draw_fpu_regs
  1204.         pop     eax                         ;restore stack
  1205.         pop     ebp
  1206.  
  1207.         mov     ecx, COLOR_TXT_INACTIVE
  1208.         cmp     [debuggee_pid], 0
  1209.         jz      @f
  1210.         cmp     [bSuspended], 0
  1211.         jz      @f
  1212.         mov     ecx, COLOR_TXT_NORMAL
  1213.     @@:
  1214.         mov     edx, aColon
  1215.         xor     esi, esi
  1216.         inc     esi
  1217.         mcall   4, (registers_x_pos+10)*10000h+registers_y_pos+122
  1218.         mov     edx, flags
  1219.  
  1220.     @@:
  1221.         add     ebx, 2*6*10000h
  1222.         call    draw_flag
  1223.         inc     edx
  1224.         cmp     dl, flags_bits and 0xFF
  1225.         jnz     @b
  1226.         ret
  1227.  
  1228. ;-----------------------------------------------------------------------------
  1229. ;                  Draw SSE registers set
  1230.  
  1231. draw_sse_registers:
  1232.  
  1233.         ret
  1234.  
  1235. ;-----------------------------------------------------------------------------
  1236. ;                  Draw AVX registers set
  1237.  
  1238. draw_avx_registers:
  1239.  
  1240.         ret
  1241.  
  1242. ;-----------------------------------------------------------------------------
  1243. ;                 Draw all registers sets
  1244. draw_registers:
  1245.  
  1246.         ; draw container rectangle/box with COLOR_BG_NORMAL
  1247.         mcall   13, (registers_x_pos-1)*10000h+(registers_x_size+2), (registers_y_pos-1)*10000h+(registers_y_size+2), COLOR_BG_NORMAL
  1248.         call    draw_reg_title
  1249.  
  1250.     .redraw:
  1251.         cmp     [reg_mode], REG_MODE_CPU
  1252.         jnz     @f
  1253.         call    draw_main_registers
  1254.         ret
  1255.  
  1256.     @@:
  1257.         cmp     [reg_mode], REG_MODE_SSE
  1258.         jnz     @f
  1259.         call    draw_sse_registers
  1260.         ret
  1261.  
  1262.     @@:
  1263.         call    draw_avx_registers
  1264.         ret
  1265.  
  1266. ;-----------------------------------------------------------------------------
  1267. ;                     Display memory dump
  1268.  
  1269. draw_dump:
  1270.         ; draw container rectangle/box in the window
  1271.         mcall   13, data_x_pos*10000h+data_x_size, dump_y_pos*10000h+dump_y_size, COLOR_BG_NORMAL
  1272.  
  1273.     .redraw:
  1274.         ; addresses
  1275.         mov     ebx, 80100h
  1276.         mov     edx, data_x_pos*10000h + dump_y_pos
  1277.         mov     ecx, [dumppos]
  1278.         mov     edi, COLOR_BG_NORMAL
  1279.         mov     esi, (COLOR_TXT_INACTIVE or 0x40000000)
  1280.         cmp     [debuggee_pid], 0
  1281.         jz      @f
  1282.         cmp     [bSuspended], 0
  1283.         jz      @f
  1284.         mov     esi, (COLOR_TXT_NORMAL or 0x40000000)
  1285.     @@:
  1286.         ; draw a number in the window
  1287.         mcall   47
  1288.         add     ecx, 10h
  1289.         add     edx, 10
  1290.         cmp     dl, dump_y_pos + dump_y_size
  1291.         jb      @b
  1292.         ; hex dump of data
  1293.         mov     ecx, dumpdata
  1294.         push    ecx
  1295.         xor     ebx, ebx
  1296.         mov     edx, (data_x_pos+12*6)*10000h + dump_y_pos
  1297.         cmp     [dumpread], ebx
  1298.         jz      .hexdumpdone1
  1299.  
  1300.     .hexdumploop1:
  1301.         push    ebx
  1302.         mov     ebx, 20101h
  1303.         ; draw a number in the window
  1304.         mcall
  1305.         pop     ebx
  1306.         add     edx, 3*6*10000h
  1307.         inc     ecx
  1308.         inc     ebx
  1309.         test    bl, 15
  1310.         jz      .16
  1311.         test    bl, 7
  1312.         jnz     @f
  1313.         add     edx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
  1314.  
  1315.     .16:
  1316.         add     edx, 10 - 6*(3*10h+2)*10000h
  1317.  
  1318.     @@:
  1319.         cmp     ebx, [dumpread]
  1320.         jb      .hexdumploop1
  1321.  
  1322.     .hexdumpdone1:
  1323.         mov     al, 4
  1324.         ; copy color value from esi to ecx
  1325.         ; to draw text string with 'mcall 4'
  1326.         mov     ecx, esi
  1327.         xchg    ebx, edx
  1328.         push    2
  1329.         pop     esi
  1330.  
  1331.     .hexdumploop2:
  1332.         cmp     edx, dump_height*10h
  1333.         jae     .hexdumpdone2
  1334.         push    edx
  1335.         mov     edx, aQuests
  1336.         ; draw text string with color in ecx, copied from esi
  1337.         mcall
  1338.         pop     edx
  1339.         add     ebx, 3*6*10000h
  1340.         inc     edx
  1341.         test    dl, 15
  1342.         jz      .16x
  1343.         test    dl, 7
  1344.         jnz     .hexdumploop2
  1345.         add     ebx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
  1346.  
  1347.     .16x:
  1348.         add     ebx, 10 - 6*(3*10h+2)*10000h
  1349.         jmp     .hexdumploop2
  1350.  
  1351.     .hexdumpdone2:
  1352.         dec     esi
  1353.         ; colon, minus signs
  1354.         mov     ebx, (data_x_pos+8*6)*10000h + dump_y_pos
  1355.         mov     edx, aColon
  1356.  
  1357.     @@:
  1358.         mcall
  1359.         add     ebx, 10
  1360.         cmp     bl, dump_y_pos+dump_height*10
  1361.         jb      @b
  1362.         mov     ebx, (data_x_pos+(12+3*8)*6)*10000h + dump_y_pos
  1363.         mov     edx, aMinus
  1364.  
  1365.     @@:
  1366.         mcall
  1367.         add     ebx, 10
  1368.         cmp     bl, dump_y_pos+dump_height*10
  1369.         jb      @b
  1370.         ; ASCII data
  1371.         mov     ebx, (data_x_pos+(12+3*10h+2+2)*6)*10000h + dump_y_pos
  1372.         pop     edx
  1373.         push    dump_height*10h
  1374.  
  1375.     .asciiloop:
  1376.         push    edx
  1377.         cmp     byte [edx], 20h
  1378.         jae     @f
  1379.         mov     edx, aPoint
  1380.  
  1381.     @@:
  1382.         ; draw a text string in the window, color in ecx
  1383.         mcall
  1384.         pop     edx
  1385.         inc     edx
  1386.         add     ebx, 6*10000h
  1387.         dec     dword [esp]
  1388.         jz      .asciidone
  1389.         test    byte [esp], 15
  1390.         jnz     .asciiloop
  1391.         add     ebx, 10 - 6*10h*10000h
  1392.         jmp     .asciiloop
  1393.  
  1394.     .asciidone:
  1395.         pop     ecx
  1396.         ret
  1397.  
  1398. ;-----------------------------------------------------------------------------
  1399. ;                   Display disassembled code
  1400.  
  1401. draw_disasm:
  1402.  
  1403.         mov     eax, [disasm_start_pos]
  1404.         mov     [disasm_cur_pos], eax
  1405.         and     [disasm_cur_str], 0
  1406.  
  1407.     .loop:
  1408.         mov     eax, [disasm_cur_pos]
  1409.         call    find_symbol
  1410.         jc      .nosymb
  1411.         mov     ebx, [disasm_cur_str]
  1412.         imul    ebx, 10
  1413.         push    ebx
  1414.         lea     ecx, [ebx+disasm_y_pos-1]
  1415.         shl     ecx, 16
  1416.         mov     cl, 11
  1417.         ; setting up background color for disassembled text
  1418.         mov     edx, COLOR_BG_NORMAL
  1419.         ; draw container rectangle/box with color COLOR_BG_NORMAL (was 0xFFFFFF - white)
  1420.         mcall   13, data_x_pos*10000h+data_x_size
  1421.         pop     ebx
  1422.         ; copy color value from edx (COLOR_BG_NORMAL)
  1423.         mov     edi, edx
  1424.         add     ebx, (data_x_pos+6*2)*10000h+disasm_y_pos
  1425.         mov     edx, esi
  1426.  
  1427.     @@:
  1428.         lodsb
  1429.         test    al, al
  1430.         jnz     @b
  1431.         mov     byte [esi-1], ':'
  1432.         sub     esi, edx
  1433.         ; normal color
  1434.         ; was 0x40000000
  1435.         mov     ecx, (COLOR_TXT_LABEL or 0x40000000)
  1436.         mov     al, 4
  1437.         ; draw a text string in the window with color COLOR_TXT_NORMAL in ecx
  1438.         mcall
  1439.         mov     byte [esi+edx-1], 0
  1440.         lea     esi, [esi*3]
  1441.         movzx   ecx, bx
  1442.         shr     ebx, 16
  1443.         lea     ebx, [ebx+esi*2]
  1444.         shl     ecx, 16
  1445.         mov     cl, 10
  1446.         imul    ebx, 10001h
  1447.         sub     bx, data_x_pos+data_x_size
  1448.         neg     bx
  1449.         mov     al, 13
  1450.         ; copy color value from edi
  1451.         mov     edx, edi
  1452.         ; draw container rectangle/box for disassembled text, color in edx
  1453.         mcall
  1454.         inc     [disasm_cur_str]
  1455.         cmp     [disasm_cur_str], disasm_height
  1456.         jae     .loopend
  1457.  
  1458.     .nosymb:
  1459.         push    [disasm_cur_pos]
  1460.         call    disasm_instr
  1461.         pop     ebp
  1462.         jc      .loopend
  1463.         mov     edx, COLOR_BG_NORMAL
  1464.         mov     esi, COLOR_TXT_NORMAL
  1465.         mov     ebx, data_x_pos*10000h + data_x_size
  1466.         mov     ecx, [disasm_cur_str]
  1467.         imul    ecx, 10*10000h
  1468.         add     ecx, (disasm_y_pos-1)*10000h + 10
  1469.         mov     eax, ebp
  1470.         pushad
  1471.         call    find_enabled_breakpoint
  1472.         popad
  1473.         jnz     .nobp
  1474.         mov     edx, COLOR_BG_BREAKPOINT
  1475.         mov     esi, COLOR_TXT_BREAKPOINT
  1476.     .nobp:
  1477.  
  1478.         mov     eax, [_eip]
  1479.         cmp     eax, ebp
  1480.         jnz     .notcurrent
  1481.         mov     edx, COLOR_BG_SELECTED
  1482.         mov     esi, COLOR_TXT_SELECTED
  1483.     .notcurrent:
  1484.         push    esi     ; Save color value for disassembled text
  1485.  
  1486.         ; draw container rectangle/box for disassembled text
  1487.         ; color in edx
  1488.         mcall   13
  1489.  
  1490.         mov     edx, [disasm_cur_str]
  1491.         imul    edx, 10
  1492.         add     edx, data_x_pos*10000h + disasm_y_pos
  1493.         ; draw a number in the window, color in esi
  1494.         mcall   47, 80100h, ebp
  1495.  
  1496.         lea     ebx, [edx+8*6*10000h]
  1497.         mov     ecx, esi    ; text color
  1498.         push    2
  1499.         pop     esi
  1500.         mov     edx, aColon
  1501.         ; draw the colon
  1502.         mcall   4
  1503.         push    9
  1504.         pop     edi
  1505.         lea     edx, [ebx+2*6*10000h]
  1506.         mov     ecx, ebp
  1507.         sub     ecx, [disasm_start_pos]
  1508.         add     ecx, disasm_buffer
  1509.  
  1510.         mov     esi, COLOR_TXT_HEX
  1511.         mov     eax, [_eip]
  1512.         cmp     eax, ebp
  1513.         jnz     @f
  1514.         mov     esi, COLOR_TXT_SELECTED
  1515.   @@:
  1516.     .drawhex:
  1517.         ; draw a number in the window, color in esi
  1518.         mcall   47, 20101h
  1519.         add     edx, 6*3*10000h
  1520.         inc     ecx
  1521.         inc     ebp
  1522.         cmp     ebp, [disasm_cur_pos]
  1523.         jae     .hexdone
  1524.         dec     edi
  1525.         jnz     .drawhex
  1526.         push    esi
  1527.         mov     esi, [disasm_cur_pos]
  1528.         dec     esi
  1529.         cmp     esi, ebp
  1530.         pop     esi
  1531.         jbe     .drawhex
  1532.  
  1533.         lea     ebx, [edx-6*10000h]
  1534.         ; copy color value from esi
  1535.         mov     ecx, esi
  1536.         push    3
  1537.         pop     esi
  1538.         mov     edx, aDots
  1539.         ; draw a text string in the window, color in ecx
  1540.         mcall   4
  1541.  
  1542.     .hexdone:
  1543.         pop     esi
  1544.         xor     eax, eax
  1545.         mov     edi, disasm_string
  1546.         mov     edx, edi
  1547.         or      ecx, -1
  1548.         repnz scasb
  1549.         not     ecx
  1550.         dec     ecx
  1551.         xchg    ecx, esi
  1552.         mov     ebx, [disasm_cur_str]
  1553.         imul    ebx, 10
  1554.         add     ebx, (data_x_pos+6*40)*10000h+disasm_y_pos
  1555.  
  1556.         ; draw a text string in the window, color in ecx
  1557.         mcall   4
  1558.         inc     [disasm_cur_str]
  1559.         cmp     [disasm_cur_str], disasm_height
  1560.         jb      .loop
  1561.  
  1562.     .loopend:
  1563.         mov     ecx, disasm_height
  1564.         sub     ecx, [disasm_cur_str]
  1565.         jz      @f
  1566.         imul    ecx, 10
  1567.         inc     ecx
  1568.         mov     eax, disasm_y_pos + disasm_y_size
  1569.         sub     eax, ecx
  1570.         shl     eax, 16
  1571.         add     ecx, eax
  1572.         ; Draw filled rectangle
  1573.         mcall   13, data_x_pos*10000h+data_x_size, , COLOR_BG_NORMAL
  1574.  
  1575.     @@:
  1576.         ret
  1577.  
  1578. ;-----------------------------------------------------------------------------
  1579.  
  1580. ; TODO: cleanup of this function, make some global labels local
  1581. update_disasm_eip:
  1582. ; test if instruction at eip is showed
  1583.         mov     ecx, disasm_height
  1584.         mov     eax, [disasm_start_pos]
  1585.         mov     [disasm_cur_pos], eax
  1586.  
  1587.     .l:
  1588.         mov     eax, [disasm_cur_pos]
  1589.         call    find_symbol
  1590.         jc      @f
  1591.         dec     ecx
  1592.         jz      .m
  1593.  
  1594.     @@:
  1595.         cmp     [_eip], eax
  1596.         jz      draw_disasm
  1597.         push    ecx
  1598.         call    disasm_instr
  1599.         pop     ecx
  1600.         jc      .m
  1601.         loop    .l
  1602.  
  1603.     .m:
  1604.  
  1605. update_disasm_eip_force:
  1606.         mov     eax, [_eip]
  1607.         mov     [disasm_start_pos], eax
  1608.  
  1609. update_disasm:
  1610.         cmp     [debuggee_pid], 0
  1611.         jz      .no
  1612.  
  1613.         mcall   69, 6, [debuggee_pid], 256, [disasm_start_pos], disasm_buffer
  1614.         cmp     eax, -1
  1615.         jnz     @f
  1616.         mov     esi, read_mem_err
  1617.         call    put_message
  1618.  
  1619.     .no:
  1620.         xor     eax, eax
  1621.  
  1622.     @@:
  1623.         mov     [disasm_buf_size], eax
  1624.         call    restore_from_breaks
  1625.         jmp     draw_disasm
  1626.  
  1627.  
  1628. ;-----------------------------------------------------------------------------
  1629. ;                               Draw main window
  1630.  
  1631. draw_window:
  1632.         ; start window redraw
  1633.         mcall   12, 1
  1634.  
  1635.         ; define window
  1636.         mcall   0, wnd_x_size, wnd_y_size, (COLOR_BG_NORMAL or 0x54000000), , caption_str
  1637.  
  1638.         ; clear unused areas
  1639.         ; get window skin height
  1640.         mcall   48, 4
  1641.         cmp     eax, title_y_pos
  1642.         jb      @f
  1643.         push    registers_y_pos
  1644.         pop     eax
  1645.  
  1646.     @@:
  1647.         push    registers_y_pos
  1648.         pop     ecx
  1649.         push    eax
  1650.         sub     ecx, eax
  1651.         shl     eax, 16
  1652.         add     ecx, eax
  1653.         mov     ebx, 5*10000h + (wnd_x_size-9)
  1654.         mov     edx, COLOR_BG_NORMAL
  1655.         ; draw container rectangle/box for registers information region
  1656.         mcall   13
  1657.         mov     ecx, (dump_y_pos+dump_y_size)*10000h + (disasm_y_pos-dump_y_pos-dump_y_size)
  1658.         ; draw container rectangle/box for dump memory region
  1659.         mcall
  1660.         mov     ecx, (disasm_y_pos-1+disasm_y_size)*10000h + (messages_y_pos-disasm_y_pos+1-disasm_y_size)
  1661.         ; draw container rectangle/box for disassembled code region
  1662.         mcall
  1663.         mov     ecx, (messages_y_pos+messages_y_size)*10000h + (wnd_y_size-messages_y_pos-messages_y_size-4)
  1664.         ; draw container rectangle/box for messages window region
  1665.         mcall
  1666.         mov     ebx, 5*10000h + (data_x_pos-5)
  1667.         pop     ecx
  1668.         imul    ecx, 10001h
  1669.         sub     cx, wnd_y_size-4
  1670.         neg     cx
  1671.         ; draw container rectangle/box
  1672.         mcall
  1673.         mov     ebx, (data_x_pos+data_x_size)*10000h + (wnd_x_size-data_x_pos-data_x_size-4)
  1674.         ; draw container rectangle/box
  1675.         mcall
  1676.         mov     ebx, 5*10000h + title_x_pos - 5
  1677.         mov     ecx, (title_y_pos)*10000h + (title_y_size)
  1678.         ; draw container rectangle/box for dump memory region title
  1679.         mcall
  1680.  
  1681.         ; messages frame
  1682.         mov     ebx, (messages_x_pos-2)*10000h + (messages_x_pos+messages_x_size+2)
  1683.         push    ebx
  1684.         mov     ecx, (messages_y_pos-2)*10001h
  1685.         mov     edx, COLOR_LINE
  1686.         mcall   38
  1687.         mov     ecx, (messages_y_pos+messages_y_size+2)*10001h
  1688.         mcall
  1689.         mov     ebx, (messages_x_pos-2)*10001h
  1690.         push    ebx
  1691.         mov     ecx, (messages_y_pos-2)*10000h + (messages_y_pos+messages_y_size+2)
  1692.         mcall
  1693.         mov     ebx, (messages_x_pos+messages_x_size+2)*10001h
  1694.         push    ebx
  1695.         mcall
  1696.  
  1697.         ; command line frame
  1698.         mov     ecx, (cmdline_y_pos-2)*10000h + (cmdline_y_pos+cmdline_y_size+2)
  1699.         pop     ebx
  1700.         mcall
  1701.         pop     ebx
  1702.         mcall
  1703.         pop     ebx
  1704.         mov     ecx, (cmdline_y_pos+cmdline_y_size+2)*10001h
  1705.         mcall
  1706.         mov     ecx, (cmdline_y_pos-2)*10001h
  1707.         mcall
  1708.  
  1709.         ; registers frame
  1710.         DrawRectangle (registers_x_pos-2), (registers_y_pos-2), (registers_x_size+3), (registers_y_size+3), COLOR_LINE
  1711.         ; draw container rectangle/box for registers information window region
  1712.  
  1713.         ; messages
  1714.         call    draw_messages
  1715.  
  1716.         ; command line & cursor
  1717.         call    draw_cmdline
  1718.         call    draw_cursor
  1719.  
  1720.         ; title & registers & dump & disasm
  1721.         mov     ebx, (data_x_pos-2)*10001h
  1722.         mov     ecx, (title_y_pos+5)*10000h + (messages_y_pos-2)
  1723.         mov     edx, COLOR_LINE
  1724.         mcall   38
  1725.         mov     ebx, (data_x_pos+data_x_size+2)*10001h
  1726.         mcall
  1727.         mov     ebx, (data_x_pos-2)*10000h + (data_x_pos+data_x_size+2)
  1728.         mov     ecx, (disasm_y_pos-4)*10001h
  1729.         mcall
  1730.  
  1731.         ; redraw whole window again
  1732.         call    redraw_title
  1733.         call    draw_registers
  1734.         call    draw_dump
  1735.         call    draw_disasm
  1736.  
  1737.         ; end of window redraw
  1738.         mcall   12, 2
  1739.         ret
  1740.  
  1741. ; vim: ft=fasm tabstop=4
  1742.  
  1743.