Macros.asm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ;--------------------------------------------------------------------------------------------------pointer macros
  2. dpt equ dword ptr
  3. wpt equ word ptr
  4. bpt equ byte ptr
  5. ;--------------------------------------------------------------------------------------------------clear register
  6. ; Clear a register
  7. clear macro reg
  8. xor reg,reg
  9. endm
  10. ;--------------------------------------------------------------------------------------------------conditional jumps
  11. ; Jump if register=0
  12. jife macro reg,label
  13. or reg,reg
  14. je label
  15. endm
  16. ; Jump if regester!=0
  17. jifne macro reg,label
  18. or reg,reg
  19. jne label
  20. endm
  21. ;--------------------------------------------------------------------------------------------------fast loop macro
  22. floop macro one,two
  23. ; It appears that dec reg, jne is faster than loop!
  24. ; loop 11+m
  25. ; dec reg32 2
  26. ; jne 7+m
  27. ifnb <two> ;form floop register,label
  28. dec one
  29. jne two
  30. else ;form floop label (register=ecx)
  31. dec ecx
  32. jne one
  33. endif
  34. endm
  35. ;--------------------------------------------------------------------------------------------------fetch_compact
  36. fetch_compact macro reg
  37. ; Load a register with a compact address
  38. ifndef fetch_compact_esi
  39. extrn fetch_compact_esi:near
  40. endif
  41. ifnb <reg>
  42. push esi
  43. endif
  44. call fetch_compact_esi
  45. ifnb <reg>
  46. mov reg,esi
  47. pop esi
  48. endif
  49. endm
  50. ;--------------------------------------------------------------------------------------------------Dos interrupts
  51. screen_int macro
  52. int 10h
  53. endm
  54. dos_int macro
  55. int 21h
  56. endm
  57. disk_int macro
  58. int 21h
  59. endm
  60. mouse_int macro num
  61. mov ax,num
  62. int 33h
  63. endm
  64. program_error macro num
  65. ifndef error_routine
  66. extrn error_routine:near
  67. endif
  68. mov eax,num
  69. call error_routine
  70. endm
  71. ;--------------------------------------------------------------------------------------------------lodsd lookalike
  72. flodsd macro dest,source
  73. mov dest,dword ptr [source]
  74. add source,4
  75. endm
  76. flodsws macro dest,source ;load word register
  77. mov dest,word ptr [source]
  78. add source,2
  79. endm
  80. flodswl macro dest,source ;load long register from word
  81. movzx dest,word ptr [source]
  82. add source,2
  83. endm
  84. ;--------------------------------------------------------------------------------------------------fetch_item
  85. fetch_item macro dest,source
  86. ifnb<source>
  87. mov dest,[offset item_list+source*4]
  88. else
  89. ifnb <dest>
  90. mov dest,[offset item_list+eax*4]
  91. else
  92. mov esi,[offset item_list+eax*4]
  93. endif
  94. endif
  95. endm
  96. ;--------------------------------------------------------------------------------------------------push_all
  97. push_all macro
  98. push ds
  99. push es
  100. pushad
  101. endm
  102. pop_all macro
  103. popad
  104. pop es
  105. pop ds
  106. endm
  107. ;--------------------------------------------------------------------------------------------------
  108. load_fixed macro num
  109. mov eax,num
  110. clear edx
  111. call load_file
  112. mov [item_list + num * 4],eax
  113. endm
  114. ;--------------------------------------------------------------------------------------------------
  115. open_file macro name,error_mes
  116. local err_lab
  117. mov ax,3d00h
  118. mov edx,offset name
  119. disk_int
  120. jnc err_lab
  121. program_error error_mes
  122. err_lab:
  123. endm
  124. close_file macro
  125. mov ah,3eh
  126. disk_int
  127. endm
  128. ;--------------------------------------------------------------------------------------------------load_to
  129. load_to macro num,dest
  130. mov eax,num
  131. clear edx
  132. call load_file
  133. mov dest,eax
  134. endm
  135. free_clr2 macro addr
  136. mov eax,addr
  137. call my_free
  138. mov addr,0
  139. endm
  140. free_if_n0 macro addr
  141. local not_aloc
  142. mov eax,[addr]
  143. jife eax,not_aloc
  144. call my_free
  145. mov [addr],0
  146. not_aloc:
  147. endm
  148.