Subversion Repositories Kolibri OS

Rev

Rev 4876 | Rev 4977 | 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
 
2234 mario79 213
;------------------------------------------------------------------------------
31 halyavin 214
;   *********************************************
215
;   *******  WINDOW DEFINITIONS AND DRAW ********
216
;   *********************************************
217
draw_window:
2234 mario79 218
	mcall	12,1	; 1, start of draw
4876 leency 219
	mcall 48, 5     ; GetClientTop
220
    shr ebx, 16
221
	mov	ecx,ebx
222
	shl ecx,16
223
	add ecx,MAXSTRINGS*10+45	   ; [y start] *65536 + [y size]
2234 mario79 224
	xor	eax,eax		     ; function 0 : define and draw window
2484 mario79 225
;	mov	edx,[sc.work]		   ; color of work area RRGGBB,8->color gl
226
	mov	edx,0xffffff
2743 dunkaist 227
	or	edx,0x14000000
2234 mario79 228
	xor	esi,esi
229
	mcall	,[xstart],,,,title
230
	mov	ebx,296 shl 16+5*6
231
	mcall	8,,<5,12>,3,[sc.work]
232
	mov	edx,[vmode]
233
	lea	edx,[edx*4+duk]
234
	mcall	4,<300,8>,,,4
235
	call	draw_text
236
	mcall	12,2	; 2, end of draw
237
	ret
238
;------------------------------------------------------------------------------
239
draw_text:
240
	mov	ebx,15*65536+30	   ; draw info text with function 4
2484 mario79 241
;	mov	ecx,[sc.work_text]
242
	xor	ecx,ecx
2234 mario79 243
	or	ecx,0x40000000
2484 mario79 244
;	mov	edi,[sc.work]
245
	mov	edi,0xffffff
2234 mario79 246
	mov	edx,text1
247
	cmp	[vmode],0
248
	je	.kern
249
	mov	edx,text2
250
.kern:
251
	push	ebx ecx edx
252
	mcall	9,procinfo,-1
253
	mov	eax,[ebx+42]
254
	xor	edx,edx
255
	mov	ebx,6
256
	div	ebx
257
	pop	edx ecx ebx
258
	mov	esi,80
259
	cmp	eax,esi
260
	ja	@f
261
	mov	esi,eax
262
@@:
263
	cmp	esi,5
264
	ja	@f
265
	mov	esi,5
266
@@:
267
	sub	esi,4
268
	mov	eax,4
269
newline:
270
	mcall
271
	add	ebx,10
272
	add	edx,80
273
	cmp	[edx],byte 'x'
274
	jne	newline
275
	ret
3586 fedesco 276
;------------------------------------------------------------------------------
1571 Asper 277
;********************************************
278
;*  input:  esi = pointer to the file name  *
279
;********************************************
280
 
281
CreateFile:
2234 mario79 282
	pusha
283
	mov	dword [InfoStructure],2		; create file
284
	mov	dword [InfoStructure+4],0	; reserved
285
	mov	dword [InfoStructure+8],0	; reserved
286
	mov	dword [InfoStructure+12],0	; 0 bytes to write (just create)
287
	mov	dword [InfoStructure+16],0	; NULL data pointer (no data)
288
	mov	dword [InfoStructure+20],0	; reserved
289
	mov	dword [InfoStructure+21],esi	; pointer to the file name
290
	mcall	70, InfoStructure
291
	test	eax,eax
292
	jz	.out
293
	stc
294
.out:
295
	popa
296
	ret
297
;------------------------------------------------
1571 Asper 298
;********************************************
299
;*  input:  esi = pointer to the file name  *
300
;*          edx = pointer to data buffer    *
301
;*          ecx = data length               *
302
;********************************************
303
 
304
WriteToFile:
2234 mario79 305
	push	ebx
306
	mov	dword [InfoStructure],3		; write to file
307
	mov	eax,  [filepos]
308
	mov	dword [InfoStructure+4],eax	; lower position addr
309
	mov	dword [InfoStructure+8],0	; upper position addr (0 for FAT)
310
	mov	dword [InfoStructure+12],ecx	; number of bytes to write
311
	mov	dword [InfoStructure+16],edx	; pointer to data buffer
312
	mov	dword [InfoStructure+20],0	; reserved
313
	mov	dword [InfoStructure+21],esi	; pointer to the file name
314
	mcall	70, InfoStructure
315
	clc
316
	test	eax,eax
317
	jz	.out
318
	stc
319
.out:
320
	pop      ebx
321
	ret
4672 izikiel 322
 
323
;-------------------------------------------------
324
;********************************************
325
;*  input:  esi = pointer to string         *
326
;*          edi = pointer to string         *
327
;*          ecx = data length               *
328
;********************************************
329
StrCmp:
330
	repe cmpsb
331
	ja .a_greater_b
332
	jb .a_less_b
333
.equal:
334
	mov eax, 0
335
	jmp .end
336
.a_less_b:
337
	mov eax, 1
338
	jmp .end
339
.a_greater_b:
340
	mov eax, -1
341
.end:
342
	ret
343
 
344
;-------------------------------------------------
345
;********************************************
346
;*  input:  edi = pointer to string         *
347
;*          ecx = data length			    *
348
;********************************************
349
; 'a' - 'A' = 32 -> 'A'|32 = 'a'
350
ToLower:
351
	xor eax, eax
352
.cycle:
353
	or byte[edi+eax], 32
354
	inc eax
355
	loop .cycle
356
.end:
357
	ret
358
 
359
 
360
;-------------------------------------------------
361
CheckUnique:
362
;get info on current thread, save pid/tid
363
;look for another process with same name and different pid/tid
364
;if found, close self
365
;else continue normally
366
 
367
.get_thread_info:
368
	mov ebx, procinfo
369
	mov ecx, -1
370
	mcall 9
371
.get_pid:
372
; check_buffer
373
	mov [process_count], eax
374
	mov eax, [ebx+process_information.PID]
375
	mov [pid_tid], eax
376
	mov ecx, 2
377
 
378
.check_threads:
379
	cmp ecx, [process_count]
380
	ja .leave_check
381
	mov eax, 9
382
	mcall
383
 
384
.check_slot_free:
385
	cmp dword [ebx+process_information.slot_state], 9
386
	je .next_thread
387
 
388
.check_pid:
389
	mov eax, [pid_tid]
390
	cmp [ebx+process_information.PID], eax
391
	je .next_thread
392
 
393
.get_proc_name:
394
	lea edi, [ebx+process_information.process_name]
395
	push ecx
396
	mov ecx, my_name_size-1
397
.lower_case:
398
	call ToLower
399
	lea esi, [my_name]
400
 
401
	mov ecx, my_name_size
402
	call StrCmp
403
 
404
	pop ecx
405
 
406
	cmp eax, 0
407
	je .close_program
408
 
409
.next_thread:
410
	inc ecx
411
	jmp .check_threads
412
 
413
.close_program:
4673 izikiel 414
	mcall 18,3 ; restore and active window of previous thread
4672 izikiel 415
	mov eax, -1
416
	mcall
417
 
418
.leave_check:
419
	ret
420
 
421
 
422
 
2234 mario79 423
;--------------------------------------------------
1571 Asper 424
InfoStructure:
2234 mario79 425
	dd 0x0	; subfunction number
426
	dd 0x0	; position in the file in bytes
427
	dd 0x0	; upper part of the position address
428
	dd 0x0	; number of bytes to read
429
	dd 0x0	; pointer to the buffer to write data
430
	db 0
431
	dd 0	; pointer to the filename
1571 Asper 432
 
2234 mario79 433
filepos	dd 0
1996 clevermous 434
default_filename db '/sys/boardlog.txt',0
2234 mario79 435
;------------------------------------------------------------------------------
131 diamond 436
krnl_msg db 'K : '
1997 clevermous 437
duk db 'KernUser'
131 diamond 438
 
31 halyavin 439
; DATA AREA
440
 
131 diamond 441
; 11,11 > 0,-1
442
; 5,11  > 0,-1
31 halyavin 443
if lang eq ru
2234 mario79 444
 title	db 'Доска отладки и сообщений',0
3586 fedesco 445
else if lang eq it
446
 title	db 'Notifiche e informazioni generiche per il debug',0
447
else if lang eq ge
448
 title	db 'Allgemeines debug- & nachrichtenboard',0
449
else
2234 mario79 450
 title	db 'General debug & message board',0
31 halyavin 451
end if
2234 mario79 452
krnl_cnt	dd 0
453
vmode		dd 1
454
targ		dd text2
4672 izikiel 455
 
456
my_name 	   db 'board',0
457
my_name_size   = $-my_name
458
process_count  dd 0x0
459
pid_tid		   dd 0x0
2234 mario79 460
;------------------------------------------------------------------------------
31 halyavin 461
I_END:
2234 mario79 462
;------------------------------------------------------------------------------
463
offs	dd ?
464
flag	rb 1
465
	rd 2
466
;x1pos	dd ?
467
;y1pos	dd ?
468
text1	rb 80*(MAXSTRINGS+1)
469
tmp1	db ?
470
	rd 2
471
;x2pos	dd ?
472
;y2pos	dd ?
473
text2	rb 80*(MAXSTRINGS+1)
474
tmp2	db ?
475
xstart	dd ?
476
 
477
sc system_colors
478
 
131 diamond 479
i_end:
4480 mario79 480
buffer_length	rb 1
481
;------------------------------------------------------------------------------
482
tmp	rb	256
483
;------------------------------------------------------------------------------
2234 mario79 484
filename	rb 256
3586 fedesco 485
;------------------------------------------------------------------------------
1997 clevermous 486
align 4
2234 mario79 487
procinfo:
488
	rb 1024
3586 fedesco 489
;------------------------------------------------------------------------------
2234 mario79 490
align 4
491
stackbuf	rb 2000h
492
;------------------------------------------------------------------------------
4672 izikiel 493
mem: