Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define POLLS 4
- #define _data_len ( 45 * ( (POLLS) / 4 ) )
- typedef struct {
- u32 init;
- volatile u8* data_pointer;
- u32 crc_state;
- u32 crc_table[ 256 ];
- u32 poll_count;
- u8 temp_data[ 24 ];
- union {
- u8 bytes[ _data_len ];
- u16 _u16[ _data_len / sizeof(u16) ];
- u32 _u32[ _data_len / sizeof(u32) ];
- s16 _s16[ _data_len / sizeof(s16) ];
- int _int[ _data_len / sizeof(int) ];
- } out;
- } static_globals;
- extern static_globals gvars;
- typedef struct {
- u8 b1, b2, x, y;
- u16 status;
- } __attribute__((packed)) raw_input_t;
- // 6 bytes long
- // might be bad, probably not needed
- // hopefully this works if you pay attention to alignment
- int pad_poll( void ) {
- u32 bits;
- u8 bits_n, i, written_bytes, padding;
- bits_n = 0;
- bits = 0ULL;
- written_bytes = 0;
- for( i = 0; i < (POLLS); ++i ) {
- raw_input_t* pad_data;
- // try to preserve the original pad input
- // *never write* to padmgr
- if( !i ) { // the first time, use pad data from the original game poll
- pad_data = (raw_input_t*)(&padmgr->pads[0]);
- } else { // afterwards, poll the pads ourselves, and discard data for pad 1
- pad_data = (raw_input_t*)(gvars.temp_data);
- osContStartReadData( queue ); // black magic
- osRecvMesg( queue, NULL, OS_MESG_BLOCK );
- osContGetReadData( pad_data ); // actually get the pad data
- }
- // pad_data now has the state of the pads for this poll
- if( pad_data[1].status == 0 || pad_data[2].status == 0 || pad_data[3].status == 0 )
- return 0;
- gvars.out.bytes[ written_bytes++ ] = pad_data[1].b1;
- gvars.out.bytes[ written_bytes++ ] = pad_data[1].x;
- gvars.out.bytes[ written_bytes++ ] = pad_data[1].y;
- gvars.out.bytes[ written_bytes++ ] = pad_data[2].b1;
- gvars.out.bytes[ written_bytes++ ] = pad_data[2].x;
- gvars.out.bytes[ written_bytes++ ] = pad_data[2].y;
- gvars.out.bytes[ written_bytes++ ] = pad_data[3].b1;
- gvars.out.bytes[ written_bytes++ ] = pad_data[3].x;
- gvars.out.bytes[ written_bytes++ ] = pad_data[3].y;
- bits <<= 6;
- bits |= pad_data[1].b2;
- bits <<= 6;
- bits |= pad_data[2].b2;
- bits <<= 6;
- bits |= pad_data[3].b2;
- bits_n += 18;
- gvars.out.bytes[ written_bytes++ ] = ( bits & 0xFF );
- bits >>= 8;
- gvars.out.bytes[ written_bytes++ ] = ( bits & 0xFF );
- bits >>= 8;
- bits_n -= 16;
- if( bits_n == 8 ) {
- gvars.out.bytes[ written_bytes++ ] = ( bits & 0xFF );
- bits >>= 8;
- bits_n -= 8;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement