Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This loads 10 bytes per frame, with 10 signalling bits
- // we only do bitwise operations at the beginning, and there's not too many
- // (I also intentionally wrote them to be (hopefully) easier to convert to assembly)
- // let the following be an array that magically contains the bytes for 3 controllers
- uint8_t pad_bytes[ 12 ];
- uint16_t command = 0;
- uint16_t command_last = 1;
- read_pad( ) {
- uint16_t temp;
- uint8_t out_bytes[ 10 ];
- // for all of the controller bytes that are full bytes, load them directly
- out_bytes[ 0 ] = pad_bytes[ 0 ];
- out_bytes[ 1 ] = pad_bytes[ 2 ];
- out_bytes[ 2 ] = pad_bytes[ 3 ];
- out_bytes[ 3 ] = pad_bytes[ 4 ];
- out_bytes[ 4 ] = pad_bytes[ 6 ];
- out_bytes[ 5 ] = pad_bytes[ 7 ];
- out_bytes[ 6 ] = pad_bytes[ 8 ];
- out_bytes[ 7 ] = pad_bytes[ 10 ];
- out_bytes[ 8 ] = pad_bytes[ 11 ];
- // pad_bytes[ 1 ], pad_bytes[ 5 ], pad_bytes[ 9 ] only have 6 bits of useful data
- // we'll have to do some bitwise operations to compose them into bytes
- // mask off garbage bits, can skip if this isn't needed
- pad_bytes[ 1 ] &= 63;
- pad_bytes[ 5 ] &= 63;
- pad_bytes[ 9 ] &= 63;
- // --- Read extra byte ---
- // step by step bit twiddling
- temp = pad_bytes[ 5 ]; // read pad byte 5 into a register
- temp &= 3; // mask off everything except the first two bits
- temp <<= 6; // shift it up 6 bits, so that the first two bits are at the top of the byte
- temp |= pad_bytes[ 1 ]; // merge it with the entirety of pad byte 1
- // write it out
- out_bytes[ 9 ] = temp;
- // out_bytes now has 10 new bytes loaded into it
- // --- Read command ---
- command_last = command; // so we can detect when a command has changed (ie, started)
- // more bit level voodoo
- command = pad_bytes[ 5 ]; // store pad byte 5 in a register
- command &= 60; // mask off the lowest two bits (which were data)
- command <<= 4; // shift what's left up 4 bits
- command |= pad_bytes[ 9 ]; // merge all of the bits of pad byte 9 into it
- // "command" is now a 10 bit number
- // --- Execute command ---
- switch( command ) {
- default: break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement