Subversion Repositories Kolibri OS

Rev

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

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