ps2sdk pad left_p/right_p
Posted: Tue Nov 23, 2004 9:00 am
It appears that left_p and right_p in padButtonStatus need to be swapped. (Incidentally rigth_p is spelt incorrectly).
Homebrew PS2, PSP & PS3 Development Discussions
https://forums.ps2dev.org./
Code: Select all
20,35c20,35
< #define PAD_LEFT 0x8000
< #define PAD_DOWN 0x4000
< #define PAD_RIGHT 0x2000
< #define PAD_UP 0x1000
< #define PAD_START 0x0800
< #define PAD_R3 0x0400
< #define PAD_L3 0x0200
< #define PAD_SELECT 0x0100
< #define PAD_SQUARE 0x0080
< #define PAD_CROSS 0x0040
< #define PAD_CIRCLE 0x0020
< #define PAD_TRIANGLE 0x0010
< #define PAD_R1 0x0008
< #define PAD_L1 0x0004
< #define PAD_R2 0x0002
< #define PAD_L2 0x0001
---
> #define PAD_LEFT 0x0080
> #define PAD_DOWN 0x0040
> #define PAD_RIGHT 0x0020
> #define PAD_UP 0x0010
> #define PAD_START 0x0008
> #define PAD_R3 0x0004
> #define PAD_L3 0x0002
> #define PAD_SELECT 0x0001
> #define PAD_SQUARE 0x8000
> #define PAD_CROSS 0x4000
> #define PAD_CIRCLE 0x2000
> #define PAD_TRIANGLE 0x1000
> #define PAD_R1 0x0800
> #define PAD_L1 0x0400
> #define PAD_R2 0x0200
> #define PAD_L2 0x0100
98c98
< unsigned char btns[2];
---
> unsigned short btns;
104a105
> unsigned char right_p;
106d106
< unsigned char rigth_p;
111d110
< unsigned char square_p;
112a112
> unsigned char square_p;
Code: Select all
#include <tamtypes.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <libpad.h>
#include <fileio.h>
#include <malloc.h>
#include "gsDefs.h"
#include "gsDriver.h"
#include "gsPipe.h"
#include "gsFont.h"
#define PAD_TYPE 0
static char padBuf[256] __attribute__((aligned(64)));
void* LoadMemalign(const char* filename, int align)
{
int filehandle = fioOpen(filename, O_RDONLY);
int filesize = fioLseek(filehandle, 0, SEEK_END);
void* mem = memalign(align, filesize);
fioLseek(filehandle, 0, SEEK_SET);
if (fioRead(filehandle, mem, filesize) <= 0)
{
free(mem);
mem = 0;
}
fioClose(filehandle);
return mem;
}
void LoadModules()
{
const char* modules[] = {
#if PAD_TYPE != 1
"rom0:SIO2MAN",
"rom0:PADMAN",
#else
"rom0:XSIO2MAN",
"rom0:XPADMAN",
#endif
0 };
const char** thismodule = modules;
while (*thismodule)
{
//printf("Loading Module: %s\n", *thismodule);
int ret = SifLoadModule(*thismodule, 0, NULL);
if (ret < 0)
{
printf("Error Loading Module: %s\n", *thismodule);
}
++thismodule;
};
}
void waitPadReady(int port, int slot)
{
// todo check for PAD_STATE_DISCONN
int state = 0;
do
{
state=padGetState(port, slot);
}
while((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1));
}
void DrawButton(gsFont& myFont, int y, const char* name, int up)
{
myFont.Print(10, 110, y, 2, GS_SET_RGBA(0xFF,0xFF,0xFF,0xFF), GSFONT_ALIGN_LEFT, name);
if (up)
myFont.Print(100, 200, y, 2, GS_SET_RGBA(0x00,0xFF,0x00,0xFF), GSFONT_ALIGN_LEFT, "UP");
else
myFont.Print(100, 200, y, 2, GS_SET_RGBA(0xFF,0x00,0x00,0xFF), GSFONT_ALIGN_LEFT, "DOWN");
}
void DrawButton(gsFont& myFont, int y, const char* name, int down, int pressure)
{
DrawButton(myFont, y, name, down);
char buffer[100];
sprintf(buffer, "%d", pressure);
myFont.Print(200, 300, y, 2, GS_SET_RGBA(0xFF,0xFF,0xFF,0xFF), GSFONT_ALIGN_LEFT, buffer);
}
int main()
{
gsDriver myGsDriver;
myGsDriver.setDisplayMode(640, 480, 180, 70,
GS_PSMCT32, 2, GS_TV_AUTO, GS_TV_INTERLACE,
GS_ENABLE, GS_PSMZ32);
myGsDriver.drawPipe.setAlphaEnable(GS_ENABLE);
gsFont myFont;
myFont.assignPipe(&myGsDriver.drawPipe);
gsFontTex* fontTex = (gsFontTex*)LoadMemalign("mc0:/FONTS/arial.fnt", 64);
if (fontTex)
{
// Upload into the beginning of texture mem (with texture-buffer width set to 256)
myFont.uploadFont(fontTex, myGsDriver.getTextureBufferBase(),
fontTex->TexWidth, // Use the fontTex width as texbuffer width (can use diff width)
0, 0 );
}
SifInitRpc(0);
LoadModules();
int ret = 0;
ret = padInit(0);
if(ret < 0)
printf("Failed to initialise pad server: %d\n\n", -ret);
int port = 0; // 0 -> Connector 1, 1 -> Connector 2
int slot = 0; // Always zero if not using multitap
//char padBuf[256] __attribute__((aligned(64)));
ret = padPortOpen(port, slot, padBuf);
if(ret < 0)
printf("padOpenPort failed: %d\n\n", -ret);
waitPadReady(port, slot);
// When using MMODE_LOCK, user cant change mode with Select button
padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
waitPadReady(port, slot);
padEnterPressMode(port, slot);
while (true)
{
waitPadReady(port, slot);
padButtonStatus buttons;
ret = padRead(port, slot, &buttons); // port, slot, buttons
if (ret != 0)
{
// Clear the screen (with ZBuffer Disabled)
myGsDriver.drawPipe.setZTestEnable(GS_DISABLE);
myGsDriver.drawPipe.RectFlat(0,0,639,479,0,GS_SET_RGBA(0x00,0x00,0x00,0x80));
myGsDriver.drawPipe.setZTestEnable(GS_ENABLE);
DrawButton(myFont, 10, "LEFT", buttons.btns & PAD_LEFT, buttons.left_p);
DrawButton(myFont, 30, "RIGHT", buttons.btns & PAD_RIGHT, buttons.right_p);
DrawButton(myFont, 50, "UP", buttons.btns & PAD_UP, buttons.up_p);
DrawButton(myFont, 70, "DOWN", buttons.btns & PAD_DOWN, buttons.down_p);
DrawButton(myFont, 110, "SQUARE", buttons.btns & PAD_SQUARE, buttons.square_p);
DrawButton(myFont, 130, "CROSS", buttons.btns & PAD_CROSS, buttons.cross_p);
DrawButton(myFont, 150, "CIRCLE", buttons.btns & PAD_CIRCLE, buttons.circle_p);
DrawButton(myFont, 170, "TRIANGLE", buttons.btns & PAD_TRIANGLE, buttons.triangle_p);
DrawButton(myFont, 210, "L1", buttons.btns & PAD_L1, buttons.l1_p);
DrawButton(myFont, 230, "L2", buttons.btns & PAD_L2, buttons.l2_p);
DrawButton(myFont, 250, "L3", buttons.btns & PAD_L3);
DrawButton(myFont, 270, "R1", buttons.btns & PAD_R1, buttons.r1_p);
DrawButton(myFont, 290, "R2", buttons.btns & PAD_R2, buttons.r2_p);
DrawButton(myFont, 310, "R3", buttons.btns & PAD_R3);
DrawButton(myFont, 350, "SELECT", buttons.btns & PAD_SELECT);
DrawButton(myFont, 370, "START", buttons.btns & PAD_START);
{
char buffer[100];
sprintf(buffer, "Right Joy %d %d", buttons.rjoy_h, buttons.rjoy_v);
myFont.Print(10, 210, 410, 2, GS_SET_RGBA(0xFF,0xFF,0xFF,0xFF), GSFONT_ALIGN_LEFT, buffer);
sprintf(buffer, "Left Joy %d %d", buttons.ljoy_h, buttons.ljoy_v);
myFont.Print(10, 210, 430, 2, GS_SET_RGBA(0xFF,0xFF,0xFF,0xFF), GSFONT_ALIGN_LEFT, buffer);
}
myGsDriver.drawPipe.RectFlat(
320 - 128 - 10 + buttons.rjoy_h, 240 - 128 - 10 + buttons.rjoy_v,
320 - 128 + 10 + buttons.rjoy_h, 240 - 128 + 10 + buttons.rjoy_v,
3, GS_SET_RGBA(0xFF,0x00,0x00,0x80));
myGsDriver.drawPipe.RectFlat(
320 - 128 - 10 + buttons.ljoy_h, 240 - 128 - 10 + buttons.ljoy_v,
320 - 128 + 10 + buttons.ljoy_h, 240 - 128 + 10 + buttons.ljoy_v,
3, GS_SET_RGBA(0x00,0xFF,0x00,0x80));
myGsDriver.drawPipe.RectFlat(
320 - 10 + (buttons.right_p - buttons.left_p)/2, 240 - 10 + (buttons.down_p - buttons.up_p)/2,
320 + 10 + (buttons.right_p - buttons.left_p)/2, 240 + 10 + (buttons.down_p - buttons.up_p)/2,
3, GS_SET_RGBA(0x00,0x00,0xFF,0x80));
myGsDriver.drawPipe.Flush();
myGsDriver.WaitForVSync();
myGsDriver.swapBuffers();
}
}
return 0;
}
Code: Select all
Index: ee/rpc/pad/include/libpad.h
===================================================================
RCS file: /home/ps2cvs/ps2sdk/ee/rpc/pad/include/libpad.h,v
retrieving revision 1.2
diff -u -r1.2 libpad.h
--- ee/rpc/pad/include/libpad.h 14 Sep 2004 14:41:27 -0000 1.2
+++ ee/rpc/pad/include/libpad.h 24 Nov 2004 01:16:40 -0000
@@ -20,22 +20,22 @@
/*
* Button bits
*/
-#define PAD_LEFT 0x8000
-#define PAD_DOWN 0x4000
-#define PAD_RIGHT 0x2000
-#define PAD_UP 0x1000
-#define PAD_START 0x0800
-#define PAD_R3 0x0400
-#define PAD_L3 0x0200
-#define PAD_SELECT 0x0100
-#define PAD_SQUARE 0x0080
-#define PAD_CROSS 0x0040
-#define PAD_CIRCLE 0x0020
-#define PAD_TRIANGLE 0x0010
-#define PAD_R1 0x0008
-#define PAD_L1 0x0004
-#define PAD_R2 0x0002
-#define PAD_L2 0x0001
+#define PAD_LEFT 0x0080
+#define PAD_DOWN 0x0040
+#define PAD_RIGHT 0x0020
+#define PAD_UP 0x0010
+#define PAD_START 0x0008
+#define PAD_R3 0x0004
+#define PAD_L3 0x0002
+#define PAD_SELECT 0x0001
+#define PAD_SQUARE 0x8000
+#define PAD_CROSS 0x4000
+#define PAD_CIRCLE 0x2000
+#define PAD_TRIANGLE 0x1000
+#define PAD_R1 0x0800
+#define PAD_L1 0x0400
+#define PAD_R2 0x0200
+#define PAD_L2 0x0100
/*
* Pad states
@@ -98,21 +98,21 @@
{
unsigned char ok;
unsigned char mode;
- unsigned char btns[2];
+ unsigned short btns;
// joysticks
unsigned char rjoy_h;
unsigned char rjoy_v;
unsigned char ljoy_h;
unsigned char ljoy_v;
// pressure mode
+ unsigned char right_p;
unsigned char left_p;
- unsigned char rigth_p;
unsigned char up_p;
unsigned char down_p;
unsigned char triangle_p;
unsigned char circle_p;
- unsigned char square_p;
unsigned char cross_p;
+ unsigned char square_p;
unsigned char l1_p;
unsigned char r1_p;
unsigned char l2_p;
Code: Select all
paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]);
Code: Select all
paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]);
Code: Select all
paddata = buttons.btns;
Code: Select all
#define PAD_BUTTONS(buttons) (0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]))
they are packaged already, new version requires new work like fixing API changes. we cant get too afraid of changing bad code in ps2sdk aslong as we fix the 'samples' using it.pixel wrote:ps2menu ? ps2bor ? keylauncher ? neogeo/cdps2 ? all the dummy games examples such as the tetris, the space invaders, etc ? aww :) Is that all ? :P
All you did was change code, right ? Don't sweat it. Things will be fine.radad wrote:I get the feeling that most agree with the change so I have updated cvs with the changes. I will take the blame if anyone complains.
Hehe, I'm not complaining. Just glad I found this thread.radad wrote:I get the feeling that most agree with the change so I have updated cvs with the changes. I will take the blame if anyone complains.
ok tried this substituited all 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]); with paddata = buttons.btns;. but i don't work right. i have a function to the start button and it execute it 2 times! and there is nothing inserted, also it does two left press without touching anithing also sometimes i have to press two times or press longer a button or it don't work!radad wrote:I agree with your concerns but the fix is simple. Most apps have copied the pad example:
The fix is to replace it with this:Code: Select all
paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]);
See, they are extracting it into a short so they can use the defines. It is now simpler.Code: Select all
paddata = buttons.btns;
Code: Select all
if (controllerReturn != 0)
{
//paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]); sdk 1.1 or before
paddata = buttons.btns;
new_pad = paddata & ~old_pad;
old_pad = paddata;
}