But anyway, for completionist's sake, here is the rest of the code.
Anyhow, can you or someone else explain to me what a mask is? I think it might've been explained to me once, but I probably forgot it as I never have to use that stuff in my ASM hacks. Also, I understand that the bits are being shifted to the left, but where does the new bit come from? So, I understand the new bit is being set from the results of the bitmask, but which side is the bit being taken from? The right or the left?
Well, sure, I can take a stab at that. I apologize in advance if this is aimed too high or too low.
Wikipedia does a fairly decent job of explaining masking here
. The "Querying the status of a bit" section is exactly what the Time Twist code is doing at $832A: pretend the first row of Wikipedia's example is ($6A),Y, the second row is $006C, and the third row is what's left in the accumulator (A) as a result. In the context of this section of code, masking basically means ignoring the bits you don't care about by setting them to 0.
On the NES, the AND operation also sets the zero processor flag if the result (A) is #$00, and that flag is what the BNE at $832C checks to decide what to do next. If A is not #$00 (which means it has some bit set, which in turn can only mean that the bit of ($6A),Y that we were checking with $006C was
set), then it branches to $8336, where (in addition to updating $6A, $6B, and $6C via the JSR $833E) it does a SEC and a ROL $003A. The rightmost bit (a.k.a. the new bit, a.k.a. the lowest-order bit) in the ROL actually comes from the carry processor flag, not anything in A, so the SEC (SE
arry) makes sure that the low bit of $003A does
get set. On the other hand, if A is #$00 (which means it has no bits set, which in turn can only mean that the bit of ($6A),Y that we were checking with $006C was not
set), then it doesn't branch and (in addition to running the exact same code for updating $6A, $6B, and $6C via the JSR $833E) instead does a CLC (CL
arry) and a ROL $003A, which results in the low bit of $003A not
being set. So in either case, the low bit of $003A becomes the same as the bit of ($6A),Y that we were checking with $006C.
If you haven't seen it already, Programming the 65816
, a handy reference for both 65816 and 6502, has a nice little picture on the reference page for ROL that is probably a better explanation than anything I just wrote :p.
Anyway, that entire block of code from $8328 to $8358 is basically just reading one bit at a time from ($6A),Y and updating $003A accordingly. It gets called a lot, but (IMHO) it's fairly boring per se. I'm not sure exactly what part of Time Twist's text routine you're interested in most, but for me finding out what happens with $003A after $8328 - $8358 updates it is, well, not exactly exciting but at least closer to it