Subversion Repositories Kolibri OS

Rev

Rev 1868 | Rev 1997 | 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
;
1571 Asper 8
LMARGIN    equ (15+5)
9
TMARGIN    equ (35+5)
10
HSPACE	   equ 16
11
VSPACE	   equ 12
12
IPC_BUF    equ 160
13
DR_GRID    equ 0;1
14
WRITE_LOG  equ 1
31 halyavin 15
 
131 diamond 16
FL_KRNL equ 1
17
 
31 halyavin 18
include 'lang.inc'
19
 
20
   use32
1571 Asper 21
   org	  0x0
22
   db	  'MENUET01'		  ; 8 byte id
23
   dd	  0x01			  ; header version
24
   dd	  START 		  ; start of code
25
   dd	  I_END 		  ; size of image
26
   dd	  i_end+0x2000			; memory for app (4 Kb)
27
   dd	  i_end+0x2000			; esp
1996 clevermous 28
   dd	  filename , 0x0	  ; I_Param , I_Icon
1741 dunkaist 29
include '../../../macros.inc'
131 diamond 30
include 'debug.inc'
31
purge newline
31 halyavin 32
MAXSTRINGS = 16
131 diamond 33
TMP = 80*(MAXSTRINGS+1)
31 halyavin 34
 
1571 Asper 35
START:				; start of execution
1996 clevermous 36
	mov	edi, filename
37
	cmp	byte [edi], 0
38
	jnz	param
39
	mov	esi, default_filename
40
@@:
41
	lodsb
42
	stosb
43
	test	al, al
44
	jnz	@b
45
param:
31 halyavin 46
 
131 diamond 47
     mcall 60,1,ipcbuff,IPC_BUF+20
48
     mcall 40,1000111b
49
     mov  [ipcbuff+4],8
1355 diamond 50
; allow user to see messages written before start
51
;     mov  ecx,4096
52
;    flush:
53
;     mov  eax,63
54
;     mov  ebx,2
55
;     mcall
56
;     loop flush
31 halyavin 57
 
131 diamond 58
     mov  ecx, TMP
31 halyavin 59
     xor  eax, eax
131 diamond 60
     mov  edi, [targ]
31 halyavin 61
     rep  stosb
62
 
131 diamond 63
     mov  [tmp1],'x'
64
     mov  [tmp2],'x'
31 halyavin 65
 
66
     mov  eax,14
447 heavyiron 67
     mcall
31 halyavin 68
     and  eax,0xffff0000
131 diamond 69
     sub  eax,399 shl 16
70
     add  eax,399
31 halyavin 71
     mov  [xstart],eax
447 heavyiron 72
 
73
     mov  eax,48
74
     mov  ebx,3
75
     mov  ecx,sc
76
     mov  edx,sizeof.system_colors
77
     mcall
1571 Asper 78
  if WRITE_LOG
79
     mov  esi, filename
80
     call CreateFile
81
  end if
447 heavyiron 82
 
131 diamond 83
  red:
31 halyavin 84
     call draw_window
85
 
86
still:
87
 
1571 Asper 88
    mov  eax,23 		; wait here for event
31 halyavin 89
    mov  ebx,1
447 heavyiron 90
    mcall
31 halyavin 91
 
1571 Asper 92
    cmp  eax,1			; redraw request ?
93
    je	 red
94
    cmp  eax,2			; key in buffer ?
95
    je	 key
96
    cmp  eax,3			; button in buffer ?
97
    je	 button
131 diamond 98
    cmp  eax,7
1571 Asper 99
    je	 ipc
447 heavyiron 100
 
31 halyavin 101
    mov  eax,63
102
    mov  ebx,2
447 heavyiron 103
    mcall
31 halyavin 104
 
105
    cmp  ebx,1
106
    jne  still
1571 Asper 107
 
31 halyavin 108
  new_data:
1571 Asper 109
  if WRITE_LOG
110
     pusha
111
     mov  [tmp], al
112
     mov  edx, tmp
113
     mov  ecx, 1
114
     mov  esi, filename
115
  .write_to_logfile:
116
     call WriteToFile
117
     cmp  eax, 5
118
     jne  @f
119
     mov  esi, filename
120
     mov  [filepos], 0
121
     call CreateFile
122
     jmp  .write_to_logfile
123
  @@:
124
     inc  [filepos]
125
     popa
126
  end if
127
 
131 diamond 128
    mov  ebp,[targ]
129
  .no4:
31 halyavin 130
    cmp  al,13
131
    jne  no13
131 diamond 132
    and  dword[ebp-8],0
31 halyavin 133
    jmp  new_check
134
   no13:
135
    cmp  al,10
136
    jne  no10
1868 serge 137
    and  dword[ebp-8],0
131 diamond 138
    inc  dword[ebp-4]
139
    cmp  dword[ebp-4],MAXSTRINGS
140
    jbe  .noypos
141
    mov  dword[ebp-4],MAXSTRINGS
142
    lea  esi,[ebp+80]
143
    mov  edi,ebp
31 halyavin 144
    mov  ecx,80*(MAXSTRINGS)
145
    cld
146
    rep  movsb
147
 
131 diamond 148
    mov  esi,[ebp-4]
31 halyavin 149
    imul esi,80
131 diamond 150
    add  esi,[ebp-8]
151
    add  esi,ebp
31 halyavin 152
    mov  ecx,80
153
    xor  al,al
154
    rep  stosb
131 diamond 155
  .noypos:
156
    mov  [targ],text2
157
    and  [krnl_cnt],0
31 halyavin 158
    jmp  new_check
159
  no10:
131 diamond 160
    cmp  ebp,text1
1571 Asper 161
    je	 add2
162
		mov  ecx,[krnl_cnt]
131 diamond 163
		  cmp  al,[krnl_msg+ecx]
1571 Asper 164
		jne  .noknl
131 diamond 165
		  inc  [krnl_cnt]
1571 Asper 166
		cmp  [krnl_cnt],4
167
		jne  new_check
131 diamond 168
    mov  [targ],text1
1571 Asper 169
	.noknl:
131 diamond 170
    mov  ebp,[targ]
171
	   jecxz .add
172
    push eax
173
    mov  esi,krnl_msg
174
   .l1:
175
    lodsb
176
    call add_char
177
    loop .l1
178
    pop  eax
179
   .add:
180
    and  [krnl_cnt],0
181
  add2:
182
    call add_char
31 halyavin 183
 
184
  new_check:
185
 
186
    mov  eax,63
187
    mov  ebx,2
447 heavyiron 188
    mcall
31 halyavin 189
 
190
    cmp  ebx,1
1571 Asper 191
    je	 new_data
31 halyavin 192
 
131 diamond 193
    cmp  [vmode],2
1571 Asper 194
    je	 still
31 halyavin 195
    call draw_window
196
 
197
    jmp  still
198
 
131 diamond 199
  ipc:
200
    mov  [vmode],2
201
    mov  eax,ipcbuff
202
    mov  esi,[eax+8]
203
    mov  byte[eax],1
204
    push dword[eax+12]
205
    pop  [dump_len]
206
    mcall 9,work,-1
207
    mov  ecx,eax
208
   .lp:
209
    mcall 9
210
    cmp  [ebx+30],esi
1571 Asper 211
    je	 .ok
131 diamond 212
    loop .lp
213
    and  [dump_len],0
214
    jmp  red
215
  .ok:
216
    mov  [pid],esi
217
    lea  esi,[ebx+10]
218
    mov  edi,dump_title+10
219
    mov  ecx,12
220
    rep  movsb
221
    jmp  red
1571 Asper 222
  key:				; key
223
    mov  al,2		       ; just read it and ignore
447 heavyiron 224
    mcall
131 diamond 225
    cmp  ah,' '
1571 Asper 226
    je	 button.no_krnl_flt
131 diamond 227
    cmp  [vmode],2
228
    jne  still
229
    cmp  ah,176 ;left
1571 Asper 230
    jb	 still
131 diamond 231
    cmp  ah,179 ;right
1571 Asper 232
    ja	still
131 diamond 233
    mov  ecx,[offs]
234
    shr  eax,8
235
    sub  eax,176
236
    add  ecx,[arrows+eax*4]
237
    shl  ecx,12
238
    shr  cx,12
239
    jmp  button.check_sel
240
  .nol:
31 halyavin 241
    jmp  still
242
 
131 diamond 243
arrows dd -1,16,-16,1
244
 
1571 Asper 245
  button:			; button
246
    mov  al,17		       ; get id
447 heavyiron 247
    mcall
31 halyavin 248
 
1571 Asper 249
    cmp  ah,1			; button id=1 ?
131 diamond 250
    jne  .noclose
31 halyavin 251
 
1571 Asper 252
    or	 eax,-1 		; close this program
447 heavyiron 253
    mcall
131 diamond 254
  .noclose:
1571 Asper 255
	shr  eax,8
256
		cmp  eax,10
257
		jb   .nodump
131 diamond 258
		  lea  edi,[eax-10]
1571 Asper 259
		mcall 37,1
131 diamond 260
		  sub  eax,[edi*4+dump_cell_marg]
1571 Asper 261
		sub  eax,TMARGIN+VSPACE
262
		push eax
131 diamond 263
    and  eax,0xffff
264
		  xor  edx,edx
1571 Asper 265
		div  word[edi*4+dump_cell_size+2]
131 diamond 266
		  mov  ecx,eax
267
    shl  ecx,16
1571 Asper 268
		xor  edx,edx
131 diamond 269
		  pop  eax
1571 Asper 270
		shr  eax,16
271
		div  word[edi*4+dump_cell_size]
272
		mov  cx,ax
131 diamond 273
  .check_sel:
1571 Asper 274
		mov  eax,ecx
131 diamond 275
    shl  ax,12
276
    shr  eax,12
277
    inc  eax
278
    cmp  eax,[dump_len]
1571 Asper 279
    ja	 still;.nosel
131 diamond 280
    mov  dword[sel_byte],ecx
281
    dec  eax
282
    mov  [offs],eax
283
    jmp  red
31 halyavin 284
 
131 diamond 285
  .nodump:
286
    cmp  eax,2
287
    jne  .no_krnl_flt
288
    xor  [flag],FL_KRNL
31 halyavin 289
    jmp  still
131 diamond 290
  .no_krnl_flt:
291
    mov  [ipcbuff+4],8
292
    and  byte[ipcbuff],0
293
    inc  [vmode]
294
    cmp  [vmode],3
1571 Asper 295
    jb	 .vmok
131 diamond 296
    and  [vmode],0
297
  .vmok:
298
    jmp  red
31 halyavin 299
 
131 diamond 300
add_char:
301
    push esi
302
    mov  esi,[ebp-4]
303
    imul esi,80
304
    add  esi,[ebp-8]
305
    mov  [ebp+esi],al
306
    inc  dword[ebp-8]
307
    cmp  dword[ebp-8],80
1571 Asper 308
    jb	 .ok
131 diamond 309
    mov  dword[ebp-8],79
310
  .ok:
311
    pop  esi
312
    ret
31 halyavin 313
 
314
;   *********************************************
315
;   *******  WINDOW DEFINITIONS AND DRAW ********
316
;   *********************************************
317
 
318
 
319
draw_window:
320
 
1571 Asper 321
    mov  eax,12 		   ; function 12:tell os about windowdraw
322
    mov  ebx,1			   ; 1, start of draw
447 heavyiron 323
    mcall
31 halyavin 324
 
1571 Asper 325
				   ; DRAW WINDOW
326
    xor  eax,eax		     ; function 0 : define and draw window
31 halyavin 327
;   mov  ebx,50*65536+400          ; [x start] *65536 + [x size]
328
    mov  ebx,[xstart]
1571 Asper 329
    mov  ecx,MAXSTRINGS*10+45	   ; [y start] *65536 + [y size]
330
    mov  edx,[sc.work]		   ; color of work area RRGGBB,8->color gl
331
    or	 edx,0x13000000
332
    mov  edi,title		  ; WINDOW LABEL
447 heavyiron 333
    mcall
1571 Asper 334
 
131 diamond 335
    mov  ecx,4
336
    mov  esi,[sc.work]
447 heavyiron 337
    mov  ebx,296 shl 16+5*6
131 diamond 338
    mov  edx,3;+1 shl 30
339
    mcall 8,,<5,12>
340
    mov  edx,[vmode]
341
    lea  edx,[edx*4+duk]
447 heavyiron 342
    mcall 4,<300,8>,,,4
131 diamond 343
 
344
    cmp  [vmode],2
1571 Asper 345
    je	 no_mdbg
346
    mov  ebx,15*65536+33	   ; draw info text with function 4
31 halyavin 347
    mov  ecx,[sc.work_text]
131 diamond 348
    mov  edx,text1
349
    cmp  [vmode],0
1571 Asper 350
    je	 .kern
131 diamond 351
    mov  edx,text2
352
  .kern:
31 halyavin 353
    mov  esi,80
447 heavyiron 354
    mov  eax,4
31 halyavin 355
  newline:
447 heavyiron 356
    mcall
31 halyavin 357
    add  ebx,10
358
    add  edx,80
359
    cmp  [edx],byte 'x'
360
    jne  newline
131 diamond 361
    jmp  enddraw
362
  no_mdbg:
363
  if DUMP_TEST eq 1
364
    mov  esi,0
365
    mov  [dump_len],100;IPC_BUF
366
  else
367
    mov  esi,ipcbuff+16
368
  end if
369
    mov  ecx,[dump_len]
370
    call dump_btn
1571 Asper 371
		call draw_dump
131 diamond 372
		enddraw:
1571 Asper 373
    mov  eax,12 		   ; function 12:tell os about windowdraw
374
    mov  ebx,2			   ; 2, end of draw
447 heavyiron 375
    mcall
31 halyavin 376
 
377
    ret
378
 
131 diamond 379
if DR_GRID eq 1
380
draw_grid:
381
  mov  ecx,11
382
  mov  edi,(TMARGIN+VSPACE)shl 16+TMARGIN+VSPACE
383
 .l1:
384
  push ecx
385
  mov  ebx,LMARGIN shl 16+LMARGIN+16*HSPACE
386
  mcall 38,,edi,0
387
  add  edi,VSPACE shl 16+VSPACE
388
  pop  ecx
389
  loop .l1
390
  mov  ecx,17
391
  mov  edi,(TMARGIN+VSPACE)shl 16+TMARGIN+VSPACE*10
392
  mov  ebx,LMARGIN shl 16+LMARGIN
393
 .l2:
394
  push ecx
395
  mcall 38,,edi,0
396
  add  ebx,HSPACE shl 16+HSPACE
397
  pop  ecx
398
  loop .l2
399
  ret
400
end if
31 halyavin 401
 
131 diamond 402
draw_numbers:
403
  mcall 4,(LMARGIN+2) shl 16+180,0,numb,numb_len-numb
404
  mov  eax,dword[sel_byte]
405
  shl  ax,12
406
  shr  eax,12
407
  mov  edi,eax
408
if ~ DUMP_TEST eq 1
409
  add  edi,ipcbuff+16
410
end if
411
  mov  edx,(LMARGIN+2+6*6)shl 16+180
412
  mov  ebx,0x30000
413
  movzx ecx,byte[edi]
414
  mcall 47,,,,0x4e00e7
415
  add  ebx,0x20000
416
  add  edx,(6*10)shl 16
417
  movzx ecx,word[edi]
418
  mcall
419
  add  ebx,0x50000
420
  add  edx,(6*13)shl 16
421
  mov  ecx,[edi]
422
  mcall
423
  mov  ebx,0x80100
424
  add  edx,(6*19)shl 16
425
  mcall
426
.ex:
427
  ret
428
 
429
draw_dump:
430
; esi - data ptr, ecx - length
431
  jecxz draw_numbers.ex
432
  pusha
433
  call draw_numbers
434
  mcall 4,(LMARGIN+2) shl 16+27,0,dump_title,dump_t_len-dump_title
435
  mcall 47,0x30101,ipcbuff+8,(LMARGIN+2+6*29)shl 16+27
1571 Asper 436
  add	edx,(6*27) shl 16
437
  mov	ecx,offs
131 diamond 438
  mcall
1571 Asper 439
  sub	edx,(5*6)shl 16
131 diamond 440
  mcall ,0x30001
441
  mov  ecx,16
442
  mov  edi,HSPACE shl 16
443
  mov  ebx,(LMARGIN+5)shl 16+42
444
  call draw_marks
445
  mov  ecx,[esp+24]
446
  dec  ecx
447
  shr  ecx,4
448
  inc  ecx
449
  mov  ebx,(LMARGIN-10)shl 16+TMARGIN+2+VSPACE
450
  mov  edi,VSPACE
451
  call draw_marks
452
  popa
453
		mov  edx,TMARGIN+2
454
		mov  edi,ecx
1571 Asper 455
	.lp:
131 diamond 456
		add  edx,(LMARGIN+2) shl 16+VSPACE
457
		mov  ecx,16
458
		cmp  edi,ecx
459
		jae  .less
460
		mov  ecx,edi
1571 Asper 461
	.less:
131 diamond 462
		sub  edi,ecx
463
		push esi ecx
464
		mov  ebx,0x20100
1571 Asper 465
	.lp1:
131 diamond 466
		push ecx esi
467
		movzx ecx,byte[esi]
468
		mcall 47,,,,0
469
		add  edx,HSPACE shl 16
470
		pop  esi ecx
471
		inc  esi
472
		loop .lp1
473
		pusha
474
		mov  ebx,edx
475
		and  ebx,0xffff
476
		add  ebx,(LMARGIN+16*HSPACE+15)shl 16
477
		mov  edx,[esp+36]
478
		mov  esi,[esp+32]
479
		mcall 4,,0
480
		popa
481
		add  esp,8
482
		and  edx,0xffff
483
		test edi,edi
484
		jnz  .lp
485
.ex:
486
		ret
487
 
488
draw_marks:
489
; ebx -xy, edi-addition, ecx -cycles
490
		pusha
491
  mov  edx,__hexdigits
492
  mov  eax,4
493
  mov  esi,1
494
.tt:
495
  push ecx
496
  mcall ,,0xffffff
497
  add  ebx,edi
498
  inc  edx
499
  pop  ecx
500
  loop .tt
501
  popa
502
  ret
503
 
504
dump_btn: ; ecx-length
505
  jecxz draw_dump.ex
506
		pusha
507
		test ecx,0xffff
508
		je   .even
509
		add  ecx,16
1571 Asper 510
	.even:
131 diamond 511
		shr  ecx,4
512
		imul ecx,VSPACE
513
		add  ecx,(TMARGIN+VSPACE)shl 16-5
514
		mcall 8,LMARGIN shl 16+16*HSPACE-5,,10+3 shl 29,[sc.work]
515
		inc  edx
516
		mcall ,(LMARGIN+16*HSPACE+15)shl 16+6*16
517
		mov  edx,0xff0000
518
		mov  esi,dump_cell_size
519
		xor  eax,eax
520
		movzx ebx,[sel_byte]
521
		lodsw
522
		imul bx,ax
523
		shl  ebx,16
524
		lea  ebx,[ebx+eax+LMARGIN shl 16]
525
		movzx ecx,[sel_byte+2]
526
		lodsw
527
		imul cx,ax
528
		shl  ecx,16
529
		lea  ecx,[ecx+eax+(TMARGIN+VSPACE) shl 16]
530
		mcall 13
531
		movzx ebx,[sel_byte]
532
		lodsw
533
		imul bx,ax
534
		shl  ebx,16
535
		lea  ebx,[ebx+eax+(LMARGIN+16*HSPACE+15)shl 16]
536
  mcall 13
537
		popa
538
.ex:
1571 Asper 539
		ret
131 diamond 540
 
1571 Asper 541
 
542
if WRITE_LOG
543
;********************************************
544
;*  input:  esi = pointer to the file name  *
545
;********************************************
546
 
547
CreateFile:
548
    pusha
549
    mov      dword [InfoStructure],    2   ; create file
550
    mov      dword [InfoStructure+4],  0   ; reserved
551
    mov      dword [InfoStructure+8],  0   ; reserved
552
    mov      dword [InfoStructure+12], 0   ; 0 bytes to write (just create)
553
    mov      dword [InfoStructure+16], 0   ; NULL data pointer (no data)
554
    mov      dword [InfoStructure+20], 0   ; reserved
555
    mov      dword [InfoStructure+21], esi ; pointer to the file name
556
    mcall    70, InfoStructure
557
    clc
558
    test     eax, eax
559
    jz	     .out
560
    stc
561
  .out:
562
    popa
563
    ret
564
 
565
;********************************************
566
;*  input:  esi = pointer to the file name  *
567
;*          edx = pointer to data buffer    *
568
;*          ecx = data length               *
569
;********************************************
570
 
571
WriteToFile:
572
    push     ebx
573
    mov      dword [InfoStructure],    3   ; write to file
574
    mov      eax,  [filepos]
575
    mov      dword [InfoStructure+4],  eax ; lower position addr
576
    mov      dword [InfoStructure+8],  0   ; upper position addr (0 for FAT)
577
    mov      dword [InfoStructure+12], ecx ; number of bytes to write
578
    mov      dword [InfoStructure+16], edx ; pointer to data buffer
579
    mov      dword [InfoStructure+20], 0   ; reserved
580
    mov      dword [InfoStructure+21], esi ; pointer to the file name
581
    mcall    70, InfoStructure
582
    clc
583
    test     eax, eax
584
    jz	     .out
585
    stc
586
  .out:
587
    pop      ebx
588
    ret
589
 
590
 
591
InfoStructure:
592
		     dd      0x0     ; subfunction number
593
		     dd      0x0     ; position in the file in bytes
594
		     dd      0x0     ; upper part of the position address
595
		     dd      0x0     ; number of     bytes to read
596
		     dd      0x0     ; pointer to the buffer to write data
597
		     db      0
598
		     dd      0	     ; pointer to the filename
599
 
600
filepos  dd 0
1996 clevermous 601
default_filename db '/sys/boardlog.txt',0
1571 Asper 602
tmp	 db 0
603
end if
604
 
605
 
606
 
607
 
131 diamond 608
krnl_msg db 'K : '
609
duk db 'KernUserDump'
610
numb db 'Byte:     Word:       Dword:               Hex:'
611
numb_len:
612
dump_title db 'Dump from              (pid=    h)         Offset:     (   h)'
613
dump_t_len:
614
 
31 halyavin 615
; DATA AREA
616
 
131 diamond 617
dump_cell_marg dd LMARGIN shl 16,(LMARGIN+16*HSPACE+15)shl 16
618
dump_cell_size dw HSPACE,VSPACE,6,VSPACE
619
; 11,11 > 0,-1
620
; 5,11  > 0,-1
31 halyavin 621
if lang eq ru
1571 Asper 622
   title    db	 'Доска отладки и сообщений',0
135 diamond 623
else if lang eq en
1571 Asper 624
   title    db	 'General debug & message board',0
135 diamond 625
else
1571 Asper 626
   title    db	 'Allgemeines debug- & nachrichtenboard',0
31 halyavin 627
end if
205 heavyiron 628
   krnl_cnt dd 0
1571 Asper 629
   vmode dd 1
131 diamond 630
   targ  dd text2
31 halyavin 631
I_END:
131 diamond 632
     offs dd ?
633
     flag rb 1
634
     ipcbuff rb IPC_BUF+20
635
     rd 2
636
;     x1pos  dd ?
637
;     y1pos  dd ?
638
     text1 rb 80*(MAXSTRINGS+1)
639
     tmp1  db ?
640
     rd 2
641
;     x2pos  dd ?
642
;     y2pos  dd ?
643
     text2 rb 80*(MAXSTRINGS+1)
644
     tmp2  db ?
645
     work rb 4096
646
     sel_byte  dw ?,?
647
     pid  dd ?
31 halyavin 648
     xstart dd ?
131 diamond 649
     dump_len dd ?
650
     sc system_colors
651
i_end:
1996 clevermous 652
 
653
filename	rb	256