Mikes360 Posted January 3, 2015 Share Posted January 3, 2015 Hi Guys, I have created a little macro to pad my graphics with zero bytes and I would like to use it in the following way. Here is the macro: MAC ZERO_PAD .COUNT SET {1} ECHO "### ZERO_PAD ", [.COUNT]d REPEAT .COUNT .byte #0 REPEND ENDM And here is a example of how I would like to use it: ZERO_PAD PLAYER_HEIGHT - 5 PlayerStopped .byte #%00000000 .byte #%00000000 .byte #%00100100 .byte #%01111110 .byte #%00101100 .byte #%00101000 .byte #%00101000 ;-- .byte #%00111000 .byte #%00110000 .byte #%10110010 .byte #%01111100 .byte #%00110000 ;-- .byte #%00111000 .byte #%01111000 .byte #%00111000 .byte #%00111000 PLAYER_HEIGHT = (* - PlayerStopped) echo "PLAYER_HEIGHT = ", [PLAYER_HEIGHT]d I know the issue is with the fact I am using PLAYER_HEIGHT before it is defined but I though the assembler might be cleaver enough to work this out via multiple passes. Is this something that should work? I know if I use the ZERO_PAD macro after PLAYER_HEIGHT is defined it then works. Thanks, Mike Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 4, 2015 Share Posted January 4, 2015 Unfortunately DASM is not smart enough here. I suppose to add a check inside the macro and skip if PLAYER_HEIGHT is still uninitialized (= 0). BTW: Instead of the loop you can simply use: ds {1}, 0 Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted January 4, 2015 Author Share Posted January 4, 2015 (edited) Thanks if I add a check in to the macro it won't try again the second time around so it never actually inserts the zeros I have decided to do this a bit more manually with a bit of validation to make sure I don't mess up the tables down the line ;============================================================================== ; R A I L - D A T A ;============================================================================== RAIL_START = 80 RAIL_HEIGHT = 23 RailTable2 SUBROUTINE ZERO_PAD PLAYFIELD_START - RAIL_START - RAIL_HEIGHT .start .byte #%00000000 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 ;----- IF (* - .start) != RAIL_HEIGHT ECHO "Rail table not the same as its defined height", [(* - .start)]d ERR ENDIF ;----- ZERO_PAD RAIL_START Edited January 4, 2015 by Mikes360 Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 4, 2015 Share Posted January 4, 2015 Weird, because for me it works that way. Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted January 4, 2015 Author Share Posted January 4, 2015 would you mind posting your version of the macro? Mine is: MAC ZERO_PAD IF {1} > 0 ECHO "### ZERO_PAD ", [{1}]d ds {1}, 0 ENDIF ENDM Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 4, 2015 Share Posted January 4, 2015 (edited) Nothing special: MAC ZERO_PAD .COUNT SET {1} IF .COUNT > 0 ECHO "### ZERO_PAD ", [.COUNT]d ds .COUNT, 0 ENDIF ENDM And your macro works for me too. Edited January 4, 2015 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted January 4, 2015 Author Share Posted January 4, 2015 Actually I just tired it again and its not what I thought its failing to assemble the code altogether When I try the following Test ZERO_PAD TEST_HEIGHT - 1 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 .byte #%00000010 TEST_HEIGHT = (* - Test) I get this in my output 116 c20a Test 0 c20a ZERO_PAD TEST_HEIGHT - 1 1 c20a IF TEST_HEIGHT - 1 > 0 ### ZERO_PAD 4 2 c20a ECHO "### ZERO_PAD ", [TEST_HEIGHT - 1]d 3 c20a 00 00 00 00 ds TEST_HEIGHT - 1, 0 4 c20e ENDIF 118 c20e 02 .byte.b #%00000010 119 c20f 02 .byte.b #%00000010 120 c210 02 .byte.b #%00000010 121 c211 02 .byte.b #%00000010 122 c212 02 .byte.b #%00000010 Graphics.asm (123): error: EQU: Value mismatch. 123 c212 00 09 TEST_HEIGHT = (* - Test) Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 4, 2015 Share Posted January 4, 2015 (edited) Ah, that's the problem. You are assigning different values to TEST_HEIGHT. You can try using SET instead of =, but I am not sure if it will work. Your previous approach works. Edited January 4, 2015 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted January 4, 2015 Author Share Posted January 4, 2015 Ok I understand now thanks for your help... Again, one day ill be able to spot this myself. 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.