Subversion Repositories Kolibri OS

Rev

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