Subversion Repositories Kolibri OS

Rev

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