Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8560 Kenshin 1
;-------------------------------------------------------------------------------
2
; DEBUG BOARD v1.0.1 for APPLICATIONS and KERNEL DEVELOPMENT
4977 Akyltist 3
; See f63
4
; Compile with FASM for KolibriOS
8560 Kenshin 5
;-------------------------------------------------------------------------------
6
	use32
7
	org	0
8
	db	"MENUET01"
9
	dd	1
10
	dd	START
11
	dd	I_END
12
	dd	MEM_END
13
	dd	STACK_TOP
14
	dd	PARAMS_STRING
15
	dd	0
16
;-------------------------------------------------------------------------------
17
	include	"lang.inc"
18
	include	"../../../macros.inc"
6592 leency 19
 
8560 Kenshin 20
	purge	newline
21
MAX_STRINGS = 45
22
STRING_LENGTH = 80	;must be a multiple of 4
23
LINE_HEIGHT = 16
24
WINDOW_W = 60*8+5*2
25
WINDOW_W_MIN = 330
26
WORK_AREA_H_MIN = 60
27
WINDOW_W_PRCNT = 40
28
WINDOW_H_PRCNT = 75
29
TEXTFIELD_H = MAX_STRINGS*LINE_HEIGHT
30
FONT_TYPE = 0x50000000
31
;-------------------------------------------------------------------------------
5925 pathoswith 32
START:
8560 Kenshin 33
	mcall	68, 11	;init heap
34
 
35
	call	parse_params_string
36
	test	eax, eax
37
	jnz	.no_params
38
	call	check_and_fix_params
4672 izikiel 39
 
8560 Kenshin 40
.no_params:
41
	call	STATE_handler
4672 izikiel 42
 
8560 Kenshin 43
	mov	ecx, MAX_STRINGS*(STRING_LENGTH/4)
44
	mov	edi, text1
45
	mov	eax, "    "
46
	push	ecx
47
	rep	stosd
5925 pathoswith 48
 
8560 Kenshin 49
	pop	ecx
50
	mov	edi, text2
51
	rep	stosd
31 halyavin 52
 
8560 Kenshin 53
	cmp	[params.daemon_mode], 1
54
	je	.create_log_file
55
 
56
	call	calc_window_size
57
	mov	ax, word [xstart+2]
58
	mov	[prev_win_x], ax
59
	mov	ax, word [ystart+2]
60
	mov	[prev_win_y], ax
61
	mov	ax, word [xstart]
62
	mov	[prev_win_w], ax
63
	mov	ax, word [ystart]
64
	mov	[prev_win_h], ax
65
 
66
	cmp	[fullscreen_mode], 0
67
	je	@f
68
	call	calc_fullscreen_window_size
69
 
5925 pathoswith 70
@@:
8560 Kenshin 71
	mcall	48, 3, sc, sizeof.system_colors
72
 
73
	xor	eax, eax
74
	mov	[vmode], eax
75
	mov	dword [text1-4], eax
76
	mov	dword [text1-8], eax
77
	mov	dword [text2-4], eax
78
	mov	dword [text2-8], eax
79
	mov	[krnl_cnt], eax
80
	mov	[hl_line_count], eax
31 halyavin 81
 
8560 Kenshin 82
.create_log_file:
83
	xor	eax, eax
84
	mov	byte [buffer_length], al
85
	mov	[filepos], eax
31 halyavin 86
 
8560 Kenshin 87
	cmp	[params.logging_mode], 0
88
	je	@f
89
 
90
	mov	esi, [log_filename]
91
	call	create_file
92
	jnc	@f
93
	mov	esi, default_log_filename
94
	mov	[log_filename], default_log_filename
95
	call	create_file
96
 
97
@@:
98
	cmp	[params.daemon_mode], 0
99
	je	.red
100
	mcall	40, 0	;set event mask (do not receive any event codes)
447 heavyiron 101
 
8560 Kenshin 102
.red:
103
	cmp	[params.daemon_mode], 1
104
	je	.still
105
	mcall	9, procinfo, -1			;get info about board process
106
	mov	eax, dword [procinfo+42]	;width of board window
107
	mov	edx, WINDOW_W_MIN
108
	cmp	eax, edx
109
	jae	@f
110
	mcall	67, -1, -1, WINDOW_W_MIN, -1	;resize window
111
	mov	dword [procinfo+42], edx
31 halyavin 112
 
5925 pathoswith 113
@@:
8560 Kenshin 114
	mcall	48, 4				; get window header height
115
	mov	[window_header_height], eax
116
	mov	esi, WORK_AREA_H_MIN
117
	add	esi, eax
118
	mov	eax, dword [procinfo+46]	;height of board window
119
	cmp	eax, esi
120
	jae	@f
121
	mcall	67, -1, -1, -1 ;resize window
122
	mov	dword [procinfo+46], esi
123
 
124
@@:
125
	call	draw_window
126
 
127
.still:
128
	cmp	byte [buffer_length], 0
129
	je	@f
130
	cmp	[params.logging_mode], 0
131
	je	@f
132
	call	write_buffer
133
 
2234 mario79 134
@@:
8560 Kenshin 135
	cmp	[params.daemon_mode], 0
136
	je	@f
137
	mcall	5, 50				;pause for 0.5 sec
138
	jmp	.read_byte
139
@@:
140
	mcall	23, 50				; wait here for event
141
	dec	eax				; redraw request ?
142
	jz	.red
143
 
144
	dec	eax				; key in buffer ?
145
	jz	.key
146
 
147
	dec	eax				; button in buffer ?
148
	jz	.button
1571 Asper 149
 
8560 Kenshin 150
.read_byte:
151
	mcall	63, 2				;read a byte from the debug buffer
152
	cmp	ebx, 1
153
	je	.new_data
154
	jne	.still
155
 
156
.key:
157
	mcall	2
158
	cmp	ah, " "
159
	jne	@f
160
	not	[vmode]
161
	and	[vmode], 1
162
	jmp	.red
163
@@:
164
	cmp	ah, 51 ; F2
165
	je	.open_boardlog
166
	cmp	ah, 0x1B		;[Esc]?
167
	je	terminate_board
168
	cmp	ah, 0x44		;[F11]?
169
	jne	.still
170
	cmp	[fullscreen_mode], 0
171
	jne	@f
172
	mov	[fullscreen_mode], 1
173
	mcall	9, procinfo, -1		;get info about process
174
	mov	ax, word [ebx+34]
175
	mov	[prev_win_x], ax
176
	mov	ax, word [ebx+38]
177
	mov	[prev_win_y], ax
178
	mov	ax, word [ebx+42]
179
	mov	[prev_win_w], ax
180
	mov	ax, word [ebx+46]
181
	mov	[prev_win_h], ax
182
	call	calc_fullscreen_window_size
183
	movzx	ebx, word [xstart+2]
184
	movzx	ecx, word [ystart+2]
185
	movzx	edx, word [xstart]
186
	movzx	esi, word [ystart]
187
	mcall	67			;change window size & position
188
	jmp	.still
189
 
190
@@:
191
	mov	[fullscreen_mode], 0
192
	mcall	71, 2, title, 1			;set window caption
193
	mcall	18, 25, 2, -1, 0		;set window position (usual)
194
	mov	[already_on_top], 0
195
	movzx	ebx, word [prev_win_x]
196
	movzx	ecx, word [prev_win_y]
197
	movzx	edx, word [prev_win_w]
198
	movzx	esi, word [prev_win_h]
199
	mcall	67				;change window size & position
200
 
201
@@:
202
	jmp	.still
203
 
204
.open_boardlog:
205
	mov	eax, [log_filename]
206
	mov	[open_log_in_tinypad+8], eax
207
	mcall 70, open_log_in_tinypad
208
	jmp	.red
209
 
210
.button:
211
	mcall	17			; get id
212
	cmp	ah, 1			; button id=1 ?
213
	jne	.button.noclose
214
 
215
.exit:
216
	jmp	terminate_board
217
.button.noclose:
218
	cmp	ah, 3
219
	jne	@f
220
	mov	[vmode], 0
221
	jmp	.red
222
@@:
223
	cmp	ah, 4
224
	jne	@f
225
	mov	[vmode], 1
226
@@:
227
	jmp	.red
228
 
229
.new_data:
230
	cmp	byte [buffer_length], 255
231
	jne	@f
232
	cmp	[params.logging_mode], 0
233
	je	@f
234
	call	write_buffer
235
 
236
@@:
237
	movzx	ebx, byte [buffer_length]
238
	mov	[ebx+tmp], al
239
	inc	byte [buffer_length]
240
	cmp	[params.daemon_mode], 1
241
	je	.read_byte
242
	mov	ebp, [targ]
243
	cmp	al, 10
244
	jz	.new_line
245
	cmp	al, 13
246
	jz	.new_check
247
	jmp	.char
248
 
249
.new_line:
250
	and	[ebp-8], dword 0
251
	inc	dword [ebp-4]
252
	cmp	[ebp-4], dword MAX_STRINGS
253
	jb	.noypos
254
	mov	[ebp-4], dword MAX_STRINGS-1
255
	lea	esi, [ebp+STRING_LENGTH]
256
	mov	edi, ebp
257
	mov	ecx, (MAX_STRINGS-1)*(STRING_LENGTH/4)
258
	cld
259
	rep	movsd
260
 
261
	mov	esi, [ebp-4]
262
	imul	esi, STRING_LENGTH
263
	add	esi, [ebp-8]
264
	add	esi, ebp
265
	mov	ecx, STRING_LENGTH/4
266
	mov	eax, "    "
267
	rep	stosd
268
 
5925 pathoswith 269
.noypos:
8560 Kenshin 270
	mov	[targ], text1
271
	and	[krnl_cnt], 0
272
	jmp	.new_check
273
 
274
.char:
275
	cmp	ebp, text2
276
	je	.add2
277
	mov	ecx, [krnl_cnt]
278
	cmp	al, [krnl_msg+ecx]
279
	jne	.nokrnl
280
	inc	[krnl_cnt]
281
	cmp	[krnl_cnt], 4
282
	jne	.new_check
283
	mov	[targ], text2
284
.nokrnl:
285
	mov	ebp, [targ]
286
	jecxz	.add
287
	push	eax
288
	mov	esi, krnl_msg
5925 pathoswith 289
.l1:
8560 Kenshin 290
	lodsb
291
	call	add_char
292
	loop	.l1
293
	pop	eax
5925 pathoswith 294
.add:
8560 Kenshin 295
	and	[krnl_cnt], 0
296
.add2:
297
	call	add_char
1571 Asper 298
 
8560 Kenshin 299
.new_check:
300
	mcall	63, 2			;read a byte from the debug buffer
301
	cmp	ebx, 1
302
	je	.new_data
303
 
304
	cmp	[params.daemon_mode], 1
305
	je	.still
306
	call	draw_text
307
 
308
	jmp	.still
309
;-------------------------------------------------------------------------------
310
 
2234 mario79 311
;------------------------------------------------------------------------------
131 diamond 312
add_char:
8560 Kenshin 313
	push	esi
314
	mov	esi, [ebp-4]
315
	imul	esi, STRING_LENGTH
316
	add	esi, [ebp-8]
317
	mov	[ebp+esi], al
318
	cmp	dword [ebp-8], STRING_LENGTH-1
319
	je	.ok
320
	inc	dword [ebp-8]
2234 mario79 321
.ok:
8560 Kenshin 322
	pop	esi
323
	ret
324
;-------------------------------------------------------------------------------
5925 pathoswith 325
 
8560 Kenshin 326
calc_fullscreen_window_size:
327
;-------------------------------------------------------------------------------
328
	push	eax
329
 
330
	mcall	14			;get screen size
331
;	inc	ax
332
	mov	word [ystart], ax
333
	shr	eax, 16
334
;	inc	ax
335
	mov	word [xstart], ax
336
	xor	eax, eax
337
	mov	word [xstart+2], ax
338
	mov	word [ystart+2], ax
339
 
340
	pop	eax
341
	ret
342
;-------------------------------------------------------------------------------
343
 
344
calc_window_size:
345
;-------------------------------------------------------------------------------
346
	pusha
347
 
348
	mcall	48, 5			;get screen working area size
349
	mov	[ystart], ebx
350
	ror	eax, 16
351
	ror	ebx, 16
352
	mov	[xstart], eax
353
	movzx	ecx, ax
354
	movzx	edx, bx
355
	shr	eax, 16
356
	shr	ebx, 16
357
	sub	eax, ecx
358
	sub	ebx, edx
359
	inc	eax
360
	inc	ebx
361
 
362
	mov	ecx, 100
363
	mov	edx, WINDOW_W_PRCNT
364
	mul	edx
365
	xor	edx, edx
366
	div	ecx
367
	cmp	ax, WINDOW_W_MIN
368
	jae	@f
369
	mov	ax, WINDOW_W_MIN
370
@@:
371
	mov	word [xstart], ax
372
	sub	word [xstart+2], ax
373
	mov	eax, ebx
374
	mov	edx, WINDOW_H_PRCNT
375
	mul	edx
376
	xor	edx, edx
377
	div	ecx
378
	mov	dx, ax
379
	mov	cx, WORK_AREA_H_MIN
380
	mcall	48, 4				; get window header height
381
	add	ax, cx
382
	cmp	dx, ax
383
	jae	@f
384
	mov	dx, ax
385
@@:
386
	mov	word [ystart], dx
387
 
388
	popa
389
	ret
390
;-------------------------------------------------------------------------------
391
 
392
;-------------------------------------------------------------------------------
393
write_buffer:
394
	pusha
395
 
396
	mov	edx, tmp
397
	movzx	ecx, byte [buffer_length]
398
	mov	esi, [log_filename]
399
	mov	ebx, ecx
400
 
401
.write_to_logfile:
402
	call	write_to_file
403
	cmp	eax, 5
404
	jne	@f
405
	mov	esi, [log_filename]
406
	mov	[filepos], 0
407
	call	create_file
408
	jnc	.write_to_logfile
409
;	mov	[params.logging_mode], 0
410
	jmp	.ret
411
@@:
412
	add	[filepos], ebx
413
	xor	eax, eax
414
	mov	byte [buffer_length], al
415
 
416
.ret:
417
	popa
418
	ret
419
;-------------------------------------------------------------------------------
420
 
421
;-------------------------------------------------------------------------------
422
parse_params_string:
423
;result: eax = 0 (OK), eax = -1 (no params string), -2 (wrong params string)
424
	xor	eax, eax
425
	pusha
426
 
427
	mov	esi, PARAMS_STRING
428
	mov	ecx, 256
429
 
430
	cmp	byte [esi], 0
431
	je	.no_params_string
432
 
433
@@:
434
	call	skip_spaces
435
	call	check_param
436
	inc	eax
437
	jz	.no_params_string
438
	inc	eax
439
	jz	.wrong_params_string
440
	cmp	byte [esi], 0
441
	je	.ok
442
	loop	@b
443
 
444
.ok:
445
	popa
446
 
447
	ret
448
 
449
.no_params_string:
450
	popa
451
 
452
	dec	eax
453
 
454
	ret
455
 
456
.wrong_params_string:
457
	popa
458
 
459
	dec	eax
460
	dec	eax
461
 
462
	ret
463
 
464
;-------------------------------------------------------------------------------
465
 
466
;-------------------------------------------------------------------------------
467
skip_spaces:
468
	push	eax
469
	cld
470
.0:
471
	lodsb
472
	cmp	al, " "
473
	je	@f
474
	cmp	al, 9	;skip tabs too
475
	jne	.ret
476
@@:
477
	loop	.0
478
 
479
.ret:
480
	dec	esi
481
 
482
	pop	eax
483
	ret
484
;-------------------------------------------------------------------------------
485
 
486
;-------------------------------------------------------------------------------
487
check_param:
488
	push	ebx
489
 
490
	test	ecx, ecx
491
	jz	.empty
492
 
493
	cld
494
	lodsb
495
	test	al, al
496
	jnz	@f
497
	dec	esi
498
	jmp	.empty
499
 
500
@@:
501
	cmp	al, "-"
502
	jne	.not_option
503
	dec	ecx
504
	lodsb
505
	test	al, al
506
	jz	.wrong_option
507
	cmp	al, " "
508
	je	.wrong_option
509
	cmp	al, 9
510
	je	.wrong_option
511
 
512
	dec	esi
513
	call	check_option
514
	inc	eax
515
	jnz	.ok
516
 
517
.wrong_option:
518
	lea	esi, [esi-2]
519
	jmp	.wrong
520
 
521
.not_option:
522
	cmp	[params.log_filename_found], 1
523
	je	.wrong
524
	mov	[params.log_filename], esi
525
	cmp	al, '"'
526
	je	.quoted
527
	dec	[params.log_filename]
528
	xor	ebx, ebx
529
	inc	ebx
530
	dec	ecx
531
 
532
@@:
533
	lodsb
534
	test	al, al
535
	jz	@f
536
	cmp	al, " "
537
	je	@f
538
	cmp	al, 9
539
	je	@f
540
	inc	ebx
541
	loop	@b
542
	dec	ebx
543
 
544
@@:
545
	dec	esi
546
	mov	[params.log_filename_found], 1
547
	mov	[params.log_filename.size], ebx
548
	jmp	.ok
549
 
550
.quoted:
551
	xor	ebx, ebx
552
	dec	ecx
553
.quoted.0:
554
	lodsb
555
	test	al, al
556
	jnz	@f
557
	lea	ecx, [ecx+ebx+1]
558
	lea	esi, [esi-2]
559
	sub	esi, ebx
560
	jmp	.wrong
561
@@:
562
	cmp	al, '"'
563
	je	@f
564
	inc	ebx
565
	loop	.quoted.0
566
	lea	ecx, [ecx+ebx+1]
567
	lea	esi, [esi-2]
568
	sub	esi, ebx
569
	jmp	.wrong
570
 
571
@@:
572
	mov	al, byte [esi]
573
	test	al, al
574
	jz	@f
575
	cmp	al, " "
576
	je	@f
577
	cmp	al, 9
578
	jne	.wrong		;there must be spaces or null after closing (final) quote mark
579
@@:
580
	mov	[params.log_filename_found], 1
581
	mov	[params.log_filename.size], ebx
582
 
583
 
584
.ok:
585
	xor	eax, eax
586
 
587
	pop	ebx
588
	ret
589
 
590
.empty:
591
	xor	eax, eax
592
	dec	eax
593
 
594
	pop	ebx
595
	ret
596
 
597
.wrong:
598
	xor	eax, eax
599
	dec	eax
600
	dec	eax
601
 
602
	pop	ebx
603
	ret
604
;-------------------------------------------------------------------------------
605
 
606
;-------------------------------------------------------------------------------
607
check_option:
608
	push	ebx edi
609
	lea	ebx, [esi-1]
610
	cmp	byte [esi], "-"
611
	je	.long_option
612
 
613
	cld
614
@@:
615
	lodsb
616
	test	al, al
617
	jz	.ok
618
	cmp	al, " "
619
	je	.ok
620
	cmp	al, 9
621
	je	.ok
622
	call	.subcheck
623
	test	eax, eax
624
	jz	.wrong
625
	loop	@b
626
 
627
.subcheck:
628
	cmp	al, "d"
629
	jne	@f
630
	mov	[params.daemon_mode], 1
631
	ret
632
 
633
@@:
634
	cmp	al, "s"
635
	jne	@f
636
	mov	[params.stop_daemon_flag], 1
637
	ret
638
 
639
@@:
640
	cmp	al, "n"
641
	jne	@f
642
	mov	[params.logging_mode], 0
643
	ret
644
 
645
@@:
646
	cmp	al, "r"
647
	jne	@f
648
	mov	[params.rewrite_log_flag], 1
649
	ret
650
 
651
@@:
652
	cmp	al, "f"
653
	jne	@f
654
	mov	[fullscreen_mode], 1
655
	ret
656
 
657
 
658
 
659
 
660
@@:
661
	xor	eax, eax
662
	ret
663
 
664
 
665
.long_option:
666
	lodsb
667
	dec	ecx
668
	jz	.wrong
669
	mov	edi, esi
670
	push	esi
671
	cmp	ecx, params.options.d.size-1
672
	jl	@f
673
	mov	esi, params.options.d
674
	call	cmp_str
675
	jnz	@f
676
	pop	esi
677
	lea	ecx, [ecx-params.options.d.size-1]
678
	lea	esi, [esi+params.options.d.size-1]
679
	mov	[params.daemon_mode], 1
680
	jmp	.long_option.0
681
 
682
@@:
683
	cmp	ecx, params.options.s.size-1
684
	jl	@f
685
	mov	esi, params.options.s
686
	call	cmp_str
687
	jnz	@f
688
	pop	esi
689
	lea	ecx, [ecx-params.options.s.size-1]
690
	lea	esi, [esi+params.options.s.size-1]
691
	mov	[params.stop_daemon_flag], 1
692
	jmp	.long_option.0
693
 
694
@@:
695
	cmp	ecx, params.options.n.size-1
696
	jl	@f
697
	mov	esi, params.options.n
698
	call	cmp_str
699
	jnz	@f
700
	pop	esi
701
	lea	ecx, [ecx-params.options.n.size-1]
702
	lea	esi, [esi+params.options.n.size-1]
703
	mov	[params.logging_mode], 0
704
	jmp	.long_option.0
705
 
706
@@:
707
	cmp	ecx, params.options.r.size-1
708
	jl	@f
709
	mov	esi, params.options.r
710
	call	cmp_str
711
	jnz	@f
712
	pop	esi
713
	lea	ecx, [ecx-params.options.r.size-1]
714
	lea	esi, [esi+params.options.r.size-1]
715
	mov	[params.rewrite_log_flag], 1
716
	jmp	.long_option.0
717
 
718
@@:
719
	cmp	ecx, params.options.f.size-1
720
	jl	@f
721
	mov	esi, params.options.f
722
	call	cmp_str
723
	jnz	@f
724
	pop	esi
725
	lea	ecx, [ecx-params.options.f.size-1]
726
	lea	esi, [esi+params.options.f.size-1]
727
	mov	[fullscreen_mode], 1
728
	jmp	.long_option.0
729
 
730
@@:
731
	pop	esi
732
	jmp	.wrong
733
 
734
.long_option.0:
735
	mov	al, byte [esi]
736
	test	al, al
737
	jz	@f
738
	cmp	al, " "
739
	je	@f
740
	cmp	al, 9
741
	jne	.wrong		;there must be spaces or null after long option
742
@@:
743
	inc	esi
744
 
745
.ok:
746
	dec	esi
747
	xor	eax, eax
748
 
749
	pop	edi ebx
750
	ret
751
 
752
.wrong:
753
	xor	eax, eax
754
	dec	eax
755
	pop	edi esi
756
	ret
757
;-------------------------------------------------------------------------------
758
 
759
check_and_fix_params:
760
;-------------------------------------------------------------------------------
761
	push	eax
762
 
763
	cmp	[params.daemon_mode], 1
764
	jne	@f
765
	mov	[params.stop_daemon_flag], 0
766
	mov	[params.logging_mode], 1
767
 
768
@@:
769
	mov	eax, [params.log_filename]
770
	test	eax, eax
771
	jz	@f
772
	mov	[log_filename], eax
773
	add	ebx, [params.log_filename.size]
774
	mov	byte [eax+ebx], 0
775
 
776
@@:
777
	pop	eax
778
	ret
779
;-------------------------------------------------------------------------------
780
 
781
;-------------------------------------------------------------------------------
782
;************************	WINDOW DEFINITIONS AND DRAW ************************
783
;-------------------------------------------------------------------------------
31 halyavin 784
draw_window:
8560 Kenshin 785
	mcall	12, 1			; start of draw
786
	xor	edx, edx
787
	mov	dl, 0x13
788
	cmp	[fullscreen_mode], 0
789
	je	@f
790
	mov	dl, 1			;set fullscreen mode window
791
 
792
@@:
793
	shl	edx, 24
794
	or	edx, 0xFFFFFF
795
	xor	esi, esi
796
	mcall	0,[xstart],[ystart],,,title
797
 
798
	cmp	[fullscreen_mode], 0
799
	je	.l0
800
 
801
	cmp	[already_on_top], 1
802
	je	@f
803
	mcall	18, 25, 2, -1, 1			;set window position (always on top)
804
	mov	[already_on_top], 1
805
 
806
@@:
807
	mcall	13, [xstart], [ystart], 0xFFFFFF	;draw a rectangle (fill the window)
808
 
809
.l0:
810
	mov	ebx, 15 shl 16+(8*4+5)
811
	xor	ecx, ecx
812
	cmp	[fullscreen_mode], 1
813
	je	@f
814
	mov	ecx, [window_header_height]
815
 
816
@@:
817
	add	ecx, 5
818
	shl	ecx, 16
819
	mov	cx, LINE_HEIGHT+5
820
	mov	eax, [sc.work_button]
821
	cmp	[vmode], 0
822
	jne	@f
823
	call	lighten_color	;make button lighter if it's active
824
@@:
825
	mov	esi, eax
826
	mcall	8,,,3	;'User' button
827
 
828
	push	ebx ecx
829
 
830
	shr	ecx, 16
831
	mov	bx, cx
832
	rol	ebx, 16
833
	add	bx, 3
834
	ror	ebx, 16
835
	add	bx, 4
836
	mov	ecx, 0x90
837
	shl	ecx, 24
838
	add	ecx, [sc.work_button_text]
839
	mcall	4,,, u_button_text
840
	cmp	[vmode], 0
841
	jne	@f
842
	add	ebx, 1 shl 16
843
	mcall			;make text bolder if the button is active
844
 
845
@@:
846
	pop	ecx ebx
847
 
848
	add	ebx, (8*4+10) shl 16
849
	mov	bx, (8*6+5+5)
850
	mov	eax, [sc.work_button]
851
	cmp	[vmode], 1
852
	jne	@f
853
	call	lighten_color	;make button lighter if it's active
854
@@:
855
	mov	esi, eax
856
	mcall	8,,,4	;'Kernel' button
857
 
858
	shr	ecx, 16
859
	mov	bx, cx
860
	rol	ebx, 16
861
	add	bx, 3
862
	ror	ebx, 16
863
	add	bx, 4
864
	mov	ecx, 0x90
865
	shl	ecx, 24
866
	add	ecx, [sc.work_button_text]
867
	mcall	4,,, k_button_text
868
	cmp	[vmode], 1
869
	jne	@f
870
	add	ebx, 1 shl 16
871
	mcall			;make text bolder if the button is active
872
 
873
@@:
874
	call	draw_text
875
	mcall	12, 2			; 2, end of draw
876
	ret
877
;-------------------------------------------------------------------------------
878
 
879
;-------------------------------------------------------------------------------
2234 mario79 880
draw_text:
8560 Kenshin 881
	mov	ebx, 15 shl 16 + 0
882
	xor	bx, bx
883
	cmp	[fullscreen_mode], 1
884
	je	@f
885
	mov	bx, word [window_header_height]
886
 
887
@@:
888
	add	bx, 5+(LINE_HEIGHT+5)+5			;space between window header and textfield
889
	mov	ecx, FONT_TYPE
890
	mov	edi, 0xFFFFFF
891
	mov	edx, text2
892
	cmp	[vmode], 1
893
	je	.kern
894
	mov	edx, text1
5925 pathoswith 895
.kern:
8560 Kenshin 896
	push	ebx edx
897
 
898
 
899
 
900
	mov	eax, dword [procinfo+42]		;x-size of board window
901
	sub	eax, 15*2
902
	xor	edx, edx
903
	mov	ebx, 8
904
	div	ebx
905
 
2234 mario79 906
@@:
8560 Kenshin 907
	cmp	[vmode], 1
908
	jne	@f
909
	add	eax, 4
910
 
2234 mario79 911
@@:
8560 Kenshin 912
	mov	esi, STRING_LENGTH
913
	cmp	eax, esi
914
	ja	@f
915
	mov	esi, eax
4977 Akyltist 916
 
8560 Kenshin 917
@@:
918
	mov	eax, dword [procinfo+46]		;y-size of board window
919
	cmp	[fullscreen_mode], 1
920
	je	@f
921
	sub	eax, [window_header_height]
4672 izikiel 922
 
8560 Kenshin 923
@@:
924
	sub	eax, 5+(LINE_HEIGHT+5)+5+5
925
	xor	edx, edx
926
	mov	ebx, 16
927
	div	ebx
928
 
929
	pop	edx ebx
930
 
931
	mov	ebp, [edx-4]	;[edx-4] = count of strings
932
	cmp	eax, ebp
933
	ja	@f
934
	mov	ebp, eax
4672 izikiel 935
 
8560 Kenshin 936
@@:
937
	test	ebp, ebp
938
	jz	.ret
939
	mov	eax, 4
940
.newline:
941
	cmp	[edx], dword "K : "
942
	jne	.no_k_prefix
943
 
944
	push	edx esi
945
	add	edx, 4
946
	sub	esi, 4
947
 
948
	push	ecx esi edi
949
	mov	ecx, STRING_LENGTH-4
950
	mov	edi, edx
951
 
952
	mov	esi, proc_fors_term
953
	call	cmp_str
954
	jz	.highlight
4672 izikiel 955
 
8560 Kenshin 956
	mov	esi, proc_fors_term_sp
957
	call	cmp_str
958
	jnz	.no_fors_term
4672 izikiel 959
 
8560 Kenshin 960
.highlight:
961
	lea	edi, [edx+STRING_LENGTH*7]
962
	mov	esi, unexp_end_of_stack
963
	call	cmp_str
964
	jnz	@f
965
	mov	[hl_line_count], 8
966
	jmp	.no_fors_term
967
@@:
968
	mov	[hl_line_count], 10
4672 izikiel 969
 
8560 Kenshin 970
.no_fors_term:
971
	pop	edi esi ecx
972
	push	ecx
973
	cmp	[hl_line_count], 0
974
	je	@f
975
	and	ecx, 0xFF000000
976
	or	ecx, 0xCC0000		;red
977
	dec	[hl_line_count]
978
@@:
979
	mcall				; draw info text with function 4
980
	pop	ecx
981
	pop	esi edx
982
	jmp	@f
983
.no_k_prefix:
984
	mcall
985
@@:
986
	add	ebx, LINE_HEIGHT
987
	add	edx, STRING_LENGTH
988
	dec	ebp
989
	jnz	.newline
990
.ret:
991
	ret
992
;-------------------------------------------------------------------------------
4672 izikiel 993
 
8560 Kenshin 994
cmp_str:
995
;-------------------------------------------------------------------------------
996
	pusha
4672 izikiel 997
 
8560 Kenshin 998
@@:
999
	lodsb
1000
	test	al, al
1001
	jz	.ret
1002
	scasb
1003
	loope	@b
1004
	xor	eax, eax
1005
	inc	eax
1006
 
1007
.ret:
1008
	popa
1009
	ret
1010
;-------------------------------------------------------------------------------
1011
 
1012
;-------------------------------------------------------------------------------
1013
lighten_color:
1014
	ror	eax, 16
1015
	add	al, 20
1016
	rol	eax, 8
1017
	add	al, 20
1018
	rol	eax, 8
1019
	add	al, 20
1020
	ret
1021
;-------------------------------------------------------------------------------
1022
 
1023
;-------------------------------------------------------------------------------
1024
;*	input:	esi = pointer to the file name	*
1025
;-------------------------------------------------------------------------------
1026
create_file:
1027
	pusha
1028
 
1029
	cmp	[params.rewrite_log_flag], 1
1030
	je	.create
1031
	xor	eax, eax
1032
	mov	dword [f70_structure+0], 5		; get file info
1033
	mov	dword [f70_structure+4], eax		; reserved
1034
	mov	dword [f70_structure+8], eax		; reserved
1035
	mov	dword [f70_structure+12], eax		; reserved
1036
	mov	dword [f70_structure+16], file_info	; file info buf pointer
1037
	mov	dword [f70_structure+20], eax		; reserved
1038
	mov	dword [f70_structure+21], esi 		; pointer to the file name
1039
	mcall	70, f70_structure
1040
	cmp	eax, 5
1041
	je	.create			;create file if it doesn't exist
1042
	test	eax, eax
1043
	jnz	.create
1044
 
1045
	cmp	dword [file_info+36], 0
1046
	jne	.create
1047
	mov	eax, dword [file_info+32]
1048
	mov	[filepos], eax
4672 izikiel 1049
 
8560 Kenshin 1050
	jmp	.ret
1051
 
1052
.create:
1053
	xor	eax, eax
1054
	mov	dword [f70_structure+0], 2	; create file
1055
	mov	dword [f70_structure+4], eax	; reserved
1056
	mov	dword [f70_structure+8], eax	; reserved
1057
	mov	dword [f70_structure+12], eax	; 0 bytes to write (just create)
1058
	mov	dword [f70_structure+16], eax	; NULL data pointer (no data)
1059
	mov	dword [f70_structure+20], eax	; reserved
1060
	mov	dword [f70_structure+21], esi ; pointer to the file name
1061
	mcall	70, f70_structure
1062
	test	eax, eax
1063
	jz	.ret
1064
	stc
1065
.ret:
1066
	popa
1067
	ret
1068
;-------------------------------------------------------------------------------
4672 izikiel 1069
 
1070
 
1071
 
1072
 
1073
 
8560 Kenshin 1074
 
1075
;-------------------------------------------------------------------------------
1076
;*	input:	esi = pointer to the file name	*
1077
;*		edx = pointer to data buffer	*
1078
;*		ecx = data length		*
1079
;-------------------------------------------------------------------------------
1080
write_to_file:
1081
	push	ebx
1082
	mov	dword [f70_structure+0], 3	; write to file
1083
	mov	eax,	[filepos]
1084
	mov	dword [f70_structure+4], eax ; lower position addr
1085
	mov	dword [f70_structure+8], 0	; upper position addr (0 for FAT)
1086
	mov	dword [f70_structure+12], ecx ; number of bytes to write
1087
	mov	dword [f70_structure+16], edx ; pointer to data buffer
1088
	mov	dword [f70_structure+20], 0	; reserved
1089
	mov	dword [f70_structure+21], esi ; pointer to the file name
1090
	mcall	70, f70_structure
1091
	clc
1092
	test	eax, eax
1093
	jz	.out
1094
	stc
1095
.out:
1096
	pop	ebx
1097
	ret
1098
;-------------------------------------------------------------------------------
1099
 
1100
;-------------------------------------------------------------------------------
1101
STATE_handler:
1102
	mcall	68, 22, STATE_shm_block.name,, 0x00	;open "BOARDAPP:STATE" shared memory block (ro access)
1103
	test	eax, eax
1104
	jz	.create_STATE_shm_block
1105
 
1106
	mov	ecx, 20*10	;timeout = 20 sec
1107
.0:
1108
	mov	ebx, [eax]
1109
	test	ebx, ebx
1110
	jz	@f
1111
	mcall	5, 10		;wait for 0.1 sec
1112
	loop	.0
1113
	jmp	terminate_board
1114
 
1115
@@:
1116
	mov	ebx, [eax+4]
1117
	test	ebx, ebx
1118
	jnz	terminate_board
1119
	cmp	dword [eax+12], 0
1120
	jne	@f
1121
	mov	ecx, [eax+16]
1122
	mcall	18, 21		;get slot number by PID
1123
	test	eax, eax
1124
	jz	terminate_board
1125
	mov	ecx, eax
1126
	mcall	18, 3		;activate board window
1127
	jmp	terminate_board
1128
 
1129
@@:
1130
	cmp	[params.stop_daemon_flag], 1
1131
	jne	terminate_board
1132
	cmp	dword [eax+12], 1
1133
	jne	terminate_board
1134
	mov	ecx, [eax+16]
1135
	mcall	18, 18		;terminate daemonized board
1136
	jmp	terminate_board
1137
 
1138
.create_STATE_shm_block:
1139
	cmp	[params.stop_daemon_flag], 1
1140
	je	terminate_board
1141
 
1142
	mcall	68,,,STATE_shm_block.size, 0x08		;create "BOARDAPP:STATE" shared memory block (ro access for other processes)
1143
	test	eax, eax
1144
	jz	terminate_board
1145
 
1146
	mov	edi, eax
1147
	mov	dword [edi], 1
1148
	mov	dword [edi+4], STATE_shm_block.version
1149
	mov	dword [edi+8], STATE_shm_block.size
1150
	movzx	eax, byte [params.daemon_mode]
1151
	mov	dword [edi+12], eax
1152
	mcall	9, procinfo, -1
1153
	mov	eax, [ebx+30]				;PID of board
1154
	mov	dword [edi+16], eax
1155
	mov	dword [edi], 0
1156
 
1157
.ret:
1158
	ret
1159
;-------------------------------------------------------------------------------
1160
 
1161
terminate_board:
1162
	mcall	-1
1163
;-------------------------------------------------------------------------------
5925 pathoswith 1164
; DATA
4672 izikiel 1165
 
8560 Kenshin 1166
	if lang eq ru
1167
		title	db	"Доска отладки и сообщений v1.0.1", 0
1168
	else if lang eq it
1169
		title	db	"Notifiche e informazioni generiche per il debug v1.0.1", 0
1170
	else if lang eq ge
1171
		title	db	"Allgemeines debug- & nachrichtenboard v1.0.1", 0
1172
	else
1173
		title	db	"General debug & message board v1.0.1", 0
1174
	end if
5925 pathoswith 1175
 
8560 Kenshin 1176
STATE_shm_block:
1177
;structure of BOARDAPP:STATE shared memory block:
1178
;+0	dd	mutex (0 - unlocked, block was already written by board, 1 - locked, board is writing into block)
1179
;+4	dd	version of block structure (current is 0)
1180
;+8	dd	size of block (min. 4096 byte for version 0)
1181
;+12	dd	board's state (0 - usual windowed app, 1 - daemonized)
1182
;+16	dd	board's PID
1183
;next bytes are reserved
5925 pathoswith 1184
 
8560 Kenshin 1185
	.name	db	"BOARDAPP:STATE", 0
1186
	.size = 4*1024
1187
	.version = 0
1188
 
1189
default_log_filename	db	"/tmp0/1/boardlog.txt", 0
1190
krnl_msg	db	"K : "
1191
k_button_text	db	"Kernel", 0
1192
u_button_text	db	"User", 0
1193
 
1194
proc_fors_term		db	"Process - forced terminate PID: ", 0
1195
proc_fors_term_sp	db	"Proceso - terminado forzado PID: ", 0
1196
unexp_end_of_stack	db	"Unexpected end of the stack", 0
1197
 
1198
log_filename	dd	default_log_filename
1199
 
1200
filepos			dd	0
1201
 
1202
already_on_top	db	0
1203
 
1204
 
1205
params:
1206
	.log_filename		dd	0
1207
	.log_filename.size	dd	0
1208
	.log_filename_found	db	0
1209
	.daemon_mode		db	0	;0 - normal mode, 1 - daemon mode
1210
	.stop_daemon_flag	db	0
1211
	.logging_mode		db	1	;0 - don't log, 1 - log
1212
	.rewrite_log_flag	db	0
1213
	.options.d		db	"daemonize", 0
1214
	.options.d.size = $-.options.d
1215
	.options.s		db	"stop-daemon", 0
1216
	.options.s.size = $-.options.s
1217
	.options.n		db	"no-log", 0
1218
	.options.n.size = $-.options.n
1219
	.options.r		db	"rewrite-log", 0
1220
	.options.r.size = $-.options.r
1221
	.options.f		db	"fullscreen", 0
1222
	.options.f.size = $-.options.f
1223
 
1224
vmode			dd	1
1225
fullscreen_mode		db	0
1226
 
1227
 
5925 pathoswith 1228
align 4
1229
 
8560 Kenshin 1230
targ	dd	text1
1231
 
1232
open_log_in_tinypad:
1233
	dd	7
1234
	dd	0
1235
	dd	0
1236
	dd	0
1237
	dd	0
1238
	db	"/sys/tinypad", 0
1239
 
31 halyavin 1240
I_END:
5925 pathoswith 1241
 
8560 Kenshin 1242
	prev_win_x	dw	?
1243
prev_win_y	dw	?
1244
prev_win_w	dw	?
1245
prev_win_h	dw	?
5925 pathoswith 1246
 
8560 Kenshin 1247
f70_structure:
1248
	dd	?	; subfunction number
1249
	dd	?	;
1250
	dd	?	;
1251
	dd	?	;
1252
	dd	?	;
1253
	db	?
1254
	dd	?	; pointer to the filename
7425 leency 1255
 
8560 Kenshin 1256
window_header_height	dd	?
1257
buffer_length		dd	?
1258
krnl_cnt		dd	?
1259
xstart			dd	?
1260
ystart			dd	?
5925 pathoswith 1261
 
8560 Kenshin 1262
hl_line_count	rd	1
5925 pathoswith 1263
 
8560 Kenshin 1264
sc	system_colors
5925 pathoswith 1265
 
8560 Kenshin 1266
	rd	2
1267
text1	rb	STRING_LENGTH*MAX_STRINGS	;'User' messages
1268
 
1269
	rd	2
1270
text2	rb	STRING_LENGTH*MAX_STRINGS	;'Kernel' messages
1271
 
1272
tmp			rb	256
1273
PARAMS_STRING		rb	256
1274
procinfo		rb	1024
1275
file_info		rb	40
1276
 
1277
	align	4
1278
	rb	512
1279
STACK_TOP:
1280
 
1281
MEM_END: