Jump to content
IGNORED

Macro Variable Sharing


Recommended Posts

Ok I was just wondering if it was the same for macros which seems to be the case as the following works:

	MAC BYTE_COUNT_BEGIN
	
_BYTE_COUNT SET *
_BYTE_COUNT_NAME SET {1}  

	ECHO "###", {1}, "starting at byte", *
	
	ENDM
	
;===========================
	
	MAC BYTE_COUNT_END

	ECHO "###", _BYTE_COUNT_NAME, "ending at byte", *, "byte count =", [* -  _BYTE_COUNT]d
	
	ENDM
Link to comment
Share on other sites

I have made the macro a bit simpler so you only have to place the macro at the end of the section of code you want to count with a reference to the start label:

	MAC BYTE_COUNT 
	
	ECHO "###", {2}, "start =", {1}, "end =", *, "byte count=", [* -  {1}]d
	
	ENDM

I still have to call it like this BYTE_COUNT LabelName, "LabelName" to print out the name of the label with an echo command

 

Is there a way to remove the second argument and be able to convert the label to a string name in the macro itself?

Edited by Mikes360
Link to comment
Share on other sites

Well, the temporary variables have to start with a period. So shouldn't anything that doesn't start with a period be global?

 

I'm sitting here reading through the DASM documentation. Slight correction-- temporary variables don't *have* to start with a period; there can also be temporary variables that are numbers followed by a $, like 0$, 00$ (which is different than 0$), 123$, etc. But I'm not sure if this format is always valid-- the documentation says "#if Olafdol." I'm not sure what that means-- I presume it refers to an option that's enabled when DASM itself is being compiled (as opposed to when DASM is being used to assemble a program)-- but for BYTE, WORD, and LONG it says "#if OlafByte," and they work all the time for me, which I presume means that the version of DASM I'm using was compiled with that option enabled. :?

Link to comment
Share on other sites

Is there a way to remove the second argument and be able to convert the label to a string name in the macro itself?

 

I don't see a way to do that, because the label isn't passed as a label-- it's passed as the value of the label. And if you pass the label name as a string, I can't figure out how to convert the string to the value of the label.

Link to comment
Share on other sites

 

I don't see a way to do that, because the label isn't passed as a label-- it's passed as the value of the label. And if you pass the label name as a string, I can't figure out how to convert the string to the value of the label.

 

The "best" solution I can come up is to do something like this:

 

 

   MAC WHEREIS
   ECHO {1}, "=", HERE, "THRU", .
   ENDM
 
HERE_I_AM_MOE
HERE SET .
 
   NOP
   NOP
   NOP
 
   WHEREIS "HERE_I_AM_MOE"
 
THERE_YOU_ARE_SHEMP
HERE SET .
 
   NOP
   NOP
   NOP
 
   WHEREIS "THERE_YOU_ARE_SHEMP"
Link to comment
Share on other sites

One final revision... even less typing (well, except for the label names)!

 

 

   MAC !
HERE SET .
   ENDM
 
   MAC ?
   ECHO {1}, "=", HERE, "thru", .-1
   ENDM
 
Here_I_Am_Moe !
   NOP
   NOP
   NOP
   ? "Here_I_Am_Moe"
 
There_You_Are_Shemp !
   NOP
   NOP
   NOP
   ? "There_You_Are_Shemp"

 

I had no idea you could define ! and ? as macro names-- it's kind of cool!

Link to comment
Share on other sites

Very cool! I still like the following as you only need to have it at the end and passing the extra string argument can make the output more easy to understand. I also found the CHECK_PAGE macro while digging around on here which is great for making sure 48 pixel graphics stays on a single page

	MAC BYTE_COUNT 
        
	ECHO "###", {2}, "start =", {1}, "end =", *, "byte count=", [* -  {1}]d
        
	ENDM

	MAC CHECK_PAGE
          IF >. != >{1}
                 ECHO ""
                 ECHO "ERROR: different pages! (", {1}, ",", ., ")"
                 ECHO ""
                 ERR
          ENDIF
	ENDM


PointZeroLogoColors
	.byte $36,$3E,$3E,...... 
PointZeroLogoGfx1
	.byte #%01111101,#%01111010,#%01111010.....
PointZeroLogoGfx2
        .byte ......

BYTE_COUNT PointZeroLogoColors, "Logo Gfx Data"
CHECK_PAGE PointZeroLogoColors

I think we could do with a library of useful macros. Update macro.h with some more goodies?

Link to comment
Share on other sites

I still like the following as you only need to have it at the end and passing the extra string argument can make the output more easy to understand.

 

In defense of my ! macro, it's pretty quick and easy to type a ! after the label you're interested in, and it doesn't interfere with the not operator (I checked to be sure). Also, it doesn't have to be after a label-- it could be on any line whose address you want to remember:

 

 

   DEX
   BNE Jump_Ahead
   ! ; remember this address
 
; insert code here
; insert more code here
 
Jump_Ahead ? "message"

 

Then the ECHO will show the address from which the branch is counted, followed by the address of the target, so you can see if there's a page crossing.

 

The downside, of course, is that it's only temporary-- each time you use it, the previous value of HERE gets wiped out. But that also makes it useful as a temporary and reusable address marker.

 

As for the ? macro, the text doesn't have to be a label, and the ECHO could show the number of bytes rather than the starting/ending addresses-- or both.

 

I don't know if it's such a good idea to define macros whose "names" are single characters, like ! and ?-- but they could easily be renamed, although I did try to pick characters that "made sense" or seemed reasonably fitting for these particular macros.

 

I haven't written very many macros, myself, but I have written a few that might be of general use. We should start a topic (and perhaps ask the mods to pin it) for everybody to post their macros in, then maybe we could all vote on which ones would be good to add to new "official" versions of the MACRO.H file. And any macros that "didn't make the vote" would still be on record for people to see and adopt as needed/desired.

Link to comment
Share on other sites

Yes I do like the flexibility of being able to start the byte counting from any address that is fairly powerful.

 

Sounds like a plan if we start a new topic hopefully we will get all kinds of great macros to help everybody with their development.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...