Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; macros to write stuff to menuet's debug message board.
  2. ; the macros don't change any registers, not even flags.
  3. ; they take only effect if DEBUG is defined.
  4. ;
  5. ; Copyright (c) 2003 Thomas Mathys
  6. ; killer@vantage.ch
  7. ;
  8. ; This program is free software; you can redistribute it and/or modify
  9. ; it under the terms of the GNU General Public License as published by
  10. ; the Free Software Foundation; either version 2 of the License, or
  11. ; (at your option) any later version.
  12. ;
  13. ; This program is distributed in the hope that it will be useful,
  14. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ; GNU General Public License for more details.
  17. ;
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21. ;
  22. %ifndef _DBGBOARD_INC
  23. %define _DBGBOARD_INC
  24.  
  25.  
  26. %ifdef DEBUG
  27.  
  28.  
  29. ;********************************************************************
  30. ;       print newline
  31. ;       no input
  32. ;********************************************************************
  33. %macro DBG_BOARD_PRINTNEWLINE 0
  34.         call    dbg_board_printnewline
  35. %endm
  36.  
  37.  
  38. ;********************************************************************
  39. ;       print a character
  40. ;
  41. ;       examples        :       DBG_BOARD_PRINTCHAR '?'
  42. ;                               DBG_BOARD_PRINTCHAR 65
  43. ;                               DBG_BOARD_PRINTCHAR cl
  44. ;                               DBG_BOARD_PRINTCHAR [esi]
  45. ;                               DBG_BOARD_PRINTCHAR [somevariable]
  46. ;********************************************************************
  47. %macro DBG_BOARD_PRINTCHAR 1
  48.         push    ecx
  49.         mov     cl,byte %1
  50.         call    dbg_board_printchar
  51.         pop     ecx
  52. %endm
  53.  
  54.  
  55.  
  56. ;********************************************************************
  57. ;       print a dword (in hex)
  58. ;
  59. ;       examples:       DBG_BOARD_PRINTDWORD esp
  60. ;                       DBG_BOARD_PRINTDWORD 0xdeadbeef
  61. ;                       DBG_BOARD_PRINTDWORD [somevariable]
  62. ;********************************************************************
  63. %macro DBG_BOARD_PRINTDWORD 1
  64.         push    dword %1
  65.         call    dbg_board_printdword
  66. %endm
  67.  
  68.  
  69. ;********************************************************************
  70. ;       print a string literal
  71. ;       a terminating zero is automagically appended to the string.
  72. ;
  73. ;       examples        DBG_BOARD_PRINTSTRINGLITERAL "foo",0
  74. ;                       DBG_BOARD_PRINTSTRINGLITERAL "bar",10,13,0
  75. ;********************************************************************
  76. %macro DBG_BOARD_PRINTSTRINGLITERAL 1+
  77.         jmp     %%bar
  78. %%foo   db      %1, 0           ; terminate string, just to be sure
  79. %%bar:
  80.         push    dword %%foo
  81.         call    dbg_board_printstring
  82. %endm
  83.  
  84.  
  85. ;********************************************************************
  86. ;       print a string (asciiz)
  87. ;
  88. ;       examples        DBG_BOARD_PRINTSTRING addressofstring
  89. ;                       DBG_BOARD_PRINTSTRING esi
  90. ;                       DBG_BOARD_PRINTSTRING [ebx]
  91. ;********************************************************************
  92. %macro DBG_BOARD_PRINTSTRING 1
  93.         push    dword %1
  94.         call    dbg_board_printstring
  95. %endm
  96.  
  97.  
  98. ; no input
  99. dbg_board_printnewline:
  100.         pushad
  101.         pushfd
  102.         mov     eax,MOS_SC_DEBUGBOARD
  103.         mov     ebx,1
  104.         mov     ecx,10
  105.         int     0x40
  106.         mov     ecx,13
  107.         int     0x40
  108.         popfd
  109.         popad
  110.         ret
  111.        
  112.        
  113. ; input : cl = character to print
  114. dbg_board_printchar:
  115.         pushad
  116.         pushfd
  117.         mov     eax,MOS_SC_DEBUGBOARD
  118.         mov     ebx,1
  119.         and     ecx,0xff
  120.         int     0x40
  121.         popfd
  122.         popad
  123.         ret
  124.  
  125.        
  126. ; input : dword to print on stack
  127. dbg_board_printdword:
  128.         enter   0,0
  129.         pushad
  130.         pushfd 
  131.         mov     eax,MOS_SC_DEBUGBOARD
  132.         mov     ebx,1
  133.         mov     ecx,'0'                 ; print 0x prefix
  134.         int     0x40
  135.         mov     ecx,'x'
  136.         int     0x40
  137.         mov     edx,[ebp + 8]           ; get dword to print
  138.         mov     esi,8                   ; iterate through all nibbles
  139. .loop:
  140.         mov     ecx,edx                 ; display hex digit
  141.         shr     ecx,28
  142.         movzx   ecx,byte [dbg_board_printdword_digits + ecx]
  143.         int     0x40
  144.         shl     edx,4                   ; next nibble
  145.         dec     esi
  146.         jnz     .loop
  147.         popfd
  148.         popad
  149.         leave
  150.         ret     4
  151. dbg_board_printdword_digits:
  152.         db      '0','1','2','3','4','5','6','7'
  153.         db      '8','9','a','b','c','d','e','f'
  154.  
  155.        
  156. ; input : address of string (asciiz) to print on stack
  157. dbg_board_printstring:
  158.         enter   0,0
  159.         pushad
  160.         pushfd
  161.         cld
  162.         mov     esi,[ebp + 8]           ; esi -> string
  163.         mov     ebx,1
  164. .loop:
  165.         lodsb                           ; get character
  166.         or      al,al                   ; zero ?
  167.         je      .done                   ; yeah -> get outta here
  168.         movzx   ecx,al                  ; nope -> display character
  169.         mov     eax,MOS_SC_DEBUGBOARD
  170.         int     0x40
  171.         jmp     .loop
  172. .done:
  173.         popfd
  174.         popad
  175.         leave
  176.         ret     4
  177.        
  178. %else
  179.  
  180.  
  181. %macro DBG_BOARD_PRINTNEWLINE 0
  182. %endm
  183.  
  184. %macro DBG_BOARD_PRINTCHAR 1
  185. %endm
  186.  
  187. %macro DBG_BOARD_PRINTDWORD 1
  188. %endm
  189.  
  190. %macro DBG_BOARD_PRINTSTRINGLITERAL 1+
  191. %endm
  192.  
  193. %macro DBG_BOARD_PRINTSTRING 1
  194. %endm
  195.  
  196. %endif
  197.  
  198.  
  199. %endif
  200.  
  201.