Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.
GradualGames wrote:Not sure I understand all the syntax there, particularly the double %%'s.
Those are there because of the inner sprintf constructs the format string for the outer sprintf. So, for example .sprintf("%%.%ds", 9) would turn into "%.9s" which is used as the format string in the outer sprintf.
(Note that unlike C sprintf, ca65 does not support specifying the field precision as an argument with "*", so nested sprintfs are needed.)
GradualGames wrote:Not sure I understand all the syntax there, particularly the double %%'s.
Those are there because of the inner sprintf constructs the format string for the outer sprintf. So, for example .sprintf("%%.%ds", 9) would turn into "%.9s" which is used as the format string in the outer sprintf.
(Note that unlike C sprintf, ca65 does not support specifying the field precision as an argument with "*", so nested sprintfs are needed.)
Ah, %% is an escape for itself then? Gotcha. Cool! There's a couple of other things I don't understand in there, it looks like you're doing a multiply on strlens somewhere, too, what's that for? *edit* I think I understand now that < is returning 0 or 1 so you can prevent it from parameterizing sprintf with a negative number, the trickery you mentioned, I assume. Neat.
GradualGames wrote:There's a couple of other things I don't understand in there, it looks like you're doing a multiply on strlens somewhere, too, what's that for?
That's the "trickery" I mentioned. (.strlen(ends_with) < .strlen(string)) evaluates to 0 if the ends_with is shorter than string (and 1 otherwise). The multiplication then forces the expression value to 0 to avoid a negative value going into the format string. E.g., "%.-7s" would not be a valid format string.
GradualGames wrote:There's a couple of other things I don't understand in there, it looks like you're doing a multiply on strlens somewhere, too, what's that for?
That's the "trickery" I mentioned. (.strlen(ends_with) < .strlen(string)) evaluates to 0 if the ends_with is shorter than string (and 1 otherwise). The multiplication then forces the expression value to 0 to avoid a negative value going into the format string. E.g., "%.-7s" would not be a valid format string.
I can't seem to get ca65 to be happy with it. Trying to compile the following:
Wondering if it's a linecont issue. Like if I use .linecont + and then add some \ 's if it'll work.
GradualGames wrote:There's a couple of other things I don't understand in there, it looks like you're doing a multiply on strlens somewhere, too, what's that for?
That's the "trickery" I mentioned. (.strlen(ends_with) < .strlen(string)) evaluates to 0 if the ends_with is shorter than string (and 1 otherwise). The multiplication then forces the expression value to 0 to avoid a negative value going into the format string. E.g., "%.-7s" would not be a valid format string.
I can't seem to get ca65 to be happy with it. Trying to compile the following:
Wondering if it's a linecont issue. Like if I use .linecont + and then add some \ 's if it'll work.
thefox wrote:It works by stripping off .strlen(string) - .strlen(ends_with) characters from the end of string, then appends ends_with to it, and compares to the original string.