Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4977 Akyltist 1
;------------------------------------------------------------------------------
2
; DEBUG BOARD for APPLICATIONS and KERNEL DEVELOPMENT
3
; See f63
4
; Compile with FASM for KolibriOS
5
;------------------------------------------------------------------------------
6
include 'lang.inc'
4672 izikiel 7
WRITE_LOG    equ 1
4977 Akyltist 8
P_LEN        equ 11
9
;------------------------------------------------------------------------------
10
        use32
11
        org     0x0
12
        db      'MENUET01'
13
        dd      0x01
14
        dd      START
15
        dd      I_END
16
        dd      mem
17
        dd      mem
18
        dd     filename, 0x0
19
;------------------------------------------------------------------------------
1741 dunkaist 20
include '../../../macros.inc'
3013 dunkaist 21
include '../../../debug.inc'
4977 Akyltist 22
purge       newline
5546 leency 23
MAXSTRINGS  = 45
131 diamond 24
TMP = 80*(MAXSTRINGS+1)
2234 mario79 25
;------------------------------------------------------------------------------
4977 Akyltist 26
    START:
27
        call    CheckUnique
28
        mov     edi, filename
29
        cmp     [edi], byte 0
30
        jnz     param
31
        mov     esi, default_filename
32
    @@:
33
        lodsb
34
        stosb
35
        test    al,al
36
        jnz     @b
37
    param:
38
        mov     ecx, TMP
39
        xor     eax, eax
40
        mov     edi, [targ]
41
        rep     stosb
4672 izikiel 42
 
4977 Akyltist 43
        mov     [tmp1], 'x'
44
        mov     [tmp2], 'x'
4672 izikiel 45
 
4977 Akyltist 46
        mcall   14
47
        and     eax, 0xffff0000
48
        sub     eax, 399 shl 16
49
        add     eax, 399
50
        mov     [xstart], eax
51
        mcall   48, 3, sc, sizeof.sys_colors_new
31 halyavin 52
 
4977 Akyltist 53
        mov     esi, filename
54
        call    CreateFile
2234 mario79 55
;------------------------------------------------------------------------------
56
red:
4977 Akyltist 57
        call draw_window
2234 mario79 58
;------------------------------------------------------------------------------
31 halyavin 59
still:
4977 Akyltist 60
        cmp     [buffer_length], 0
61
        je      @f
62
        call    write_buffer
63
    @@:
64
        mcall   23, 50                    ; wait here for event
65
        cmp     eax, 1                    ; redraw request ?
66
        je      red
31 halyavin 67
 
4977 Akyltist 68
        cmp     eax, 2                    ; key in buffer ?
69
        je      key
31 halyavin 70
 
4977 Akyltist 71
        cmp     eax, 3                    ; button in buffer ?
72
        je      button
447 heavyiron 73
 
4977 Akyltist 74
        mcall   63, 2
75
        cmp     ebx, 1
76
        jne     still
31 halyavin 77
 
2234 mario79 78
new_data:
4977 Akyltist 79
        cmp     [buffer_length], 255
80
        jne     @f
81
        call    write_buffer
82
    @@:
83
        movzx   ebx, byte[buffer_length]
84
        mov     [ebx+tmp], al
85
        inc     [buffer_length]
86
        mov     ebp, [targ]
87
    .no4:
88
        cmp     al, 13
89
        jne     no13
90
        and     [ebp-8], dword 0
91
        jmp     new_check
4480 mario79 92
;------------------------------------------
93
write_buffer:
4977 Akyltist 94
        pusha
95
        mov     edx, tmp
96
        movzx   ecx, byte[buffer_length]	;1
97
        mov     esi, filename
98
    .write_to_logfile:
99
        call    WriteToFile
100
        cmp     eax, 5
101
        jne     @f
102
        mov     esi, filename
103
        mov     [filepos], 0
104
        call    CreateFile
105
        jnc     .write_to_logfile
2234 mario79 106
@@:
4977 Akyltist 107
        movzx   eax,byte[buffer_length]
108
        add     [filepos],eax
109
        xor     eax,eax
110
        mov     [buffer_length],al
111
        popa
112
        ret
2234 mario79 113
;------------------------------------------
114
no13:
4977 Akyltist 115
        cmp     al, 10
116
        jne     no10
117
        and     [ebp-8], dword 0
118
        inc     dword [ebp-4]
119
        cmp     [ebp-4], dword MAXSTRINGS
120
        jbe     .noypos
121
        mov     [ebp-4], dword MAXSTRINGS
122
        lea     esi, [ebp+80]
123
        mov     edi, ebp
124
        mov     ecx, 80*(MAXSTRINGS)
125
        cld
126
        rep     movsb
1571 Asper 127
 
4977 Akyltist 128
        mov     esi, [ebp-4]
129
        imul    esi, 80
130
        add     esi, [ebp-8]
131
        add     esi, ebp
132
        mov     ecx, 80
133
        xor     al , al
134
        rep     stosb
135
    .noypos:
136
        mov     [targ],text2
137
        and     [krnl_cnt],0
138
        jmp     new_check
2234 mario79 139
;------------------------------------------
140
no10:
4977 Akyltist 141
        cmp     ebp, text1
142
        je      add2
143
        mov     ecx, [krnl_cnt]
144
        cmp     al, [krnl_msg+ecx]
145
        jne     .noknl
146
        inc     [krnl_cnt]
147
        cmp     [krnl_cnt], 4
148
        jne     new_check
149
        mov     [targ], text1
150
    .noknl:
151
        mov     ebp, [targ]
152
        jecxz   .add
153
        push    eax
154
        mov     esi, krnl_msg
155
    .l1:
156
        lodsb
157
        call    add_char
158
        loop    .l1
159
        pop     eax
160
    .add:
161
        and     [krnl_cnt], 0
2234 mario79 162
add2:
4977 Akyltist 163
        call    add_char
1571 Asper 164
 
2234 mario79 165
new_check:
4977 Akyltist 166
        mcall   63, 2
167
        cmp     ebx, 1
168
        je      new_data
169
        call    draw_text
170
        jmp     still
2234 mario79 171
;------------------------------------------------------------------------------
172
key:
4977 Akyltist 173
        mcall   2
174
        cmp     ah, ' '
175
        je      button.noclose
176
        jmp     still
2234 mario79 177
;------------------------------------------------------------------------------
178
button:
4977 Akyltist 179
        mcall   17                        ; get id
180
        cmp     ah, 1                     ; button id=1 ?
181
        jne     .noclose
182
        or      eax, -1                   ; close this program
183
        mcall
184
    .noclose:
185
        xor     [vmode], 1
186
        jmp     red
2234 mario79 187
;------------------------------------------------------------------------------
131 diamond 188
add_char:
4977 Akyltist 189
        push    esi
190
        mov     esi, [ebp-4]
191
        imul    esi, 80
192
        add     esi, [ebp-8]
193
        mov     [ebp+esi], al
194
        inc     dword[ebp-8]
195
        cmp     dword[ebp-8], 80
196
        jb      .ok
197
        mov     dword[ebp-8], 79
2234 mario79 198
.ok:
4977 Akyltist 199
        pop     esi
200
        ret
4876 leency 201
 
2234 mario79 202
;------------------------------------------------------------------------------
4977 Akyltist 203
;************************  WINDOW DEFINITIONS AND DRAW ************************
204
;------------------------------------------------------------------------------
31 halyavin 205
draw_window:
4977 Akyltist 206
        mcall   12, 1                     ; 1, start of draw
207
        mcall   48, 5                     ; GetClientTop
208
        shr     ebx, 16
209
        mov     ecx, ebx
210
        shl     ecx, 16
211
        add     ecx, MAXSTRINGS*10+45     ; [y start] *65536 + [y size]
212
        xor     eax, eax                  ; function 0 : define and draw window
213
        mov     edx, 0xffffff
214
        or      edx, 0x14000000
215
        xor     esi, esi
216
        mcall   ,[xstart],,,,title
217
        mov     ebx, 296 shl 16+31
218
        mcall   8,,<4,13>,3,[sc.btn_face]
219
        mov     edx, [vmode]
220
        lea     edx, [edx*4+duk]
5546 leency 221
		mov     ecx, 0x80
222
		shr     ecx, 24
223
		add     ecx, [sc.btn_text]
4977 Akyltist 224
        mcall   4,<300,7>,,,4
225
        call    draw_text
226
        mcall   12, 2                     ; 2, end of draw
227
        ret
2234 mario79 228
;------------------------------------------------------------------------------
229
draw_text:
4977 Akyltist 230
        mov     ebx, 15*65536+30          ; draw info text with function 4
231
        xor     ecx, ecx
232
        or      ecx, 0x40000000
233
        mov     edi, 0xffffff
234
        mov     edx, text1
235
        cmp     [vmode], 0
236
        je      .kern
237
        mov     edx, text2
238
    .kern:
239
        push    ebx ecx edx
240
        mcall   9, procinfo,-1
241
        mov     eax, [ebx+42]
242
        xor     edx, edx
243
        mov     ebx, 6
244
        div     ebx
245
        pop     edx ecx ebx
246
        mov     esi, 80
247
        cmp     eax, esi
248
        ja      @f
249
        mov     esi, eax
2234 mario79 250
@@:
4977 Akyltist 251
        cmp     esi, 5
252
        ja      @f
253
        mov     esi, 5
2234 mario79 254
@@:
4977 Akyltist 255
        sub     esi, 4
256
        mov     eax, 4
2234 mario79 257
newline:
4977 Akyltist 258
        mcall
259
        add     ebx, 10
260
        add     edx, 80
261
        cmp     [edx], byte 'x'
262
        jne     newline
263
        ret
264
 
3586 fedesco 265
;------------------------------------------------------------------------------
1571 Asper 266
;*  input:  esi = pointer to the file name  *
4977 Akyltist 267
;------------------------------------------------------------------------------
1571 Asper 268
CreateFile:
4977 Akyltist 269
        pusha
270
        mov     dword [InfoStructure+00], 2   ; create file
271
        mov     dword [InfoStructure+04], 0   ; reserved
272
        mov     dword [InfoStructure+08], 0   ; reserved
273
        mov     dword [InfoStructure+12], 0   ; 0 bytes to write (just create)
274
        mov     dword [InfoStructure+16], 0   ; NULL data pointer (no data)
275
        mov     dword [InfoStructure+20], 0   ; reserved
276
        mov     dword [InfoStructure+21], esi ; pointer to the file name
277
        mcall   70, InfoStructure
278
        test    eax, eax
279
        jz      .out
280
        stc
281
    .out:
282
        popa
283
        ret
284
;------------------------------------------------------------------------------
1571 Asper 285
;*  input:  esi = pointer to the file name  *
286
;*          edx = pointer to data buffer    *
287
;*          ecx = data length               *
4977 Akyltist 288
;------------------------------------------------------------------------------
1571 Asper 289
WriteToFile:
4977 Akyltist 290
        push    ebx
291
        mov     dword [InfoStructure+00], 3   ; write to file
292
        mov     eax,  [filepos]
293
        mov     dword [InfoStructure+04], eax ; lower position addr
294
        mov     dword [InfoStructure+08], 0   ; upper position addr (0 for FAT)
295
        mov     dword [InfoStructure+12], ecx ; number of bytes to write
296
        mov     dword [InfoStructure+16], edx ; pointer to data buffer
297
        mov     dword [InfoStructure+20], 0   ; reserved
298
        mov     dword [InfoStructure+21], esi ; pointer to the file name
299
        mcall   70, InfoStructure
300
        clc
301
        test    eax, eax
302
        jz      .out
303
        stc
304
    .out:
305
        pop      ebx
306
        ret
4672 izikiel 307
 
4977 Akyltist 308
;------------------------------------------------------------------------------
4672 izikiel 309
;*  input:  esi = pointer to string         *
310
;*          edi = pointer to string         *
311
;*          ecx = data length               *
4977 Akyltist 312
;------------------------------------------------------------------------------
4672 izikiel 313
StrCmp:
4977 Akyltist 314
        repe    cmpsb
315
        ja      .a_greater_b
316
        jb      .a_less_b
317
    .equal:
318
        mov     eax, 0
319
        jmp     .end
320
    .a_less_b:
321
        mov     eax, 1
322
        jmp     .end
323
    .a_greater_b:
324
        mov     eax, -1
325
    .end:
326
        ret
4672 izikiel 327
 
4977 Akyltist 328
;------------------------------------------------------------------------------
329
;*  input:  edi = pointer to string          *
330
;*          ecx = data length                *
331
;------------------------------------------------------------------------------
4672 izikiel 332
; 'a' - 'A' = 32 -> 'A'|32 = 'a'
333
ToLower:
4977 Akyltist 334
        xor     eax, eax
4672 izikiel 335
.cycle:
4977 Akyltist 336
        or      byte[edi+eax], 32
337
        inc     eax
338
        loop    .cycle
4672 izikiel 339
.end:
4977 Akyltist 340
        ret
4672 izikiel 341
 
4977 Akyltist 342
;------------------------------------------------------------------------------
343
;* get info on current thread, save pid/tid
344
;* look for another process with same name and different pid/tid
345
;* if found, close self
346
;* else continue normally
347
;------------------------------------------------------------------------------
4672 izikiel 348
CheckUnique:
4977 Akyltist 349
    .get_thread_info:
350
        mov     ebx, procinfo
351
        mov     ecx, -1
352
        mcall   9
4672 izikiel 353
 
4977 Akyltist 354
    .get_pid:                             ; check_buffer
355
        mov     [process_count], eax
356
        mov     eax, [ebx+process_information.PID]
357
        mov     [pid_tid], eax
358
        mov     ecx, 2
4672 izikiel 359
 
4977 Akyltist 360
    .check_threads:
361
        cmp     ecx, [process_count]
362
        ja      .leave_check
363
        mov     eax, 9
364
        mcall
4672 izikiel 365
 
4977 Akyltist 366
    .check_slot_free:
367
        cmp     dword [ebx+process_information.slot_state], 9
368
        je      .next_thread
4672 izikiel 369
 
4977 Akyltist 370
    .check_pid:
371
        mov     eax, [pid_tid]
372
        cmp     [ebx+process_information.PID], eax
373
        je      .next_thread
4672 izikiel 374
 
4977 Akyltist 375
    .get_proc_name:
376
        lea     edi, [ebx+process_information.process_name]
377
        push    ecx
378
        mov     ecx, my_name_size-1
4672 izikiel 379
 
4977 Akyltist 380
    .lower_case:
381
        call    ToLower
382
        lea     esi, [my_name]
383
        mov     ecx, my_name_size
384
        call    StrCmp
385
        pop     ecx
386
        cmp     eax, 0
387
        je      .close_program
4672 izikiel 388
 
4977 Akyltist 389
    .next_thread:
390
        inc     ecx
391
        jmp     .check_threads
4672 izikiel 392
 
4977 Akyltist 393
    .close_program:
394
        ; restore and active window of previous thread
395
        mcall    18, 3
396
        mov      eax, -1
397
        mcall
4672 izikiel 398
 
4977 Akyltist 399
    .leave_check:
400
        ret
4672 izikiel 401
 
402
 
4977 Akyltist 403
;------------------------------------------------------------------------------
404
;***********************************  DATA ************************************
405
;------------------------------------------------------------------------------
406
align 4
1571 Asper 407
InfoStructure:
4977 Akyltist 408
        dd      0x0                       ; subfunction number
409
        dd      0x0                       ; position in the file in bytes
410
        dd      0x0                       ; upper part of the position address
411
        dd      0x0                       ; number of bytes to read
412
        dd      0x0                       ; pointer to the buffer to write data
413
        db      0x0
414
        dd      0x0                       ; pointer to the filename
415
filepos dd      0x0
1996 clevermous 416
default_filename db '/sys/boardlog.txt',0
2234 mario79 417
;------------------------------------------------------------------------------
31 halyavin 418
if lang eq ru
2234 mario79 419
 title	db 'Доска отладки и сообщений',0
3586 fedesco 420
else if lang eq it
421
 title	db 'Notifiche e informazioni generiche per il debug',0
422
else if lang eq ge
423
 title	db 'Allgemeines debug- & nachrichtenboard',0
424
else
2234 mario79 425
 title	db 'General debug & message board',0
31 halyavin 426
end if
2234 mario79 427
;------------------------------------------------------------------------------
4977 Akyltist 428
krnl_msg        db  'K : '
429
duk             db  'KernUser'
430
krnl_cnt        dd  0
431
vmode           dd  1
432
targ            dd  text2
433
my_name         db  'board',0
434
my_name_size    = $-my_name
435
process_count   dd  0x0
436
pid_tid         dd  0x0
437
;------------------------------------------------------------------------------
31 halyavin 438
I_END:
2234 mario79 439
;------------------------------------------------------------------------------
4977 Akyltist 440
offs            dd  ?
441
flag            rb  1
442
                rd  2
443
text1           rb  80*(MAXSTRINGS+1)
444
tmp1            db  ?
445
                rd  2
446
text2           rb  80*(MAXSTRINGS+1)
447
tmp2            db  ?
448
xstart          dd  ?
449
sc              sys_colors_new
131 diamond 450
i_end:
4977 Akyltist 451
buffer_length   rb  1
4480 mario79 452
;------------------------------------------------------------------------------
4977 Akyltist 453
tmp             rb  256
454
filename        rb  256
4480 mario79 455
;------------------------------------------------------------------------------
1997 clevermous 456
align 4
2234 mario79 457
procinfo:
4977 Akyltist 458
        rb 1024
3586 fedesco 459
;------------------------------------------------------------------------------
2234 mario79 460
align 4
4977 Akyltist 461
stackbuf        rb  2000h
2234 mario79 462
;------------------------------------------------------------------------------
4672 izikiel 463
mem: