rosutokami Posted August 28, 2007 Share Posted August 28, 2007 Hello! Do you all know if it is possible on the 2600 to 'shift' the bits on a byte? As in, if I had a byte 00010100, to somehow with a command or math move the bits so it read 00001010 or 00101000. I have been thinking about ways to modify sprites by putting them into RAM instead of having each image take up ROM space, and this idea came to me. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted August 28, 2007 Share Posted August 28, 2007 Hello!Do you all know if it is possible on the 2600 to 'shift' the bits on a byte? As in, if I had a byte 00010100, to somehow with a command or math move the bits so it read 00001010 or 00101000. I have been thinking about ways to modify sprites by putting them into RAM instead of having each image take up ROM space, and this idea came to me. Yes, you can shift and rotate the bits in a byte. It's a common assembly programming technique, and is so important for different things (such as math) that there are assembly instructions just for that purpose. The 6502 assembly language has two shift commands, and two rotate commands: ASL -- Shift Left All bits are shifted left 1 position. 0 is shifted into bit 0, and bit 7 is shifted into the carry. LSR -- Shift Right All bits are shifted right 1 position. 0 is shifted into bit 7, and bit 0 is shifted into the carry. ROL -- Rotate Left All bits are shifted left 1 position. The carry is shifted into bit 0, and bit 7 is shifted into the carry. ROR -- Rotate Right All bits are shifted right 1 position. The carry is shifted into bit 7, and bit 0 is shifted into the carry. Note that the rotate instructions do *not* rotate bit 7 into bit 0, or bit 0 into bit 7, so if you want to do a full rotation of a byte like that, you'll need to use a shift instruction instead of a rotate instruction, then follow it with a test of the carry flag, and modify the shifted byte accordingly, like this: ; rotate a byte left LDA desired_byte; shifting the accumulator is faster than shifting a byte in memory ASL; this shifts the bits ot the accumulator left, 0 goes into bit 0, and bit 7 goes into the carry BCC all_done; if the carry is clear (or 0), then we're done ORA #000001; otherwise we want to set bit 0 to a 1 without messing up the other bits all_done STA desired_byte; now we store the result back into memory ; rotate a byte right LDA desired_byte; shifting the accumulator is faster than shifting a byte in memory LSR; this shifts the bits ot the accumulator right, 0 goes into bit 7, and bit 0 goes into the carry BCC all_done; if the carry is clear (or 0), then we're done ORA #%10000000; otherwise we want to set bit 7 to a 1 without messing up the other bits all_done STA desired_byte; now we store the result back into memory Michael Quote Link to comment Share on other sites More sharing options...
rosutokami Posted August 28, 2007 Author Share Posted August 28, 2007 That's really cool, thanks! 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.