Subversion Repositories Kolibri OS

Rev

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