Subversion Repositories Kolibri OS

Rev

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