Mikes360 Posted August 27, 2013 Share Posted August 27, 2013 Hi Guys, I was wondering if it possible to declare a global variable that can be used/set in multiple macros? I haven't found a way to do this myself. Thanks, Mike Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 27, 2013 Share Posted August 27, 2013 Well, the temporary variables have to start with a period. So shouldn't anything that doesn't start with a period be global? Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted August 27, 2013 Author Share Posted August 27, 2013 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 Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted August 27, 2013 Author Share Posted August 27, 2013 Currently this works as follows BYTE_COUNT_BEGIN "RoutineName" is there a way of passing a label in and echoing its name rather than the byte its references? BYTE_COUNT_BEGIN RoutineName for example Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted August 27, 2013 Author Share Posted August 27, 2013 (edited) 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 August 27, 2013 by Mikes360 Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 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" Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 I guess for my example (the starting and ending addresses, rather than the byte count) it should have been MAC WHEREIS ECHO {1}, "=", HERE, "THRU", .-1 ENDM Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 Well, what do you know... this works, too (and is easier to type): MAC ? HERE SET . ENDM MAC WHEREIS ECHO {1}, "=", HERE, "thru", .-1 ENDM Here_I_Am_Moe ? NOP NOP NOP WHEREIS "Here_I_Am_Moe" There_You_Are_Shemp ? NOP NOP NOP WHEREIS "There_You_Are_Shemp" Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 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! Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted August 28, 2013 Author Share Posted August 28, 2013 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? Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 I think we could do with a library of useful macros. Update macro.h with some more goodies? Yes, it would be nice to see MACRO.H updated to include additional useful macros. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2013 Share Posted August 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted August 28, 2013 Author Share Posted August 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.