Deb_mac.asm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. ; Debugging macros
  2. ;--------------------------------------------------------------------------------------------------Debug a compact
  3. debug_compact macro reg,message,address
  4. local label1,label2
  5. ifdef debug_42
  6. end32code
  7. start32data
  8. ifndef _debug_flag
  9. extrn _debug_flag:dword
  10. endif
  11. label1 db message
  12. db 0
  13. end32data
  14. start32code
  15. extrn _debug_compact__Npcpcpc:near
  16. push_all
  17. bt [_debug_flag],df_debug
  18. jc label2
  19. push reg
  20. push offset label1
  21. ifnb<address>
  22. push offset address
  23. else
  24. push 0
  25. endif
  26. call _debug_compact__Npcpcpc
  27. label2: pop_all
  28. endif
  29. endm
  30. proc_start macro name
  31. name proc
  32. push ebp
  33. mov ebp,esp
  34. push ebx
  35. push esi
  36. push edi
  37. endm
  38. proc_end macro name,ret_val
  39. pop edi
  40. pop esi
  41. pop ebx
  42. pop ebp
  43. ret ret_val
  44. name endp
  45. endm
  46. ;--------------------------------------------------------------------------------------------------cherror
  47. cherror macro reg1,cond,reg2,err_mess
  48. local label1,label2
  49. ifdef debug_42
  50. cmp reg1,reg2
  51. j&cond label1
  52. jmp label2
  53. label1: program_error err_mess
  54. nop
  55. label2:
  56. endif
  57. endm
  58. ;--------------------------------------------------------------------------------------------------debug_route
  59. debug_route macro
  60. local no_debug
  61. ifdef ar_debug
  62. ifndef _debug_flag
  63. end32code
  64. start32data
  65. extrn _debug_flag:dword
  66. end32data
  67. start32code
  68. endif
  69. push_all
  70. bt [_debug_flag],df_ar
  71. jnc no_debug
  72. push [route_grid]
  73. call _debug_route_grid__Nps
  74. no_debug: pop_all
  75. endif
  76. endm
  77. ;--------------------------------------------------------------------------------------------------printf
  78. printf macro format,a,b,c,d
  79. local form_data,no_debug
  80. ifdef debug_42 ;only compile if debug option set
  81. ifndef debug_printf__Bpce ;Ensure printf routine declared
  82. extrn _debug_printf__Bpce:near
  83. endif
  84. end32code
  85. start32data
  86. ;ifndef _debug_flag
  87. ; extrn _debug_flag:dword
  88. ;endif
  89. form_data db format ;put string into data segment
  90. db 0
  91. end32data
  92. start32code
  93. push_all ;save everything
  94. pushf
  95. cld
  96. ; bt [_debug_flag],df_debug
  97. ; jc no_debug
  98. ifnb<d>
  99. push d
  100. endif
  101. ifnb<c>
  102. push c
  103. endif
  104. ifnb<b>
  105. push b
  106. endif
  107. ifnb<a>
  108. push a
  109. endif
  110. push offset form_data
  111. call _debug_printf__Bpce
  112. ifnb<d>
  113. lea esp,4[esp]
  114. endif
  115. ifnb<c>
  116. lea esp,4[esp]
  117. endif
  118. ifnb<b>
  119. lea esp,4[esp]
  120. endif
  121. ifnb<a>
  122. lea esp,4[esp]
  123. endif
  124. lea esp,4[esp]
  125. ;no_debug:
  126. popf
  127. pop_all
  128. endif
  129. endm
  130. ;--------------------------------------------------------------------------------------------------
  131. inform_debug macro cond,text,more
  132. ; If a conditional enabled then print a message to the user
  133. ifdef &cond ;if conditional on
  134. end32code
  135. start32data
  136. &cond&_text db text,13,10,0 ;text + \n
  137. end32data
  138. start32code
  139. ifndef _printf
  140. extrn _printf:near
  141. endif
  142. ifnb<more>
  143. push more
  144. endif
  145. push offset &cond&_text
  146. call _printf ;print text
  147. ifnb<more>
  148. lea esp,8[esp]
  149. else
  150. lea esp,4[esp]
  151. endif
  152. inform_debug_on equ 1 ;enable wait for key code
  153. endif
  154. endm
  155. show_files macro text,reg
  156. ifdef debug_42
  157. push eax
  158. push ebx
  159. push ecx
  160. ifnb <reg>
  161. mov eax,reg
  162. endif
  163. mov ebx,eax
  164. mov ecx,eax
  165. shr ecx,11
  166. and ebx,2047
  167. printf text,ecx,ebx,eax
  168. pop ecx
  169. pop ebx
  170. pop eax
  171. endif
  172. endm
  173. ;--------------------------------------------------------------------------------------------------
  174. ifdef mem_check
  175. free_fixed_item macro num
  176. mov eax,[item_list + num * 4]
  177. call my_free
  178. endm
  179. endif
  180. ;--------------------------------------------------------------------------------------------------border
  181. border macro col
  182. ifdef debug_42
  183. push eax
  184. push edx
  185. mov dx,3DAh
  186. in al,dx
  187. mov dx,3C0h
  188. mov al,11h
  189. out dx,al
  190. mov al,col
  191. out dx,al
  192. mov al,20h
  193. out dx,al
  194. pop edx
  195. pop eax
  196. endif
  197. endm
  198. ;--------------------------------------------------------------------------------------------------call_address
  199. call_address macro
  200. ifdef debug_42
  201. push ebp
  202. mov ebp,esp
  203. push eax
  204. mov eax,4[ebp]
  205. printf "call address %x",eax
  206. pop eax
  207. pop ebp
  208. endif
  209. endm
  210.