ThomasSpeedrunner

s2.macrosetup.asm

May 4th, 2013
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1.  
  2. padding off ; we don't want AS padding out dc.b instructions
  3. listing off ; we don't need to generate anything for a listing file
  4. supmode on ; we don't need warnings about privileged instructions
  5.  
  6.  
  7. paddingSoFar set 0
  8.  
  9. ; 128 = 80h = z80, 32988 = 80DCh = z80unDoC
  10. notZ80 function cpu,(cpu<>128)&&(cpu<>32988)
  11.  
  12. ; make org safer (impossible to overwrite previously assembled bytes) and count padding
  13. ; and also make it work in Z80 code without creating a new segment
  14. org macro address
  15. if notZ80(MOMCPU)
  16. if address < *
  17. if assembleZ80SoundDriver
  18. error "too much stuff before org $\{address} ($\{(*-address)} bytes)"
  19. else
  20. error "too much stuff before org $\{address} ($\{(*-address)} bytes) ... try setting assembleZ80SoundDriver=1 in the asm file"
  21. endif
  22. elseif address > *
  23. paddingSoFar set paddingSoFar + address - *
  24. !org address
  25. endif
  26. else
  27. if address < $
  28. error "too much stuff before org 0\{address}h (0\{($-address)}h bytes)"
  29. else
  30. while address > $
  31. db 0
  32. endm
  33. endif
  34. endif
  35. endm
  36.  
  37. ; define the cnop pseudo-instruction
  38. cnop macro offset,alignment
  39. if notZ80(MOMCPU)
  40. org (*-1+(alignment)-((*-1+(-(offset)))#(alignment)))
  41. else
  42. org ($-1+(alignment)-(($-1+(-(offset)))#(alignment)))
  43. endif
  44. endm
  45.  
  46. ; redefine align in terms of cnop, for the padding counter
  47. align macro alignment
  48. cnop 0,alignment
  49. endm
  50.  
  51. ; define the even pseudo-instruction
  52. even macro
  53. if notZ80(MOMCPU)
  54. if (*)&1
  55. paddingSoFar set paddingSoFar+1
  56. dc.b 0 ;ds.b 1
  57. endif
  58. else
  59. if ($)&1
  60. db 0
  61. endif
  62. endif
  63. endm
  64.  
  65. ; make ds work in Z80 code without creating a new segment
  66. ds macro
  67. if notZ80(MOMCPU)
  68. !ds.ATTRIBUTE ALLARGS
  69. else
  70. rept ALLARGS
  71. db 0
  72. endm
  73. endif
  74. endm
  75.  
  76. if TRUE
  77. ; define a trace macro
  78. ; lets you easily check what address a location in this disassembly assembles to
  79. ; if used in Z80 code, the displayed PC will be relative to the start of Z80 RAM
  80. trace macro optionalMessageWithoutQuotes
  81. if MOMPASS=1
  82. if notZ80(MOMCPU)
  83. if ("ALLARGS"<>"")
  84. message "#\{tracenum/1.0}: line=\{MOMLINE/1.0} PC=$\{*} msg=ALLARGS"
  85. else
  86. message "#\{tracenum/1.0}: line=\{MOMLINE/1.0} PC=$\{*}"
  87. endif
  88. else
  89. if ("ALLARGS"<>"")
  90. message "#\{tracenum/1.0}: line=\{MOMLINE/1.0} PC=\{$}h msg=ALLARGS"
  91. else
  92. message "#\{tracenum/1.0}: line=\{MOMLINE/1.0} PC=\{$}h"
  93. endif
  94. endif
  95. tracenum := (tracenum+1)
  96. endif
  97. endm
  98. else
  99. trace macro
  100. endm
  101. endif
  102. tracenum := 0
  103.  
  104. if zeroOffsetOptimization=0
  105. ; disable a space optimization in AS so we can build a bit-perfect rom
  106. ; (the hard way, but it requires no modification of AS itself)
  107.  
  108.  
  109. chkop function op,ref,(substr(lowstring(op),0,strlen(ref))<>ref)
  110.  
  111. ; 1-arg instruction that's self-patching to remove 0-offset optimization
  112. insn1op macro oper,x
  113. if (chkop("x","0(") && chkop("x","id(") && chkop("x","slot_rout("))
  114. !oper x
  115. else
  116. !oper 1+x
  117. !org *-1
  118. !dc.b 0
  119. endif
  120. endm
  121.  
  122. ; 2-arg instruction that's self-patching to remove 0-offset optimization
  123. insn2op macro oper,x,y
  124. if (chkop("x","0(") && chkop("x","id(") && chkop("x","slot_rout("))
  125. if (chkop("y","0(") && chkop("y","id(") && chkop("y","slot_rout("))
  126. !oper x,y
  127. else
  128. !oper x,1+y
  129. !org *-1
  130. !dc.b 0
  131. endif
  132. else
  133. if chkop("y","d")
  134. if (chkop("y","0(") && chkop("y","id(") && chkop("y","slot_rout("))
  135. start:
  136. !oper 1+x,y
  137. end:
  138. !org start+3
  139. !dc.b 0
  140. !org end
  141. else
  142. !oper 1+x,1+y
  143. !org *-3
  144. !dc.b 0
  145. !org *+1
  146. !dc.b 0
  147. endif
  148. else
  149. !oper 1+x,y
  150. !org *-1
  151. !dc.b 0
  152. endif
  153. endif
  154. endm
  155.  
  156. ; instructions that were used with 0(a#) syntax
  157. ; defined to assemble as they originally did
  158. _move macro
  159. insn2op move.ATTRIBUTE, ALLARGS
  160. endm
  161. _add macro
  162. insn2op add.ATTRIBUTE, ALLARGS
  163. endm
  164. _addq macro
  165. insn2op addq.ATTRIBUTE, ALLARGS
  166. endm
  167. _cmp macro
  168. insn2op cmp.ATTRIBUTE, ALLARGS
  169. endm
  170. _cmpi macro
  171. insn2op cmpi.ATTRIBUTE, ALLARGS
  172. endm
  173. _clr macro
  174. insn1op clr.ATTRIBUTE, ALLARGS
  175. endm
  176. _tst macro
  177. insn1op tst.ATTRIBUTE, ALLARGS
  178. endm
  179.  
  180. else
  181.  
  182. ; regular meaning to the assembler; better but unlike original
  183. _move macro
  184. !move.ATTRIBUTE ALLARGS
  185. endm
  186. _add macro
  187. !add.ATTRIBUTE ALLARGS
  188. endm
  189. _addq macro
  190. !addq.ATTRIBUTE ALLARGS
  191. endm
  192. _cmp macro
  193. !cmp.ATTRIBUTE ALLARGS
  194. endm
  195. _cmpi macro
  196. !cmpi.ATTRIBUTE ALLARGS
  197. endm
  198. _clr macro
  199. !clr.ATTRIBUTE ALLARGS
  200. endm
  201. _tst macro
  202. !tst.ATTRIBUTE ALLARGS
  203. endm
  204.  
  205. endif
Advertisement
Add Comment
Please, Sign In to add comment