home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / z80macro.lbr / Z80MACRO.DZC / Z80MACRO.DOC
Encoding:
Text File  |  1993-10-25  |  7.6 KB  |  163 lines

  1. Z80MACRO.DOC
  2. 06/26 09:26.17
  3.  
  4. Documentatioε fo≥ Z80MACRO.LIB¼ ß macr∩ librar∙ createΣ ì
  5. especiall∙ fo≥ usσ witΦ thσ publiπ domaiε assemble≥ Z80MRì
  6. distributeΣ b∙ Micr∩ Cornucopia.
  7.  
  8. Contributed by:        Rich Brewster
  9.             R.D.1
  10.             Brackney, PA 18812
  11.             (717) 663-2048
  12.  
  13.      Whilσ iε graduatσ schoo∞ studyinτ philosophy¼ ╔ needeΣ ß wa∙  ì
  14. t∩ relax¼ s∩ ╔ pickeΣ u≡ ß cop∙ oµ Alaε R« Miller'≤ "Masterinτ ì
  15. CP/M"«  ╔ haΣ beeε programminτ ß Sinclai≥ ZX8▒ iε machinσ codσ ì
  16. anΣ s∩ ╔ wa≤ familia≥ witΦ thσ Z80«  ╔ als∩ haΣ ß chancσ t∩ ì
  17. becomσ familia≥  witΦ CP/═ iε ß previou≤ job¼ wherσ ╔ ì
  18. occasionall∙ useΣ M8░ anΣ L80«  CombineΣ witΦ m∙ Kaypr∩ 4-84¼ anΣ ì
  19. thσ Z80M╥ assemble≥ froφ Micr∩ C¼ Miller'≤ booδ provideΣ aε ì
  20. interestinτ challenge.
  21.  
  22.      "Masterinτ CP/Mó i≤ ß successioε oµ chapter≤ involvinτ ì
  23. increasingl∙ comple° operation≤ utilizinτ CP/═ BDO╙ calls«  EacΦ ì
  24. chapte≥ introduce≤ ß se⌠ oµ macro≤ t∩ adΣ t∩ ß library¼ alonτ ì
  25. witΦ somσ tes⌠ o≥ applicatioε program≤ writteε usinτ thosσ ì
  26. macros«  It'≤ assumeΣ tha⌠ yo⌡ havσ Digita∞ Research'≤ MA├ ì
  27. assembler¼ o≥ Microsoft'≤ MACRO-80«  Al∞ oµ thσ mnemonic≤ arσ ì
  28. 8080«  S∩ ╔ haΣ t∩ translatσ int∩ Z8░ mnemonic≤ anΣ worδ withiε ì
  29. thσ limit≤ oµ Z80MR¼ whicΦ ha≤ ß fe≈ les≤ bell≤ anΣ whistles.
  30.  
  31.      M∙ aiφ wa≤ t∩ learε CP/M¼ assembl∙ languagσ programming¼ anΣ ì
  32. t∩ winΣ u≡ witΦ ß nicσ macr∩ library«  ╔ seeφ t∩ havσ ì
  33. accomplisheΣ thosσ goals¼ anΣ a≤ ß bonu≤ I'vσ turneΣ u≡ ß fe≈ ì
  34. bug≤ iε Mr« Miller'≤ code¼ a≤ wel∞ a≤ ß buτ iε Z80MR«  Oε thσ ì
  35. wholσ I'φ quitσ happ∙ witΦ Z80MR¼ bu⌠ disappointeΣ iε Miller'≤ ì
  36. book«  Hσ coulΣ no⌠ havσ actuall∙ assembleΣ anΣ testeΣ al∞ oµ hi≤ ì
  37. programs¼ becausσ somσ oµ theφ d∩ no⌠ worδ a≤ the∙ stand«  Still¼ ì
  38. i⌠ wa≤ ß gooΣ exercisσ fo≥ me¼ routinτ ou⌠ hi≤ errors.
  39.  
  40.      M∙ maiε criticisφ oµ Miller'≤ codinτ i≤ tha⌠ hσ use≤ ß lo⌠ ì
  41. oµ ver∙ genera∞ term≤ a≤ label≤ o≥ paramete≥ names¼ fo≥ instance║ ì
  42. "POINTRó anΣ "WHERE"¼ anΣ hσ i≤ no⌠ ver∙ consisten⌠ iε thσ forφ ì
  43. oµ hi≤ macros«  ╔ havσ madσ thσ librar∙ a≤ structurall∙ forma∞ a≤ ì
  44. possible¼ anΣ thσ convention≤ ╔ establisheΣ arσ listeΣ below«  ì
  45. I'vσ substituteΣ morσ meaningfu∞ term≤ iε man∙ cases«  Miller'≤ ì
  46. format≤ arσ stil∞ followeΣ fairl∙ closel∙ fo≥ thσ mos⌠ part¼ iµ ì
  47. someonσ wishe≤ t∩ usσ thσ booδ alonτ witΦ Z80MACRO.LIB«  Bu⌠ ì
  48. perhap≤ it'≤ jus⌠ a≤ wel∞ t∩ examinσ thσ librar∙ anΣ forge⌠ abou⌠ ì
  49. thσ book«  I'vσ madσ s∩ man∙ improvement≤ herσ anΣ therσ tha⌠ ╔ ì
  50. can'⌠ possibl∙ documen⌠ theφ all«  EacΦ subroutinσ embeddeΣ iε ß ì
  51. macr∩ ha≤ beeε optimizeΣ fo≥ thσ Z80«  A≤ ß result¼ thi≤ codσ ì
  52. won'⌠ worδ oε 808░ machines.
  53.  
  54.  
  55.  
  56. è     Thσ bigges⌠ drawbacδ oµ Z80M╥ wa≤ thσ lacδ oµ ß tes⌠ fo≥ ì
  57. nul∞ parameter≤ iε macros«  Iµ ß paramete≥ i≤ lef⌠ out¼ theε ì
  58. therσ i≤ simpl∙ nothinτ (ß null⌐ substituted«  S∩ al∞ thσ macro≤ ì
  59. havσ mandator∙ parameters«  Thi≤ requiremen⌠ resulteΣ iε thσ ì
  60. greates⌠ departurσ froφ Alaε Miller'≤ coding«  ╔ spen⌠ ß lo⌠ oµ ì
  61. timσ developinτ thσ followinτ typσ oµ kludge:
  62.  
  63. MACRO   MULT    #TWOS
  64.         IF      #TWOS
  65.         LD      B,#TWOS
  66.         ENDIF
  67.   ...
  68.         ENDM
  69.  
  70.      Tha⌠ wa∙ ß ░ (zero)¼ o≥ somσ expressioε evaluatinτ t∩ zero¼ ì
  71. coulΣ servσ t∩ simulatσ ß nul∞ parameter¼ a≤ lonτ a≤ thσ valuσ ì
  72. zer∩ itselµ wa≤ no⌠ needeΣ a≤ thσ actua∞ parameter«  Thi≤ seemeΣ ì
  73. likσ sucΦ ß shar≡ ideß tha⌠ ╔ haΣ man∙ oµ thσ macro≤ emplo∙ it«  ì
  74. Bu⌠ theε ╔ founΣ ou⌠ tha⌠ someho≈ afte≥ Z80M╥ haΣ encountereΣ to∩ ì
  75. man∙ oµ thesσ structure≤, whicΦ combinσ ß conditiona∞ tes⌠ witΦ ß ì
  76. macr∩ parameter¼ phasσ error≤ begaε happeninτ iε grea⌠ ì
  77. proliferation«  Probabl∙ ß tablσ oµ addresse≤ haΣ overflowed«  ì
  78. Thσ onl∙ fi° wa≤ t∩ eliminatσ mos⌠ oµ thσ structures¼ whicΦ ╔ ì
  79. did«  Somσ oµ thσ macros¼ fo≥ instancσ SYSF¼ MUL╘ anΣ EXIT¼ stil∞ ì
  80. emplo∙ it«  Truσ nul∞ paramete≥ testinτ shoulΣ bσ added.
  81.  
  82.      Aε enhancemen⌠ tha⌠ ╔ though⌠ woulΣ bσ nicσ (althougΦ ╔ go⌠ ì
  83. b∙ O╦ withou⌠ it⌐ woulΣ bσ thσ additioε oµ logica∞ operator≤ ì
  84. (insteaΣ oµ jus⌠ thσ relationa∞ operators⌐ iε conditiona∞ ì
  85. assembly«  Bu⌠ oε thσ wholσ Z80M╥ i≤ ß finσ assemble≥ anΣ ì
  86. is in complience witΦ thσ Ziloτ assemble≥ specification.
  87.  
  88.  
  89.                     --- Z80MACRO.LIB Format ---
  90.  
  91.  
  92.      Severa∞ forma∞ rule≤ werσ followeΣ iε thσ generatioε oµ thσ ì
  93. library«  Thσ firs⌠ rulσ i≤ consistenc∙ iε structure«  ThougΦ thσ ì
  94. structurσ ╔ camσ u≡ witΦ ma∙ bσ idiosyncratic¼ i⌠ i≤ fairl∙ ì
  95. consisten⌠ anΣ ough⌠ t∩ bσ easil∙ graspeΣ b∙ an∙ programme≥ ì
  96. alread∙ familia≥ witΦ assembl∙ language«  Thσ genera∞ structurσ ì
  97. ha≤ thσ followinτ elements:
  98.  
  99. 1⌐   ┴ definitioε line, e.g. 'CPATXT  MACRO   #TEXT,#ADDR'.
  100.  
  101. 2)   A comment section describing the macro, and an example.
  102.  
  103. 3⌐   Thσ main par⌠ oµ thσ macro¼ whicΦ wil∞ bσ duplicateΣ eacΦ ì
  104.      time there is a reference to it in a .AZM source file.
  105.  
  106. 4⌐   Aε embedded subroutinσ whicΦ i≤ flaggeΣ fo≥ conditiona∞ ì
  107.      assembly so that it is only assembled once.
  108.  
  109. 5⌐   Aε END═ statement¼ precedeΣ b∙ ß commen⌠ placeΣ t∩ sho≈ thσ ì
  110.      end of the macro in expanded .PRN files.
  111. è
  112. Thesσ rule≤ goverε thσ usσ oµ loca∞ o≥ globa∞ labels in macros:
  113.  
  114. 1)   Iµ ß labe∞ i≤ founΣ iε ß globa∞ subroutine¼ i.e« onσ tha⌠ i≤ ì
  115. áááááflaggeΣ t∩ bσ assembleΣ onl∙ once¼ tha⌠ labe∞ wil∞ bσ ì
  116. áááááglobal¼ anΣ wil∞ havσ ╢ characters¼ thσ las⌠ beinτ '?'«  ì
  117. áááááThi≤ yield≤ meaningfu∞ global≤ insteaΣ oµ needles≤ ì
  118. áááááassembler-generated replacements for local labels.ì
  119.  
  120.      Als∩ thi≤ way¼ wheε writinτ program≤ therσ i≤ n∩ neeΣ t∩ ì
  121. áááááworr∙ tha⌠ ß labe∞ iε thσ prograφ wil∞ duplicatσ onσ iε ß ì
  122. ááááámacro¼ a≤ lonτ a≤ yo⌡ remembe≥ no⌠ t∩ enΣ an∙ label≤ witΦ ß ì
  123. áááááquestioε mark«  ┴ simila≥ conventioε wa≤ followeΣ fo≥ globa∞ ì
  124. ááááálabel≤ whicΦ marδ variables¼ excep⌠ thσ questioε marδ ì
  125. áááááprecede≤ insteaΣ oµ follows«  Thi≤ i≤ shee≥ conventioε anΣ ì
  126. áááááma∙ bσ changeΣ iµ yo⌡ wisΦ b∙ rewritinτ thσ fe≈ occurrence≤ ì
  127. áááááiε Z80MACRO.LIB.
  128.  
  129. 2)   NO MACRO PARAMETERS CAN BE PLACED INSIDE A GLOBAL SUBROUTINE.
  130.  
  131.      Thi≤ i≤ necessar∙ t∩ kee≡ thσ macr∩ repeatable¼ whicΦ i≤ ß ì
  132. ááááágenera∞ specificatioε for al∞ macros«  Tha⌠ is¼ ever∙ macr∩ ì
  133. ááááámus⌠ bσ repeatablσ withiε thσ samσ sourcσ file«  Iµ ß ì
  134. áááááparamete≥ werσ placeΣ insidσ ß globa∞ subroutine¼ theε a ì
  135. áááááseconΣ referencσ oµ tha⌠ macr∩ witΦ differen⌠ parameter≤ ì
  136. áááááwoulΣ resul⌠ iε ß cal∞ t∩ thσ origina∞ subroutine¼ anΣ woulΣ ì
  137. áááááhavσ thσ origina∞ parameters.
  138.  
  139. 3)   Thσ #AROUN─ loca∞ labe∞ shoulΣ bσ placeΣ INSID┼ thσ ì
  140. áááááconditiona∞ assembl∙ oµ thσ subroutinσ if tha⌠ i≤ thσ onlyì
  141. áááááplacσ iε thσ macr∩ whicΦ i⌠ i≤ used«  
  142.  
  143.      Thi≤ save≤ thσ generatioε oµ spuriou≤ loca∞ variables«  Thσ ì
  144. áááááfirs⌠ pas≤ oµ thσ assemble≥ replace≤ al∞ occurrence≤ oµ ì
  145. áááááloca∞ variablσ witΦ sequentiall∙ incrementeΣ labels¼ s∩ ì
  146. ááááátherσ wil∞ bσ GAP╙ iε thσ sequencσ becausσ oµ thi≤ ì
  147. ááááátechnique«  Iµ thi≤ i≤ no⌠ clear¼ jus⌠ examinσ ß .PR╬ file«  ì
  148. áááááI don't think there is any serious impact to this.
  149.  
  150.      Thσ #AROUN─ labe∞ i≤ referenceΣ outsidσ thσ subroutinσ iε ß ì
  151. áááááfew of the macros, for instance CPATXT.
  152.  
  153. Sincσ therσ arσ 2╕ flag≤ anΣ associateΣ routines¼ ╔ createΣ ì
  154. MRFLAGS.╚ a≤ ß heade≥ filσ t∩ *INCLUD┼ iε sourcσ files«  Thi≤ ì
  155. wil∞ initializσ al∞ 2╕ flag≤ t∩ FALSE«  Thσ crosslis⌠ iε ì
  156. MRFLAGS.DO├ wil∞ hel≡ yo⌡ determinσ wha⌠ flag≤ mus⌠ bσ ì
  157. initializeΣ iµ yo⌡ d∩ no⌠ *INCLUD┼ MRFLAGS.H.
  158.  
  159. That'≤ abou⌠ ití  Jus⌠ spenΣ somσ timσ studyinτ ß printou⌠ oµ ì
  160. Z80MACRO.LI┬ beforσ usinτ it«  (┴ 13▓ columε printou⌠ wil∞ makσ ì
  161. the most readable listing.)  Therσ arσ eigh⌠ examplσ .AZ═ file≤ ì
  162. provided¼ althougΦ the∙ d∩ no⌠ usσ al∞ oµ thσ macros«  Therσ ma∙ ì
  163. stil∞ bσ ß fe≈ bugs¼ bu⌠ thosσ examplσ program≤ al∞ assemblσ anΣ ì
  164. RU╬ quitσ well«  Somσ oµ theφ arσ eveε useful!
  165.