Subversion Repositories Kolibri OS

Rev

Rev 135 | Rev 447 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   DEBUG BOARD for APPLICATIONS and KERNEL DEVELOPMENT
  3. ;
  4. ;   See f63
  5. ;
  6. ;   Compile with FASM for Menuet
  7. ;
  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.  
  15. FL_KRNL equ 1
  16.  
  17. include 'lang.inc'
  18.  
  19.    use32
  20.    org    0x0
  21.    db     'MENUET01'              ; 8 byte id
  22.    dd     0x01                    ; header version
  23.    dd     START                   ; start of code
  24.    dd     I_END                   ; size of image
  25.    dd     i_end+0x2000                  ; memory for app (4 Kb)
  26.    dd     i_end+0x2000                  ; esp
  27.    dd     0x0 , 0x0               ; I_Param , I_Icon
  28. include 'MACROS.INC'
  29. include 'debug.inc'
  30. purge newline
  31. MAXSTRINGS = 16
  32. TMP = 80*(MAXSTRINGS+1)
  33.  
  34. START:                          ; start of execution
  35.  
  36.      mcall 60,1,ipcbuff,IPC_BUF+20
  37.      mcall 40,1000111b
  38.      mov  [ipcbuff+4],8
  39.      mov  ecx,1024
  40.     flush:
  41.      mov  eax,63
  42.      mov  ebx,2
  43.      int  0x40
  44.      loop flush
  45.  
  46.      mov  ecx, TMP
  47.      xor  eax, eax
  48.      mov  edi, [targ]
  49.      rep  stosb
  50.  
  51.      mov  [tmp1],'x'
  52.      mov  [tmp2],'x'
  53.  
  54.      mov  eax,14
  55.      int  0x40
  56.      and  eax,0xffff0000
  57.      sub  eax,399 shl 16
  58.      add  eax,399
  59.      mov  [xstart],eax
  60.   red:
  61.      call draw_window
  62.  
  63. still:
  64.  
  65.     mov  eax,23                 ; wait here for event
  66.     mov  ebx,1
  67.     int  0x40
  68.  
  69.     cmp  eax,1                  ; redraw request ?
  70.     je   red
  71.     cmp  eax,2                  ; key in buffer ?
  72.     je   key
  73.     cmp  eax,3                  ; button in buffer ?
  74.     je   button
  75.     cmp  eax,7
  76.     je   ipc
  77.     mov  eax,63
  78.     mov  ebx,2
  79.     int  0x40
  80.  
  81.     cmp  ebx,1
  82.     jne  still
  83.                
  84.   new_data:
  85.     mov  ebp,[targ]
  86.   .no4:
  87.     cmp  al,13
  88.     jne  no13
  89.     and  dword[ebp-8],0
  90.     jmp  new_check
  91.    no13:
  92.     cmp  al,10
  93.     jne  no10
  94.     inc  dword[ebp-4]
  95.     cmp  dword[ebp-4],MAXSTRINGS
  96.     jbe  .noypos
  97.     mov  dword[ebp-4],MAXSTRINGS
  98.     lea  esi,[ebp+80]
  99.     mov  edi,ebp
  100.     mov  ecx,80*(MAXSTRINGS)
  101.     cld
  102.     rep  movsb
  103.  
  104.     mov  esi,[ebp-4]
  105.     imul esi,80
  106.     add  esi,[ebp-8]
  107.     add  esi,ebp
  108.     mov  ecx,80
  109.     xor  al,al
  110.     rep  stosb
  111.   .noypos:
  112.     mov  [targ],text2
  113.     and  [krnl_cnt],0
  114.     jmp  new_check
  115.   no10:
  116.     cmp  ebp,text1
  117.     je   add2
  118.                 mov  ecx,[krnl_cnt]
  119.                   cmp  al,[krnl_msg+ecx]
  120.                 jne  .noknl
  121.                   inc  [krnl_cnt]
  122.                 cmp  [krnl_cnt],4
  123.                 jne  new_check
  124.     mov  [targ],text1
  125.         .noknl:
  126.     mov  ebp,[targ]
  127.            jecxz .add
  128.     push eax
  129.     mov  esi,krnl_msg
  130.    .l1:
  131.     lodsb
  132.     call add_char
  133.     loop .l1
  134.     pop  eax
  135.    .add:
  136.     and  [krnl_cnt],0
  137.   add2:
  138.     call add_char
  139.  
  140.   new_check:
  141.  
  142.     mov  eax,63
  143.     mov  ebx,2
  144.     int  0x40
  145.  
  146.     cmp  ebx,1
  147.     je   new_data
  148.  
  149.     cmp  [vmode],2
  150.     je   still
  151.     call draw_window
  152.  
  153.     jmp  still
  154.  
  155.   ipc:
  156.     mov  [vmode],2
  157.     mov  eax,ipcbuff
  158.     mov  esi,[eax+8]
  159.     mov  byte[eax],1
  160.     push dword[eax+12]
  161.     pop  [dump_len]
  162.     mcall 9,work,-1
  163.     mov  ecx,eax
  164.    .lp:
  165.     mcall 9
  166.     cmp  [ebx+30],esi
  167.     je   .ok
  168.     loop .lp
  169.     and  [dump_len],0
  170.     jmp  red
  171.   .ok:
  172.     mov  [pid],esi
  173.     lea  esi,[ebx+10]
  174.     mov  edi,dump_title+10
  175.     mov  ecx,12
  176.     rep  movsb
  177.     jmp  red
  178.   key:                          ; key
  179.     mov  eax,2                  ; just read it and ignore
  180.     int  0x40
  181.     cmp  ah,' '
  182.     je   button.no_krnl_flt
  183.     cmp  [vmode],2
  184.     jne  still
  185.     cmp  ah,176 ;left
  186.     jb   still
  187.     cmp  ah,179 ;right
  188.     ja  still
  189.     mov  ecx,[offs]
  190.     shr  eax,8
  191.     sub  eax,176
  192.     add  ecx,[arrows+eax*4]
  193.     shl  ecx,12
  194.     shr  cx,12
  195.     jmp  button.check_sel
  196.   .nol:
  197.     jmp  still
  198.  
  199. arrows dd -1,16,-16,1
  200.  
  201.   button:                       ; button
  202.     mov  eax,17                 ; get id
  203.     int  0x40
  204.  
  205.     cmp  ah,1                   ; button id=1 ?
  206.     jne  .noclose
  207.  
  208.     mov  eax,-1                 ; close this program
  209.     int  0x40
  210.   .noclose:
  211.         shr  eax,8
  212.                 cmp  eax,10
  213.                 jb   .nodump
  214.                   lea  edi,[eax-10]
  215.                 mcall 37,1
  216.                   sub  eax,[edi*4+dump_cell_marg]
  217.                 sub  eax,TMARGIN+VSPACE
  218.                 push eax
  219.     and  eax,0xffff
  220.                   xor  edx,edx
  221.                 div  word[edi*4+dump_cell_size+2]
  222.                   mov  ecx,eax
  223.     shl  ecx,16
  224.                 xor  edx,edx
  225.                   pop  eax
  226.                 shr  eax,16
  227.                 div  word[edi*4+dump_cell_size]
  228.                 mov  cx,ax
  229.   .check_sel:
  230.                 mov  eax,ecx
  231.     shl  ax,12
  232.     shr  eax,12
  233.     inc  eax
  234.     cmp  eax,[dump_len]
  235.     ja   still;.nosel
  236.     mov  dword[sel_byte],ecx
  237.     dec  eax
  238.     mov  [offs],eax
  239.     jmp  red
  240.  
  241.   .nodump:
  242.     cmp  eax,2
  243.     jne  .no_krnl_flt
  244.     xor  [flag],FL_KRNL
  245.     jmp  still
  246.   .no_krnl_flt:
  247.     mov  [ipcbuff+4],8
  248.     and  byte[ipcbuff],0
  249.     inc  [vmode]
  250.     cmp  [vmode],3
  251.     jb   .vmok
  252.     and  [vmode],0
  253.   .vmok:
  254.     jmp  red
  255.  
  256. add_char:
  257.     push esi
  258.     mov  esi,[ebp-4]
  259.     imul esi,80
  260.     add  esi,[ebp-8]
  261.     mov  [ebp+esi],al
  262.     inc  dword[ebp-8]
  263.     cmp  dword[ebp-8],80
  264.     jb   .ok
  265.     mov  dword[ebp-8],79
  266.   .ok:
  267.     pop  esi
  268.     ret
  269.  
  270. ;   *********************************************
  271. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  272. ;   *********************************************
  273.  
  274.  
  275. draw_window:
  276.  
  277.     mov  eax,48
  278.     mov  ebx,3
  279.     mov  ecx,sc
  280.     mov  edx,sizeof.system_colors
  281.     int  0x40
  282.  
  283.     mov  eax,12                    ; function 12:tell os about windowdraw
  284.     mov  ebx,1                     ; 1, start of draw
  285.     int  0x40
  286.  
  287.                                    ; DRAW WINDOW
  288.     mov  eax,0                     ; function 0 : define and draw window
  289. ;   mov  ebx,50*65536+400          ; [x start] *65536 + [x size]
  290.     mov  ebx,[xstart]
  291.     mov  ecx,MAXSTRINGS*10+45      ; [y start] *65536 + [y size]
  292.     mov  edx,[sc.work]             ; color of work area RRGGBB,8->color gl
  293.     or   edx,0x13000000
  294.     mov  edi,header                ; WINDOW LABEL
  295.     int  0x40
  296.    
  297.     mov  ecx,4
  298.     mov  esi,[sc.work]
  299.     mov  ebx,316 shl 16+5*6
  300.     mov  edx,3;+1 shl 30
  301.     mcall 8,,<5,12>
  302.     mov  edx,[vmode]
  303.     lea  edx,[edx*4+duk]
  304.     mcall 4,<320,8>,,,4
  305.  
  306.     cmp  [vmode],2
  307.     je   no_mdbg
  308.     mov  ebx,15*65536+33           ; draw info text with function 4
  309.     mov  ecx,[sc.work_text]
  310.     mov  edx,text1
  311.     cmp  [vmode],0
  312.     je   .kern
  313.     mov  edx,text2
  314.   .kern:
  315.     mov  esi,80
  316.   newline:
  317.     mov  eax,4
  318.     int  0x40
  319.     add  ebx,10
  320.     add  edx,80
  321.     cmp  [edx],byte 'x'
  322.     jne  newline
  323.     jmp  enddraw
  324.   no_mdbg:
  325.   if DUMP_TEST eq 1
  326.     mov  esi,0
  327.     mov  [dump_len],100;IPC_BUF
  328.   else
  329.     mov  esi,ipcbuff+16
  330.   end if
  331.     mov  ecx,[dump_len]
  332.     call dump_btn
  333.                 call draw_dump
  334.                 enddraw:
  335.     mov  eax,12                    ; function 12:tell os about windowdraw
  336.     mov  ebx,2                     ; 2, end of draw
  337.     int  0x40
  338.  
  339.     ret
  340.  
  341. if DR_GRID eq 1
  342. draw_grid:
  343.   mov  ecx,11
  344.   mov  edi,(TMARGIN+VSPACE)shl 16+TMARGIN+VSPACE
  345.  .l1:
  346.   push ecx
  347.   mov  ebx,LMARGIN shl 16+LMARGIN+16*HSPACE
  348.   mcall 38,,edi,0
  349.   add  edi,VSPACE shl 16+VSPACE
  350.   pop  ecx
  351.   loop .l1
  352.   mov  ecx,17
  353.   mov  edi,(TMARGIN+VSPACE)shl 16+TMARGIN+VSPACE*10
  354.   mov  ebx,LMARGIN shl 16+LMARGIN
  355.  .l2:
  356.   push ecx
  357.   mcall 38,,edi,0
  358.   add  ebx,HSPACE shl 16+HSPACE
  359.   pop  ecx
  360.   loop .l2
  361.   ret
  362. end if
  363.  
  364. draw_numbers:
  365.   mcall 4,(LMARGIN+2) shl 16+180,0,numb,numb_len-numb
  366.   mov  eax,dword[sel_byte]
  367.   shl  ax,12
  368.   shr  eax,12
  369.   mov  edi,eax
  370. if ~ DUMP_TEST eq 1
  371.   add  edi,ipcbuff+16
  372. end if
  373.   mov  edx,(LMARGIN+2+6*6)shl 16+180
  374.   mov  ebx,0x30000
  375.   movzx ecx,byte[edi]
  376.   mcall 47,,,,0x4e00e7
  377.   add  ebx,0x20000
  378.   add  edx,(6*10)shl 16
  379.   movzx ecx,word[edi]
  380.   mcall
  381.   add  ebx,0x50000
  382.   add  edx,(6*13)shl 16
  383.   mov  ecx,[edi]
  384.   mcall
  385.   mov  ebx,0x80100
  386.   add  edx,(6*19)shl 16
  387.   mcall
  388. .ex:
  389.   ret
  390.  
  391. draw_dump:
  392. ; esi - data ptr, ecx - length
  393.   jecxz draw_numbers.ex
  394.   pusha
  395.   call draw_numbers
  396.   mcall 4,(LMARGIN+2) shl 16+27,0,dump_title,dump_t_len-dump_title
  397.   mcall 47,0x30101,ipcbuff+8,(LMARGIN+2+6*29)shl 16+27
  398.   add   edx,(6*27) shl 16
  399.   mov   ecx,offs
  400.   mcall
  401.   sub   edx,(5*6)shl 16
  402.   mcall ,0x30001
  403.   mov  ecx,16
  404.   mov  edi,HSPACE shl 16
  405.   mov  ebx,(LMARGIN+5)shl 16+42
  406.   call draw_marks
  407.   mov  ecx,[esp+24]
  408.   dec  ecx
  409.   shr  ecx,4
  410.   inc  ecx
  411.   mov  ebx,(LMARGIN-10)shl 16+TMARGIN+2+VSPACE
  412.   mov  edi,VSPACE
  413.   call draw_marks
  414.   popa
  415.                 mov  edx,TMARGIN+2
  416.                 mov  edi,ecx
  417.         .lp:   
  418.                 add  edx,(LMARGIN+2) shl 16+VSPACE
  419.                 mov  ecx,16
  420.                 cmp  edi,ecx
  421.                 jae  .less
  422.                 mov  ecx,edi
  423.         .less: 
  424.                 sub  edi,ecx
  425.                 push esi ecx
  426.                 mov  ebx,0x20100
  427.         .lp1:  
  428.                 push ecx esi
  429.                 movzx ecx,byte[esi]
  430.                 mcall 47,,,,0
  431.                 add  edx,HSPACE shl 16
  432.                 pop  esi ecx
  433.                 inc  esi
  434.                 loop .lp1
  435.                 pusha
  436.                 mov  ebx,edx
  437.                 and  ebx,0xffff
  438.                 add  ebx,(LMARGIN+16*HSPACE+15)shl 16
  439.                 mov  edx,[esp+36]
  440.                 mov  esi,[esp+32]
  441.                 mcall 4,,0
  442.                 popa
  443.                 add  esp,8
  444.                 and  edx,0xffff
  445.                 test edi,edi
  446.                 jnz  .lp
  447. .ex:
  448.                 ret
  449.  
  450. draw_marks:
  451. ; ebx -xy, edi-addition, ecx -cycles
  452.                 pusha
  453.   mov  edx,__hexdigits
  454.   mov  eax,4
  455.   mov  esi,1
  456. .tt:
  457.   push ecx
  458.   mcall ,,0xffffff
  459.   add  ebx,edi
  460.   inc  edx
  461.   pop  ecx
  462.   loop .tt
  463.   popa
  464.   ret
  465.  
  466. dump_btn: ; ecx-length
  467.   jecxz draw_dump.ex
  468.                 pusha
  469.                 test ecx,0xffff
  470.                 je   .even
  471.                 add  ecx,16
  472.         .even: 
  473.                 shr  ecx,4
  474.                 imul ecx,VSPACE
  475.                 add  ecx,(TMARGIN+VSPACE)shl 16-5
  476.                 mcall 8,LMARGIN shl 16+16*HSPACE-5,,10+3 shl 29,[sc.work]
  477.                 inc  edx
  478.                 mcall ,(LMARGIN+16*HSPACE+15)shl 16+6*16
  479.                 mov  edx,0xff0000
  480.                 mov  esi,dump_cell_size
  481.                 xor  eax,eax
  482.                 movzx ebx,[sel_byte]
  483.                 lodsw
  484.                 imul bx,ax
  485.                 shl  ebx,16
  486.                 lea  ebx,[ebx+eax+LMARGIN shl 16]
  487.                 movzx ecx,[sel_byte+2]
  488.                 lodsw
  489.                 imul cx,ax
  490.                 shl  ecx,16
  491.                 lea  ecx,[ecx+eax+(TMARGIN+VSPACE) shl 16]
  492.                 mcall 13
  493.                 movzx ebx,[sel_byte]
  494.                 lodsw
  495.                 imul bx,ax
  496.                 shl  ebx,16
  497.                 lea  ebx,[ebx+eax+(LMARGIN+16*HSPACE+15)shl 16]
  498.   mcall 13
  499.                 popa
  500. .ex:
  501.                 ret            
  502.  
  503. krnl_msg db 'K : '
  504. duk db 'KernUserDump'
  505. numb db 'Byte:     Word:       Dword:               Hex:'
  506. numb_len:
  507. dump_title db 'Dump from              (pid=    h)         Offset:     (   h)'
  508. dump_t_len:
  509.  
  510. ; DATA AREA
  511.  
  512. dump_cell_marg dd LMARGIN shl 16,(LMARGIN+16*HSPACE+15)shl 16
  513. dump_cell_size dw HSPACE,VSPACE,6,VSPACE
  514. ; 11,11 > 0,-1
  515. ; 5,11  > 0,-1
  516. if lang eq ru
  517.    header    db   '„Ž‘Š€ Ž’‹€„Šˆ ˆ ‘ŽŽ™…ˆ‰',0
  518. else if lang eq en
  519.    header    db   'GENERAL DEBUG & MESSAGE BOARD',0
  520. else
  521.    header    db   'ALLGEMEINES DEBUG- & NACHRICHTENBOARD',0
  522. end if
  523.    krnl_cnt dd 0
  524.    vmode dd 0
  525.    targ  dd text2
  526. I_END:
  527.      offs dd ?
  528.      flag rb 1
  529.      ipcbuff rb IPC_BUF+20
  530.      rd 2
  531. ;     x1pos  dd ?
  532. ;     y1pos  dd ?
  533.      text1 rb 80*(MAXSTRINGS+1)
  534.      tmp1  db ?
  535.      rd 2
  536. ;     x2pos  dd ?
  537. ;     y2pos  dd ?
  538.      text2 rb 80*(MAXSTRINGS+1)
  539.      tmp2  db ?
  540.      work rb 4096
  541.      sel_byte  dw ?,?
  542.      pid  dd ?
  543.      xstart dd ?
  544.      dump_len dd ?
  545.      sc system_colors
  546. i_end:
  547.