Before I learned how to use constants and bitwise operators/comparators, I designed my own set of code to determine what buttons are pressed. Here is the code that is more than just tried and true to work (used it in hundreds of programs).
Code: Select all
ReadSensorMSPlayStation(PSP_Port, PSP_Addr, b1, b2, lx, ly, rx, ry);
B2=b2*(-1)+255;
if (B2>=128){squ =1;B2-=128;}else{squ =0;}
if (B2>=64) {crs =1;B2-=64;} else{crs =0;}
if (B2>=32) {cir =1;B2-=32;} else{cir =0;}
if (B2>=16) {tri =1;B2-=16;} else{tri =0;}
if (B2>=8) {R1 =1;B2-=8;} else{R1 =0;}
if (B2>=4) {L1 =1;B2-=4;} else{L1 =0;}
if (B2>=2) {R2 =1;B2-=2;} else{R2 =0;}
if (B2>=1) {L2 =1;B2-=1;} else{L2 =0;}
B1=b1*(-1)+255;
if (B1>=128){lft =1;B1-=128;}else{lft =0;}
if (B1>=64) {dwn =1;B1-=64;} else{dwn =0;}
if (B1>=32) {rght=1;B1-=32;} else{rght=0;}
if (B1>=16) {up =1;B1-=16;} else{up =0;}
if (B1>=8) {str =1;B1-=8;} else{str =0;}
if (B1>=4) {sr =1;B1-=4;} else{sr =0;}
if (B1>=2) {sl =1;B1-=2;} else{sl =0;}
if (B1>=1) {sel =1;B1-=1;} else{sel =0;}
Just because I have been using this for so long, and don't want to go back and change all my programs, I still haven't updated to a better method yet.
According to that, the constants should be like this for button set 1(based on doing *(-1)+255 which inverts all the bits like a NOT would do, like Muntoo must be doing).
Code: Select all
#define PSP_BTNSET1_LEFT 0x80
#define PSP_BTNSET1_DOWN 0x40
#define PSP_BTNSET1_RIGHT 0x20
#define PSP_BTNSET1_UP 0x10
#define PSP_BTNSET1_STR 0x08
#define PSP_BTNSET1_R3 0x04
#define PSP_BTNSET1_L3 0x02
#define PSP_BTNSET1_SEL 0x01