Subversion Repositories Kolibri OS

Rev

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

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