Subversion Repositories Kolibri OS

Rev

Rev 4909 | Rev 4911 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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