Subversion Repositories Kolibri OS

Rev

Rev 4910 | Rev 4912 | 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
4901 Serge 926
 
4900 Serge 927
.skip_hb2:
4901 Serge 928
 
4900 Serge 929
        mov     al, ah
930
        and     al, 0x0F
931
        jnz     .write_lb2
932
 
933
        bt      eax, 16
934
        jc      .skip_lb2
4901 Serge 935
 
4900 Serge 936
.write_lb2:
4901 Serge 937
 
4900 Serge 938
        add     al, 0x30
939
        stosb
940
        btr     eax, 16
4901 Serge 941
 
4900 Serge 942
.skip_lb2:
4901 Serge 943
        loop    .exp_2_str
4900 Serge 944
 
4901 Serge 945
.display:
946
 
4900 Serge 947
        mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
948
        cmp     [debuggee_pid], 0
949
        jz      .do_label
950
        cmp     [bSuspended], 0
951
        jz      .do_label
952
 
953
        mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
954
 
955
        mov     eax, dword [_st0+edx]
956
        cmp     eax, dword [_st0+(oldcontext-context)+edx]
957
        jne     .scol
958
 
959
        mov     eax, dword [_st0+edx+4]
4904 Serge 960
        cmp     eax, dword [_st0+(oldcontext-context)+edx+4]
4900 Serge 961
        jne     .scol
962
 
963
        mov     ax, word [_st0+edx+8]
4903 Serge 964
        cmp     ax, word [_st0+(oldcontext-context)+edx+8]
4900 Serge 965
        je      .do_label
966
 
967
.scol:
968
        mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
969
 
970
.do_label:
971
        ; draw a text string in the window
972
 
973
        mov     eax, 4
974
        mov     esi, eax
975
        lea     edx, [fpu_strs+ebp*4]
976
        mov     edi, COLOR_BG_NORMAL
977
        int     0x40
978
 
979
        mov     esi, 16
980
        mov     edx, .str_buf
981
        add     ebx, 0x180000
982
        int     0x40
983
 
984
        sub     ebx, 0x180000
4910 Serge 985
        add     esp, 32+12+12+4+4
4900 Serge 986
 
987
        ret
988
 
989
 
990
;-----------------------------------------------------------------------------
4591 hidnplayr 991
;                      Show FPU MMX register content
992
;
4906 Serge 993
; in: ebp index, ebx = coord
4890 hidnplayr 994
 
4906 Serge 995
draw_mmx_register_2:
996
 
997
        shl     ebp, 4
998
 
4591 hidnplayr 999
        mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
1000
        cmp     [debuggee_pid], 0
1001
        jz      .cd
1002
        cmp     [bSuspended], 0
1003
        jz      .cd
4890 hidnplayr 1004
 
4591 hidnplayr 1005
        mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
1006
 
4906 Serge 1007
        mov     eax, dword [_mm0+ebp]
1008
        cmp     eax, dword [_mm0+(oldcontext-context)+ebp]
1009
        jne     .scol
1010
 
1011
        mov     eax, dword [_mm0+ebp+4]
1012
        cmp     eax, dword [_mm0+(oldcontext-context)+ebp+4]
1013
        je     .cd
1014
 
1015
.scol:
4591 hidnplayr 1016
        mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
4906 Serge 1017
.cd:
1018
        mov     eax, ebp
1019
        shl     eax, 16-4
1020
        add     eax, 'MM0='
1021
        push    eax                           ;write label into stack
4591 hidnplayr 1022
 
1023
        ; draw a text string in the window
4890 hidnplayr 1024
 
4906 Serge 1025
        mov     eax, 4
1026
        mov     esi, eax
1027
        mov     edx, esp
1028
        mov     edi, COLOR_BG_NORMAL
1029
        int     0x40
1030
 
4591 hidnplayr 1031
        mov     esi, ecx
4906 Serge 1032
        mov     [esp], ebx
1033
 
1034
        mov     ecx, dword [_mm0+ebp+4]
1035
        rol     ecx, 16
1036
        lea     edx, [ebx+0x180000]
1037
        mov     ebx, 0x00040100
1038
        mcall   47                        ;word #3
1039
 
1040
        shr     ecx, 16
1041
        add     edx, (4*6+3) shl 16
1042
        mcall   47                        ;word #2
1043
 
1044
        mov     ecx, dword [_mm0+ebp]
1045
        rol     ecx, 16
1046
        add     edx, (4*6+3) shl 16
1047
        mcall   47                        ;word #1
1048
 
1049
        shr     ecx, 16
1050
        add     edx, (4*6+3) shl 16
1051
        mcall   47                        ;word #0
1052
 
4895 Serge 1053
        pop     ebx
4906 Serge 1054
 
1055
        shr     ebp, 4
4591 hidnplayr 1056
        ret
1057
 
1058
; TODO add SSE registers
1059
; TODO add AVX registers
1060
 
1061
;-----------------------------------------------------------------------------
1062
;                   Display contents of EFLAGS register
1063
draw_flag:
1064
        movzx   edi, byte [edx+7]
1065
        bt      [_eflags], edi
1066
        jc      .on
1067
        or      byte [edx], 20h
1068
        jmp     .onoff
1069
 
1070
    .on:
1071
        and     byte [edx], not 20h
1072
 
1073
    .onoff:
1074
        mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
1075
        cmp     [debuggee_pid], 0
1076
        jz      .doit
1077
        cmp     [bSuspended], 0
1078
        jz      .doit
4890 hidnplayr 1079
 
4591 hidnplayr 1080
        mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
1081
        bt      [_eflags], edi
1082
        lahf
1083
        bt      dword [_eflags + oldcontext - context], edi
1084
        rcl     ah, 1
1085
        test    ah, 3
1086
        jp      .doit
1087
        mov     ecx, (COLOR_TXT_CHANGED or 0x40000000)
1088
 
1089
    .doit:
1090
        mov     ah, 0
1091
        mov     edi, COLOR_BG_NORMAL
1092
        ; draw a text string in the window in one case
1093
        ; and a number in another
1094
        ; color scheme same as for previously called function (was in ecx)
1095
        mcall
1096
        ret
1097
 
1098
;-----------------------------------------------------------------------------
1099
;                      Draw registers frame title
1100
 
1101
; Also show current register set (common + MMX, SSE or AVX)
1102
draw_reg_title:
1103
        mov     edi, COLOR_BG_NORMAL
1104
        mov     ecx, (COLOR_TXT_NORMAL or 0x40000000)
1105
        mov     esi, 7
1106
        cmp     [reg_mode], REG_MODE_CPU
1107
        jz      @f
1108
        mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
1109
    @@:
1110
        mov     edx, aMain
1111
        ; draw a text string in the window
4908 hidnplayr 1112
        mov     ebx, [registers_x_pos_dd]
1113
        add     ebx, 4*10000h+registers_y_pos+2
1114
        mcall   4
4888 hidnplayr 1115
 
4591 hidnplayr 1116
        cmp     [reg_mode], REG_MODE_SSE
1117
        jz      @f
1118
        mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
1119
    @@:
1120
        mov     edx, aSSE
1121
        ; draw a text string in the window
4908 hidnplayr 1122
        mov     ebx, [registers_x_pos_dd]
1123
        add     ebx, 46*10000h+registers_y_pos+2
1124
        mcall   4
4888 hidnplayr 1125
 
4591 hidnplayr 1126
        cmp     [reg_mode], REG_MODE_AVX
1127
        jz      @f
1128
        mov     ecx, (COLOR_TXT_INACTIVE or 0x40000000)
1129
    @@:
1130
        mov     edx, aAVX
1131
        ; draw a text string in the window
4908 hidnplayr 1132
        mov     ebx, [registers_x_pos_dd]
1133
        add     ebx, 88*10000h+registers_y_pos+2
1134
        mcall   4
4591 hidnplayr 1135
        ret
1136
 
1137
;-----------------------------------------------------------------------------
1138
;                Display common registers set + MMX + FPU
1139
 
1140
draw_main_registers:
4888 hidnplayr 1141
; TODO: add support for FPU ST0-ST7 registers
4591 hidnplayr 1142
        mov     edi, COLOR_BG_NORMAL
1143
        mov     esi, _eax
1144
        push    4
1145
        pop     ecx
1146
        mov     edx, regs_strs
4908 hidnplayr 1147
        mov     ebx, [registers_x_pos_dd]
1148
        add     ebx, 2*10000h+registers_y_pos+22
4591 hidnplayr 1149
        call    draw_register
4908 hidnplayr 1150
        mov     ebx, [registers_x_pos_dd]
1151
        add     ebx, 2*10000h+registers_y_pos+32
4591 hidnplayr 1152
        add     esi, _ebx-_eax
1153
        call    draw_register
4908 hidnplayr 1154
        mov     ebx, [registers_x_pos_dd]
1155
        add     ebx, 2*10000h+registers_y_pos+42
4591 hidnplayr 1156
        add     esi, _ecx-_ebx
1157
        call    draw_register
4908 hidnplayr 1158
        mov     ebx, [registers_x_pos_dd]
1159
        add     ebx, 2*10000h+registers_y_pos+52
4591 hidnplayr 1160
        add     esi, _edx-_ecx
1161
        call    draw_register
4908 hidnplayr 1162
        mov     ebx, [registers_x_pos_dd]
1163
        add     ebx, 2*10000h+registers_y_pos+62
4591 hidnplayr 1164
        add     esi, _esi-_edx
1165
        call    draw_register
4908 hidnplayr 1166
        mov     ebx, [registers_x_pos_dd]
1167
        add     ebx, 2*10000h+registers_y_pos+72
4591 hidnplayr 1168
        add     esi, _edi-_esi
1169
        call    draw_register
4908 hidnplayr 1170
        mov     ebx, [registers_x_pos_dd]
1171
        add     ebx, 2*10000h+registers_y_pos+82
4591 hidnplayr 1172
        add     esi, _ebp-_edi
1173
        call    draw_register
4908 hidnplayr 1174
        mov     ebx, [registers_x_pos_dd]
1175
        add     ebx, 2*10000h+registers_y_pos+92
4591 hidnplayr 1176
        add     esi, _esp-_ebp
1177
        call    draw_register
4908 hidnplayr 1178
        mov     ebx, [registers_x_pos_dd]
1179
        add     ebx, 2*10000h+registers_y_pos+102
4591 hidnplayr 1180
        add     esi, _eip-_esp
1181
        call    draw_register
4908 hidnplayr 1182
        mov     ebx, [registers_x_pos_dd]
1183
        add     ebx, 2*10000h+registers_y_pos+112
4895 Serge 1184
 
4591 hidnplayr 1185
        mov     cl, 7
1186
        add     esi, _eflags-_eip
1187
        call    draw_register
4895 Serge 1188
        mov     cl, 4
4591 hidnplayr 1189
 
1190
    ; MMX registers
4895 Serge 1191
 
4900 Serge 1192
        push    ebp
1193
 
4895 Serge 1194
        push    8
4906 Serge 1195
        xor     ebp, ebp
4908 hidnplayr 1196
        mov     ebx, [registers_x_pos_dd]
1197
        add     ebx, 2*10000h+registers_y_pos+142
4895 Serge 1198
 
1199
align 4
1200
.draw_mmx_regs:
1201
 
4906 Serge 1202
        call    draw_mmx_register_2
4895 Serge 1203
        add     ebx, 10
4906 Serge 1204
        inc     ebp
4895 Serge 1205
        dec     dword [esp]
1206
        jnz     .draw_mmx_regs
4890 hidnplayr 1207
 
4895 Serge 1208
;FPU registers
1209
 
4900 Serge 1210
        ;int3
4906 Serge 1211
        ;nop
4900 Serge 1212
 
4895 Serge 1213
        mov     [esp], byte 8
4900 Serge 1214
        xor     ebp, ebp
4908 hidnplayr 1215
        mov     ebx, [registers_x_pos_dd]
1216
        add     ebx, 2*10000h+registers_y_pos+232
4895 Serge 1217
 
1218
align 4
1219
.draw_fpu_regs:
1220
 
4900 Serge 1221
        call    draw_fpu_register_2
4895 Serge 1222
        add     ebx, 10
4900 Serge 1223
        inc     ebp
4895 Serge 1224
        dec     dword [esp]
1225
        jnz     .draw_fpu_regs
1226
        pop     eax                         ;restore stack
4900 Serge 1227
        pop     ebp
4895 Serge 1228
 
4591 hidnplayr 1229
        mov     ecx, COLOR_TXT_INACTIVE
1230
        cmp     [debuggee_pid], 0
1231
        jz      @f
1232
        cmp     [bSuspended], 0
1233
        jz      @f
4889 hidnplayr 1234
        mov     ecx, COLOR_TXT_NORMAL
4591 hidnplayr 1235
    @@:
1236
        mov     edx, aColon
1237
        xor     esi, esi
1238
        inc     esi
4908 hidnplayr 1239
        mov     ebx, [registers_x_pos_dd]
1240
        add     ebx, 10*10000h+registers_y_pos+122
1241
        mcall   4
4591 hidnplayr 1242
        mov     edx, flags
1243
 
1244
    @@:
1245
        add     ebx, 2*6*10000h
1246
        call    draw_flag
1247
        inc     edx
1248
        cmp     dl, flags_bits and 0xFF
1249
        jnz     @b
1250
        ret
1251
 
1252
;-----------------------------------------------------------------------------
1253
;                  Draw SSE registers set
1254
 
1255
draw_sse_registers:
4888 hidnplayr 1256
 
4591 hidnplayr 1257
        ret
1258
 
1259
;-----------------------------------------------------------------------------
1260
;                  Draw AVX registers set
1261
 
1262
draw_avx_registers:
4888 hidnplayr 1263
 
4591 hidnplayr 1264
        ret
1265
 
1266
;-----------------------------------------------------------------------------
1267
;                 Draw all registers sets
1268
draw_registers:
4888 hidnplayr 1269
 
1270
        ; draw container rectangle/box with COLOR_BG_NORMAL
4908 hidnplayr 1271
        mov     ebx, [registers_x_pos_dd]
1272
        add     ebx, (-1)*10000h+(registers_x_size+2)
1273
        mov     ecx, [registers_y_size_dd+4]
1274
        add     ecx, (registers_y_pos-1)*10000h+2
1275
        mcall   13, , , COLOR_BG_NORMAL
4591 hidnplayr 1276
        call    draw_reg_title
4888 hidnplayr 1277
 
1278
    .redraw:
4591 hidnplayr 1279
        cmp     [reg_mode], REG_MODE_CPU
1280
        jnz     @f
1281
        call    draw_main_registers
1282
        ret
1283
 
1284
    @@:
1285
        cmp     [reg_mode], REG_MODE_SSE
1286
        jnz     @f
1287
        call    draw_sse_registers
1288
        ret
1289
 
1290
    @@:
1291
        call    draw_avx_registers
1292
        ret
1293
 
1294
;-----------------------------------------------------------------------------
1295
;                     Display memory dump
1296
 
1297
draw_dump:
1298
        ; draw container rectangle/box in the window
4908 hidnplayr 1299
        mov     ebx, [data_x_size_dd+4]
1300
        add     ebx, data_x_pos*10000h
1301
        mcall   13, , dump_y_pos*10000h+dump_y_size, COLOR_BG_NORMAL
4591 hidnplayr 1302
 
1303
    .redraw:
4888 hidnplayr 1304
        ; addresses
4591 hidnplayr 1305
        mov     ebx, 80100h
1306
        mov     edx, data_x_pos*10000h + dump_y_pos
1307
        mov     ecx, [dumppos]
1308
        mov     edi, COLOR_BG_NORMAL
1309
        mov     esi, (COLOR_TXT_INACTIVE or 0x40000000)
1310
        cmp     [debuggee_pid], 0
1311
        jz      @f
1312
        cmp     [bSuspended], 0
1313
        jz      @f
1314
        mov     esi, (COLOR_TXT_NORMAL or 0x40000000)
1315
    @@:
4888 hidnplayr 1316
        ; draw a number in the window
4591 hidnplayr 1317
        mcall   47
1318
        add     ecx, 10h
1319
        add     edx, 10
1320
        cmp     dl, dump_y_pos + dump_y_size
1321
        jb      @b
4888 hidnplayr 1322
        ; hex dump of data
4591 hidnplayr 1323
        mov     ecx, dumpdata
1324
        push    ecx
1325
        xor     ebx, ebx
1326
        mov     edx, (data_x_pos+12*6)*10000h + dump_y_pos
1327
        cmp     [dumpread], ebx
1328
        jz      .hexdumpdone1
1329
 
1330
    .hexdumploop1:
1331
        push    ebx
1332
        mov     ebx, 20101h
4888 hidnplayr 1333
        ; draw a number in the window
4591 hidnplayr 1334
        mcall
1335
        pop     ebx
1336
        add     edx, 3*6*10000h
1337
        inc     ecx
1338
        inc     ebx
1339
        test    bl, 15
1340
        jz      .16
1341
        test    bl, 7
1342
        jnz     @f
1343
        add     edx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
1344
 
1345
    .16:
1346
        add     edx, 10 - 6*(3*10h+2)*10000h
1347
 
1348
    @@:
1349
        cmp     ebx, [dumpread]
1350
        jb      .hexdumploop1
1351
 
1352
    .hexdumpdone1:
1353
        mov     al, 4
1354
        ; copy color value from esi to ecx
1355
        ; to draw text string with 'mcall 4'
1356
        mov     ecx, esi
1357
        xchg    ebx, edx
1358
        push    2
1359
        pop     esi
1360
 
1361
    .hexdumploop2:
1362
        cmp     edx, dump_height*10h
1363
        jae     .hexdumpdone2
1364
        push    edx
1365
        mov     edx, aQuests
1366
        ; draw text string with color in ecx, copied from esi
1367
        mcall
1368
        pop     edx
1369
        add     ebx, 3*6*10000h
1370
        inc     edx
1371
        test    dl, 15
1372
        jz      .16x
1373
        test    dl, 7
1374
        jnz     .hexdumploop2
1375
        add     ebx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
1376
 
1377
    .16x:
1378
        add     ebx, 10 - 6*(3*10h+2)*10000h
1379
        jmp     .hexdumploop2
1380
 
1381
    .hexdumpdone2:
1382
        dec     esi
4890 hidnplayr 1383
        ; colon, minus signs
4591 hidnplayr 1384
        mov     ebx, (data_x_pos+8*6)*10000h + dump_y_pos
1385
        mov     edx, aColon
1386
 
1387
    @@:
1388
        mcall
1389
        add     ebx, 10
1390
        cmp     bl, dump_y_pos+dump_height*10
1391
        jb      @b
1392
        mov     ebx, (data_x_pos+(12+3*8)*6)*10000h + dump_y_pos
1393
        mov     edx, aMinus
1394
 
1395
    @@:
1396
        mcall
1397
        add     ebx, 10
1398
        cmp     bl, dump_y_pos+dump_height*10
1399
        jb      @b
4890 hidnplayr 1400
        ; ASCII data
4591 hidnplayr 1401
        mov     ebx, (data_x_pos+(12+3*10h+2+2)*6)*10000h + dump_y_pos
1402
        pop     edx
1403
        push    dump_height*10h
1404
 
1405
    .asciiloop:
1406
        push    edx
1407
        cmp     byte [edx], 20h
1408
        jae     @f
1409
        mov     edx, aPoint
1410
 
1411
    @@:
1412
        ; draw a text string in the window, color in ecx
1413
        mcall
1414
        pop     edx
1415
        inc     edx
1416
        add     ebx, 6*10000h
1417
        dec     dword [esp]
1418
        jz      .asciidone
1419
        test    byte [esp], 15
1420
        jnz     .asciiloop
1421
        add     ebx, 10 - 6*10h*10000h
1422
        jmp     .asciiloop
1423
 
1424
    .asciidone:
1425
        pop     ecx
1426
        ret
1427
 
1428
;-----------------------------------------------------------------------------
1429
;                   Display disassembled code
1430
 
1431
draw_disasm:
1432
 
1433
        mov     eax, [disasm_start_pos]
1434
        mov     [disasm_cur_pos], eax
1435
        and     [disasm_cur_str], 0
1436
 
1437
    .loop:
1438
        mov     eax, [disasm_cur_pos]
1439
        call    find_symbol
1440
        jc      .nosymb
1441
        mov     ebx, [disasm_cur_str]
1442
        imul    ebx, 10
1443
        push    ebx
1444
        lea     ecx, [ebx+disasm_y_pos-1]
1445
        shl     ecx, 16
1446
        mov     cl, 11
1447
        ; setting up background color for disassembled text
1448
        mov     edx, COLOR_BG_NORMAL
1449
        ; draw container rectangle/box with color COLOR_BG_NORMAL (was 0xFFFFFF - white)
4908 hidnplayr 1450
        mov     ebx, [data_x_size_dd+4]
1451
        add     ebx, data_x_pos*10000h
1452
        mcall   13
4591 hidnplayr 1453
        pop     ebx
1454
        ; copy color value from edx (COLOR_BG_NORMAL)
1455
        mov     edi, edx
1456
        add     ebx, (data_x_pos+6*2)*10000h+disasm_y_pos
1457
        mov     edx, esi
1458
 
1459
    @@:
1460
        lodsb
1461
        test    al, al
1462
        jnz     @b
1463
        mov     byte [esi-1], ':'
1464
        sub     esi, edx
1465
        ; normal color
1466
        ; was 0x40000000
4886 hidnplayr 1467
        mov     ecx, (COLOR_TXT_LABEL or 0x40000000)
4591 hidnplayr 1468
        mov     al, 4
1469
        ; draw a text string in the window with color COLOR_TXT_NORMAL in ecx
1470
        mcall
1471
        mov     byte [esi+edx-1], 0
1472
        lea     esi, [esi*3]
1473
        movzx   ecx, bx
1474
        shr     ebx, 16
1475
        lea     ebx, [ebx+esi*2]
1476
        shl     ecx, 16
1477
        mov     cl, 10
1478
        imul    ebx, 10001h
4908 hidnplayr 1479
        sub     bx, data_x_pos
1480
        sub     bx, word[data_x_size_dd+4]
4591 hidnplayr 1481
        neg     bx
1482
        mov     al, 13
1483
        ; copy color value from edi
1484
        mov     edx, edi
1485
        ; draw container rectangle/box for disassembled text, color in edx
1486
        mcall
1487
        inc     [disasm_cur_str]
4908 hidnplayr 1488
        mov     eax, [disasm_height_dd]
1489
        cmp     [disasm_cur_str], eax
4591 hidnplayr 1490
        jae     .loopend
1491
 
1492
    .nosymb:
1493
        push    [disasm_cur_pos]
1494
        call    disasm_instr
1495
        pop     ebp
1496
        jc      .loopend
4886 hidnplayr 1497
        mov     edx, COLOR_BG_NORMAL
4591 hidnplayr 1498
        mov     esi, COLOR_TXT_NORMAL
4908 hidnplayr 1499
        mov     ebx, data_x_pos*10000h
1500
        add     ebx, [data_x_size_dd+4]
4591 hidnplayr 1501
        mov     ecx, [disasm_cur_str]
1502
        imul    ecx, 10*10000h
1503
        add     ecx, (disasm_y_pos-1)*10000h + 10
1504
        mov     eax, ebp
1505
        pushad
1506
        call    find_enabled_breakpoint
1507
        popad
4886 hidnplayr 1508
        jnz     .nobp
4591 hidnplayr 1509
        mov     edx, COLOR_BG_BREAKPOINT
4886 hidnplayr 1510
        mov     esi, COLOR_TXT_BREAKPOINT
1511
    .nobp:
4591 hidnplayr 1512
 
1513
        mov     eax, [_eip]
1514
        cmp     eax, ebp
4886 hidnplayr 1515
        jnz     .notcurrent
4591 hidnplayr 1516
        mov     edx, COLOR_BG_SELECTED
1517
        mov     esi, COLOR_TXT_SELECTED
4886 hidnplayr 1518
    .notcurrent:
1519
        push    esi     ; Save color value for disassembled text
4591 hidnplayr 1520
 
1521
        ; draw container rectangle/box for disassembled text
1522
        ; color in edx
1523
        mcall   13
4890 hidnplayr 1524
 
4591 hidnplayr 1525
        mov     edx, [disasm_cur_str]
1526
        imul    edx, 10
1527
        add     edx, data_x_pos*10000h + disasm_y_pos
1528
        ; draw a number in the window, color in esi
1529
        mcall   47, 80100h, ebp
4890 hidnplayr 1530
 
4591 hidnplayr 1531
        lea     ebx, [edx+8*6*10000h]
4886 hidnplayr 1532
        mov     ecx, esi    ; text color
4591 hidnplayr 1533
        push    2
1534
        pop     esi
1535
        mov     edx, aColon
4886 hidnplayr 1536
        ; draw the colon
4591 hidnplayr 1537
        mcall   4
1538
        push    9
1539
        pop     edi
1540
        lea     edx, [ebx+2*6*10000h]
1541
        mov     ecx, ebp
1542
        sub     ecx, [disasm_start_pos]
1543
        add     ecx, disasm_buffer
1544
 
4888 hidnplayr 1545
        mov     esi, COLOR_TXT_HEX
4886 hidnplayr 1546
        mov     eax, [_eip]
1547
        cmp     eax, ebp
1548
        jnz     @f
1549
        mov     esi, COLOR_TXT_SELECTED
1550
  @@:
4591 hidnplayr 1551
    .drawhex:
1552
        ; draw a number in the window, color in esi
1553
        mcall   47, 20101h
1554
        add     edx, 6*3*10000h
1555
        inc     ecx
1556
        inc     ebp
1557
        cmp     ebp, [disasm_cur_pos]
1558
        jae     .hexdone
1559
        dec     edi
1560
        jnz     .drawhex
1561
        push    esi
1562
        mov     esi, [disasm_cur_pos]
1563
        dec     esi
1564
        cmp     esi, ebp
1565
        pop     esi
1566
        jbe     .drawhex
4890 hidnplayr 1567
 
4591 hidnplayr 1568
        lea     ebx, [edx-6*10000h]
1569
        ; copy color value from esi
1570
        mov     ecx, esi
1571
        push    3
1572
        pop     esi
1573
        mov     edx, aDots
1574
        ; draw a text string in the window, color in ecx
1575
        mcall   4
1576
 
1577
    .hexdone:
4886 hidnplayr 1578
        pop     esi
4591 hidnplayr 1579
        xor     eax, eax
1580
        mov     edi, disasm_string
1581
        mov     edx, edi
1582
        or      ecx, -1
1583
        repnz scasb
1584
        not     ecx
1585
        dec     ecx
1586
        xchg    ecx, esi
1587
        mov     ebx, [disasm_cur_str]
1588
        imul    ebx, 10
1589
        add     ebx, (data_x_pos+6*40)*10000h+disasm_y_pos
4890 hidnplayr 1590
 
4591 hidnplayr 1591
        ; draw a text string in the window, color in ecx
1592
        mcall   4
1593
        inc     [disasm_cur_str]
4908 hidnplayr 1594
        mov     eax, [disasm_height_dd]
1595
        cmp     [disasm_cur_str], eax
4591 hidnplayr 1596
        jb      .loop
1597
 
1598
    .loopend:
4908 hidnplayr 1599
        mov     ecx, [disasm_height_dd]
4591 hidnplayr 1600
        sub     ecx, [disasm_cur_str]
1601
        jz      @f
1602
        imul    ecx, 10
1603
        inc     ecx
4908 hidnplayr 1604
        mov     eax, disasm_y_pos
1605
        add     eax, [disasm_y_size_dd+4]
4591 hidnplayr 1606
        sub     eax, ecx
1607
        shl     eax, 16
1608
        add     ecx, eax
4890 hidnplayr 1609
        ; Draw filled rectangle
4908 hidnplayr 1610
        mov     ebx, [data_x_size_dd+4]
1611
        add     ebx, data_x_pos*10000h
1612
        mcall   13, , , COLOR_BG_NORMAL
4591 hidnplayr 1613
 
1614
    @@:
1615
        ret
1616
 
1617
;-----------------------------------------------------------------------------
1618
 
1619
; TODO: cleanup of this function, make some global labels local
1620
update_disasm_eip:
1621
; test if instruction at eip is showed
4908 hidnplayr 1622
        mov     ecx, [disasm_height_dd+4]
4591 hidnplayr 1623
        mov     eax, [disasm_start_pos]
1624
        mov     [disasm_cur_pos], eax
1625
 
1626
    .l:
1627
        mov     eax, [disasm_cur_pos]
1628
        call    find_symbol
1629
        jc      @f
1630
        dec     ecx
1631
        jz      .m
1632
 
1633
    @@:
1634
        cmp     [_eip], eax
4890 hidnplayr 1635
        jz      draw_disasm
4591 hidnplayr 1636
        push    ecx
1637
        call    disasm_instr
1638
        pop     ecx
1639
        jc      .m
1640
        loop    .l
1641
 
1642
    .m:
1643
 
1644
update_disasm_eip_force:
1645
        mov     eax, [_eip]
1646
        mov     [disasm_start_pos], eax
1647
 
1648
update_disasm:
1649
        cmp     [debuggee_pid], 0
1650
        jz      .no
4890 hidnplayr 1651
 
4591 hidnplayr 1652
        mcall   69, 6, [debuggee_pid], 256, [disasm_start_pos], disasm_buffer
1653
        cmp     eax, -1
1654
        jnz     @f
1655
        mov     esi, read_mem_err
1656
        call    put_message
1657
 
1658
    .no:
1659
        xor     eax, eax
1660
 
1661
    @@:
1662
        mov     [disasm_buf_size], eax
1663
        call    restore_from_breaks
4890 hidnplayr 1664
        jmp     draw_disasm
4591 hidnplayr 1665
 
1666
 
1667
;-----------------------------------------------------------------------------
1668
;                               Draw main window
1669
 
1670
draw_window:
4890 hidnplayr 1671
        ; start window redraw
4591 hidnplayr 1672
        mcall   12, 1
1673
 
4890 hidnplayr 1674
        ; define window
4908 hidnplayr 1675
        mcall   0, wnd_x_size, wnd_y_size, (COLOR_BG_NORMAL or 0x33000000), ,caption_str
4591 hidnplayr 1676
 
4908 hidnplayr 1677
        ; Get actual window size
1678
        mcall   9, thread_info, -1
4591 hidnplayr 1679
 
4908 hidnplayr 1680
        ; Check if window is rolled up
1681
        test    [thread_info.wnd_state], 100b
1682
        jnz     .done
1683
 
1684
        ; Check if window isnt smaller then permisseable
1685
        mov     eax, [thread_info.box.width]            ; window xsize
1686
        mov     ebx, [thread_info.box.height]           ; ysize
1687
        mov     edx, [thread_info.client_box.width]     ; work area xsize
1688
        mov     esi, [thread_info.client_box.height]    ; ysize
1689
        sub     eax, edx
1690
        sub     ebx, esi
1691
 
1692
        cmp     edx, wnd_x_size
1693
        jae     .x_ok
1694
        mov     edx, wnd_x_size
1695
  .x_ok:
1696
        add     edx, eax
1697
 
1698
        cmp     esi, wnd_y_size
1699
        jae     .y_ok
1700
        mov     esi, wnd_y_size
1701
  .y_ok:
1702
        add     esi, ebx
1703
        mcall   67, -1, -1      ; set the new sizes
1704
 
1705
        ; (re)calculate coordinates of GUI elements
1706
        mov     eax, [thread_info.client_box.width]
1707
        sub     eax, data_x_pos + data_x_pos + registers_x_size+3
1708
        mov     [data_x_size_dd+4], eax
1709
        mov     [messages_x_size_dd+4], eax
4591 hidnplayr 1710
        shl     eax, 16
4908 hidnplayr 1711
        mov     [data_x_size_dd], eax
1712
        mov     [messages_x_size_dd], eax
1713
        shr     eax, 16
1714
        add     eax, data_x_pos + 4
1715
        mov     [registers_x_pos_dd+4], eax
1716
        shl     eax, 16
1717
        mov     [registers_x_pos_dd], eax
4591 hidnplayr 1718
 
4908 hidnplayr 1719
        mov     eax, [thread_info.client_box.height]
1720
        sub     eax, cmdline_y_size + data_x_pos
1721
        mov     [cmdline_y_pos_dd+4], eax
1722
        shl     eax, 16
1723
        mov     [cmdline_y_pos_dd], eax
1724
        shr     eax, 16
1725
        sub     eax, messages_y_size + 4
1726
        mov     [messages_y_pos_dd+4], eax
1727
        shl     eax, 16
1728
        mov     [messages_y_pos_dd], eax
1729
        shr     eax, 16
1730
        sub     eax, disasm_y_pos + 4
1731
        mov     [disasm_y_size_dd+4], eax
1732
        shl     eax, 16
1733
        mov     [disasm_y_size_dd], eax
1734
        shr     eax, 16
1735
        mov     ecx, 10
1736
        xor     edx, edx
1737
        div     ecx
1738
        mov     [disasm_height_dd], eax
1739
 
1740
        mov     eax, [thread_info.client_box.height]
1741
        sub     eax, data_x_pos + registers_y_pos-1
1742
        mov     [registers_y_size_dd+4], eax
1743
        shl     eax, 16
1744
        mov     [registers_y_size_dd], eax
1745
 
4890 hidnplayr 1746
        ; messages frame
4908 hidnplayr 1747
        mov     ebx, [messages_x_size_dd+4]
1748
        add     ebx, (messages_x_pos-2)*10000h + (messages_x_pos+2)
4591 hidnplayr 1749
        push    ebx
4908 hidnplayr 1750
        mov     ecx, [messages_y_pos_dd+2]
1751
        add     ecx, -2*10001h
4591 hidnplayr 1752
        mov     edx, COLOR_LINE
1753
        mcall   38
4908 hidnplayr 1754
        add     ecx, (messages_y_size+2+2)*10001h
4591 hidnplayr 1755
        mcall
1756
        mov     ebx, (messages_x_pos-2)*10001h
1757
        push    ebx
4908 hidnplayr 1758
        mov     ecx, [messages_y_pos_dd+2]
1759
        add     ecx, (-2*10000h) + (messages_y_size+2)
4591 hidnplayr 1760
        mcall
4908 hidnplayr 1761
        mov     ebx, [messages_x_size_dd+2]
1762
        add     ebx, (messages_x_pos+2)*10001h
4591 hidnplayr 1763
        push    ebx
1764
        mcall
1765
 
4890 hidnplayr 1766
        ; command line frame
4908 hidnplayr 1767
        mov     ecx, [cmdline_y_pos_dd+2]
1768
        add     ecx, (-2*10000h) + (cmdline_y_size+2)
4591 hidnplayr 1769
        pop     ebx
1770
        mcall
1771
        pop     ebx
1772
        mcall
1773
        pop     ebx
4908 hidnplayr 1774
        mov     ecx, [cmdline_y_pos_dd+2]
1775
        add     ecx, (cmdline_y_size+2)*10001h
1776
 
4591 hidnplayr 1777
        mcall
4908 hidnplayr 1778
        mov     ecx, [cmdline_y_pos_dd+2]
1779
        add     ecx, (-2*10001h)
4591 hidnplayr 1780
        mcall
1781
 
4890 hidnplayr 1782
        ; registers frame
4908 hidnplayr 1783
        mov     ebx, [registers_x_pos_dd]
1784
        add     ebx, (-2) shl 16 + (registers_x_size+3)
1785
        mov     ecx, (registers_y_pos-2) shl 16 + 1
1786
        mov     edx, COLOR_LINE
1787
        mcall   13                      ; top
1788
        mov     ebx, [registers_x_pos_dd]
1789
        add     ebx, ((-2)+(registers_x_size+3)) shl 16 +1
1790
        mov     ecx, [registers_y_size_dd+4]
1791
        add     ecx, (registers_y_pos-2) shl 16 + (+3+1)
1792
        mcall                           ; right
1793
        mov     ebx, [registers_x_pos_dd]
1794
        add     ebx, (-2) shl 16 + (registers_x_size+3)
1795
        mov     ecx, [registers_y_size_dd]
1796
        add     ecx, ((registers_y_pos-2)+(+3)) shl 16 + 1
1797
        mcall                           ; bottom
4591 hidnplayr 1798
 
4890 hidnplayr 1799
        ; messages
4591 hidnplayr 1800
        call    draw_messages
1801
 
4890 hidnplayr 1802
        ; command line & cursor
4591 hidnplayr 1803
        call    draw_cmdline
1804
        call    draw_cursor
1805
 
4890 hidnplayr 1806
        ; title & registers & dump & disasm
4591 hidnplayr 1807
        mov     ebx, (data_x_pos-2)*10001h
4908 hidnplayr 1808
        mov     ecx, (title_y_pos+5)*10000h + (-2)
1809
        add     ecx, [messages_y_pos_dd+4]
4591 hidnplayr 1810
        mov     edx, COLOR_LINE
1811
        mcall   38
4908 hidnplayr 1812
        mov     ebx, [data_x_size_dd+2]
1813
        add     ebx, (data_x_pos+2)*10001h
4591 hidnplayr 1814
        mcall
4908 hidnplayr 1815
        mov     ebx, [data_x_size_dd+4]
1816
        add     ebx, (data_x_pos-2)*10000h + (data_x_pos+2)
4591 hidnplayr 1817
        mov     ecx, (disasm_y_pos-4)*10001h
1818
        mcall
1819
 
4890 hidnplayr 1820
        ; redraw whole window again
4591 hidnplayr 1821
        call    redraw_title
1822
        call    draw_registers
1823
        call    draw_dump
4890 hidnplayr 1824
        call    draw_disasm
4591 hidnplayr 1825
 
4908 hidnplayr 1826
 
1827
  .done:
4890 hidnplayr 1828
        ; end of window redraw
4591 hidnplayr 1829
        mcall   12, 2
1830
        ret
1831
 
1832
; vim: ft=fasm tabstop=4
1833