home *** CD-ROM | disk | FTP | other *** search
- Z80MACRO.DOC
- 06/26 09:26.17
-
- Documentatioε fo≥ Z80MACRO.LIB¼ ß macr∩ librar∙ createΣ ì
- especiall∙ fo≥ usσ witΦ thσ publiπ domaiε assemble≥ Z80MRì
- distributeΣ b∙ Micr∩ Cornucopia.
-
- Contributed by: Rich Brewster
- R.D.1
- Brackney, PA 18812
- (717) 663-2048
-
- Whilσ iε graduatσ schoo∞ studyinτ philosophy¼ ╔ needeΣ ß wa∙ ì
- t∩ relax¼ s∩ ╔ pickeΣ u≡ ß cop∙ oµ Alaε R« Miller'≤ "Masterinτ ì
- CP/M"« ╔ haΣ beeε programminτ ß Sinclai≥ ZX8▒ iε machinσ codσ ì
- anΣ s∩ ╔ wa≤ familia≥ witΦ thσ Z80« ╔ als∩ haΣ ß chancσ t∩ ì
- becomσ familia≥ witΦ CP/═ iε ß previou≤ job¼ wherσ ╔ ì
- occasionall∙ useΣ M8░ anΣ L80« CombineΣ witΦ m∙ Kaypr∩ 4-84¼ anΣ ì
- thσ Z80M╥ assemble≥ froφ Micr∩ C¼ Miller'≤ booδ provideΣ aε ì
- interestinτ challenge.
-
- "Masterinτ CP/Mó i≤ ß successioε oµ chapter≤ involvinτ ì
- increasingl∙ comple° operation≤ utilizinτ CP/═ BDO╙ calls« EacΦ ì
- chapte≥ introduce≤ ß se⌠ oµ macro≤ t∩ adΣ t∩ ß library¼ alonτ ì
- witΦ somσ tes⌠ o≥ applicatioε program≤ writteε usinτ thosσ ì
- macros« It'≤ assumeΣ tha⌠ yo⌡ havσ Digita∞ Research'≤ MA├ ì
- assembler¼ o≥ Microsoft'≤ MACRO-80« Al∞ oµ thσ mnemonic≤ arσ ì
- 8080« S∩ ╔ haΣ t∩ translatσ int∩ Z8░ mnemonic≤ anΣ worδ withiε ì
- thσ limit≤ oµ Z80MR¼ whicΦ ha≤ ß fe≈ les≤ bell≤ anΣ whistles.
-
- M∙ aiφ wa≤ t∩ learε CP/M¼ assembl∙ languagσ programming¼ anΣ ì
- t∩ winΣ u≡ witΦ ß nicσ macr∩ library« ╔ seeφ t∩ havσ ì
- accomplisheΣ thosσ goals¼ anΣ a≤ ß bonu≤ I'vσ turneΣ u≡ ß fe≈ ì
- bug≤ iε Mr« Miller'≤ code¼ a≤ wel∞ a≤ ß buτ iε Z80MR« Oε thσ ì
- wholσ I'φ quitσ happ∙ witΦ Z80MR¼ bu⌠ disappointeΣ iε Miller'≤ ì
- book« Hσ coulΣ no⌠ havσ actuall∙ assembleΣ anΣ testeΣ al∞ oµ hi≤ ì
- programs¼ becausσ somσ oµ theφ d∩ no⌠ worδ a≤ the∙ stand« Still¼ ì
- i⌠ wa≤ ß gooΣ exercisσ fo≥ me¼ routinτ ou⌠ hi≤ errors.
-
- M∙ maiε criticisφ oµ Miller'≤ codinτ i≤ tha⌠ hσ use≤ ß lo⌠ ì
- oµ ver∙ genera∞ term≤ a≤ label≤ o≥ paramete≥ names¼ fo≥ instance║ ì
- "POINTRó anΣ "WHERE"¼ anΣ hσ i≤ no⌠ ver∙ consisten⌠ iε thσ forφ ì
- oµ hi≤ macros« ╔ havσ madσ thσ librar∙ a≤ structurall∙ forma∞ a≤ ì
- possible¼ anΣ thσ convention≤ ╔ establisheΣ arσ listeΣ below« ì
- I'vσ substituteΣ morσ meaningfu∞ term≤ iε man∙ cases« Miller'≤ ì
- format≤ arσ stil∞ followeΣ fairl∙ closel∙ fo≥ thσ mos⌠ part¼ iµ ì
- someonσ wishe≤ t∩ usσ thσ booδ alonτ witΦ Z80MACRO.LIB« Bu⌠ ì
- perhap≤ it'≤ jus⌠ a≤ wel∞ t∩ examinσ thσ librar∙ anΣ forge⌠ abou⌠ ì
- thσ book« I'vσ madσ s∩ man∙ improvement≤ herσ anΣ therσ tha⌠ ╔ ì
- can'⌠ possibl∙ documen⌠ theφ all« EacΦ subroutinσ embeddeΣ iε ß ì
- macr∩ ha≤ beeε optimizeΣ fo≥ thσ Z80« A≤ ß result¼ thi≤ codσ ì
- won'⌠ worδ oε 808░ machines.
-
-
-
- è Thσ bigges⌠ drawbacδ oµ Z80M╥ wa≤ thσ lacδ oµ ß tes⌠ fo≥ ì
- nul∞ parameter≤ iε macros« Iµ ß paramete≥ i≤ lef⌠ out¼ theε ì
- therσ i≤ simpl∙ nothinτ (ß null⌐ substituted« S∩ al∞ thσ macro≤ ì
- havσ mandator∙ parameters« Thi≤ requiremen⌠ resulteΣ iε thσ ì
- greates⌠ departurσ froφ Alaε Miller'≤ coding« ╔ spen⌠ ß lo⌠ oµ ì
- timσ developinτ thσ followinτ typσ oµ kludge:
-
- MACRO MULT #TWOS
- IF #TWOS
- LD B,#TWOS
- ENDIF
- ...
- ENDM
-
- Tha⌠ wa∙ ß ░ (zero)¼ o≥ somσ expressioε evaluatinτ t∩ zero¼ ì
- coulΣ servσ t∩ simulatσ ß nul∞ parameter¼ a≤ lonτ a≤ thσ valuσ ì
- zer∩ itselµ wa≤ no⌠ needeΣ a≤ thσ actua∞ parameter« Thi≤ seemeΣ ì
- likσ sucΦ ß shar≡ ideß tha⌠ ╔ haΣ man∙ oµ thσ macro≤ emplo∙ it« ì
- Bu⌠ theε ╔ founΣ ou⌠ tha⌠ someho≈ afte≥ Z80M╥ haΣ encountereΣ to∩ ì
- man∙ oµ thesσ structure≤, whicΦ combinσ ß conditiona∞ tes⌠ witΦ ß ì
- macr∩ parameter¼ phasσ error≤ begaε happeninτ iε grea⌠ ì
- proliferation« Probabl∙ ß tablσ oµ addresse≤ haΣ overflowed« ì
- Thσ onl∙ fi° wa≤ t∩ eliminatσ mos⌠ oµ thσ structures¼ whicΦ ╔ ì
- did« Somσ oµ thσ macros¼ fo≥ instancσ SYSF¼ MUL╘ anΣ EXIT¼ stil∞ ì
- emplo∙ it« Truσ nul∞ paramete≥ testinτ shoulΣ bσ added.
-
- Aε enhancemen⌠ tha⌠ ╔ though⌠ woulΣ bσ nicσ (althougΦ ╔ go⌠ ì
- b∙ O╦ withou⌠ it⌐ woulΣ bσ thσ additioε oµ logica∞ operator≤ ì
- (insteaΣ oµ jus⌠ thσ relationa∞ operators⌐ iε conditiona∞ ì
- assembly« Bu⌠ oε thσ wholσ Z80M╥ i≤ ß finσ assemble≥ anΣ ì
- is in complience witΦ thσ Ziloτ assemble≥ specification.
-
-
- --- Z80MACRO.LIB Format ---
-
-
- Severa∞ forma∞ rule≤ werσ followeΣ iε thσ generatioε oµ thσ ì
- library« Thσ firs⌠ rulσ i≤ consistenc∙ iε structure« ThougΦ thσ ì
- structurσ ╔ camσ u≡ witΦ ma∙ bσ idiosyncratic¼ i⌠ i≤ fairl∙ ì
- consisten⌠ anΣ ough⌠ t∩ bσ easil∙ graspeΣ b∙ an∙ programme≥ ì
- alread∙ familia≥ witΦ assembl∙ language« Thσ genera∞ structurσ ì
- ha≤ thσ followinτ elements:
-
- 1⌐ ┴ definitioε line, e.g. 'CPATXT MACRO #TEXT,#ADDR'.
-
- 2) A comment section describing the macro, and an example.
-
- 3⌐ Thσ main par⌠ oµ thσ macro¼ whicΦ wil∞ bσ duplicateΣ eacΦ ì
- time there is a reference to it in a .AZM source file.
-
- 4⌐ Aε embedded subroutinσ whicΦ i≤ flaggeΣ fo≥ conditiona∞ ì
- assembly so that it is only assembled once.
-
- 5⌐ Aε END═ statement¼ precedeΣ b∙ ß commen⌠ placeΣ t∩ sho≈ thσ ì
- end of the macro in expanded .PRN files.
- è
- Thesσ rule≤ goverε thσ usσ oµ loca∞ o≥ globa∞ labels in macros:
-
- 1) Iµ ß labe∞ i≤ founΣ iε ß globa∞ subroutine¼ i.e« onσ tha⌠ i≤ ì
- áááááflaggeΣ t∩ bσ assembleΣ onl∙ once¼ tha⌠ labe∞ wil∞ bσ ì
- áááááglobal¼ anΣ wil∞ havσ ╢ characters¼ thσ las⌠ beinτ '?'« ì
- áááááThi≤ yield≤ meaningfu∞ global≤ insteaΣ oµ needles≤ ì
- áááááassembler-generated replacements for local labels.ì
-
- Als∩ thi≤ way¼ wheε writinτ program≤ therσ i≤ n∩ neeΣ t∩ ì
- áááááworr∙ tha⌠ ß labe∞ iε thσ prograφ wil∞ duplicatσ onσ iε ß ì
- ááááámacro¼ a≤ lonτ a≤ yo⌡ remembe≥ no⌠ t∩ enΣ an∙ label≤ witΦ ß ì
- áááááquestioε mark« ┴ simila≥ conventioε wa≤ followeΣ fo≥ globa∞ ì
- ááááálabel≤ whicΦ marδ variables¼ excep⌠ thσ questioε marδ ì
- áááááprecede≤ insteaΣ oµ follows« Thi≤ i≤ shee≥ conventioε anΣ ì
- áááááma∙ bσ changeΣ iµ yo⌡ wisΦ b∙ rewritinτ thσ fe≈ occurrence≤ ì
- áááááiε Z80MACRO.LIB.
-
- 2) NO MACRO PARAMETERS CAN BE PLACED INSIDE A GLOBAL SUBROUTINE.
-
- Thi≤ i≤ necessar∙ t∩ kee≡ thσ macr∩ repeatable¼ whicΦ i≤ ß ì
- ááááágenera∞ specificatioε for al∞ macros« Tha⌠ is¼ ever∙ macr∩ ì
- ááááámus⌠ bσ repeatablσ withiε thσ samσ sourcσ file« Iµ ß ì
- áááááparamete≥ werσ placeΣ insidσ ß globa∞ subroutine¼ theε a ì
- áááááseconΣ referencσ oµ tha⌠ macr∩ witΦ differen⌠ parameter≤ ì
- áááááwoulΣ resul⌠ iε ß cal∞ t∩ thσ origina∞ subroutine¼ anΣ woulΣ ì
- áááááhavσ thσ origina∞ parameters.
-
- 3) Thσ #AROUN─ loca∞ labe∞ shoulΣ bσ placeΣ INSID┼ thσ ì
- áááááconditiona∞ assembl∙ oµ thσ subroutinσ if tha⌠ i≤ thσ onlyì
- áááááplacσ iε thσ macr∩ whicΦ i⌠ i≤ used«
-
- Thi≤ save≤ thσ generatioε oµ spuriou≤ loca∞ variables« Thσ ì
- áááááfirs⌠ pas≤ oµ thσ assemble≥ replace≤ al∞ occurrence≤ oµ ì
- áááááloca∞ variablσ witΦ sequentiall∙ incrementeΣ labels¼ s∩ ì
- ááááátherσ wil∞ bσ GAP╙ iε thσ sequencσ becausσ oµ thi≤ ì
- ááááátechnique« Iµ thi≤ i≤ no⌠ clear¼ jus⌠ examinσ ß .PR╬ file« ì
- áááááI don't think there is any serious impact to this.
-
- Thσ #AROUN─ labe∞ i≤ referenceΣ outsidσ thσ subroutinσ iε ß ì
- áááááfew of the macros, for instance CPATXT.
-
- Sincσ therσ arσ 2╕ flag≤ anΣ associateΣ routines¼ ╔ createΣ ì
- MRFLAGS.╚ a≤ ß heade≥ filσ t∩ *INCLUD┼ iε sourcσ files« Thi≤ ì
- wil∞ initializσ al∞ 2╕ flag≤ t∩ FALSE« Thσ crosslis⌠ iε ì
- MRFLAGS.DO├ wil∞ hel≡ yo⌡ determinσ wha⌠ flag≤ mus⌠ bσ ì
- initializeΣ iµ yo⌡ d∩ no⌠ *INCLUD┼ MRFLAGS.H.
-
- That'≤ abou⌠ ití Jus⌠ spenΣ somσ timσ studyinτ ß printou⌠ oµ ì
- Z80MACRO.LI┬ beforσ usinτ it« (┴ 13▓ columε printou⌠ wil∞ makσ ì
- the most readable listing.) Therσ arσ eigh⌠ examplσ .AZ═ file≤ ì
- provided¼ althougΦ the∙ d∩ no⌠ usσ al∞ oµ thσ macros« Therσ ma∙ ì
- stil∞ bσ ß fe≈ bugs¼ bu⌠ thosσ examplσ program≤ al∞ assemblσ anΣ ì
- RU╬ quitσ well« Somσ oµ theφ arσ eveε useful!