Subversion Repositories Kolibri OS

Rev

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