ps2sdk pad left_p/right_p
ps2sdk pad left_p/right_p
It appears that left_p and right_p in padButtonStatus need to be swapped. (Incidentally rigth_p is spelt incorrectly).
Also square_p and cross_p need to be swapped. And while we are at it I thought that the 'unsigned char btns[2]' would be better as 'unsigned short btns'.
I would like to propose the following patch to libpad.h:
I tested this functionality with the following code:
Can others please test it to make the changes are correct?
I would like to propose the following patch to libpad.h:
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;
}
Last edited by radad on Thu Nov 25, 2004 9:23 am, edited 1 time in total.
Well, your patch is not a unified diff (-u option of the diff command line; if you're using cvs, that would then be "cvs diff -u libpad.h"), so I don't know if it can be applied safely using the patch software. Can you provide a unified version of your patch ? Thanks.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
sorry, here is cvs unified diff:
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;
Huh, sorry, I completely forgot this thread.
Humm, now that I look at your patch, I think there's something wrong... Why exactly changing from unsigned char btns[2] to unsigned short btns ? That would only break backward compatibility with other ps2sdk softwares which are using pad... I can agree that the actual design maybe look a bit dodgy, but you would only get people angry to change their code afterward.
Otherwise, I can agree with the left_p, right/rigth_p and square_p, cross_p fixing...
Humm, now that I look at your patch, I think there's something wrong... Why exactly changing from unsigned char btns[2] to unsigned short btns ? That would only break backward compatibility with other ps2sdk softwares which are using pad... I can agree that the actual design maybe look a bit dodgy, but you would only get people angry to change their code afterward.
Otherwise, I can agree with the left_p, right/rigth_p and square_p, cross_p fixing...
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
I agree that it would break backwards compatibility. The problem is that the hash defines (such as PAD_LEFT) only make sense when you use this line as taken from the pad example:
This line reverses the order of the bytes, that is why I reversed the order of the hash defines. The btns array are really one value as shown by the defines which is why I changed it to a short.
I believe this is better. So we either change it now and get a few people angry or we leave it as it is and explain to every newcomer why it was done this way.
I did think about using a union so it would still be backwards compatible but the defines had to be reversed so it is not really possible.
Code: Select all
paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]);
I believe this is better. So we either change it now and get a few people angry or we leave it as it is and explain to every newcomer why it was done this way.
I did think about using a union so it would still be backwards compatible but the defines had to be reversed so it is not really possible.
I fully agree with you about the fact that the example is swapping it anyway. But I believe that 99% of the ps2sdk applications which are using the pad will break afterward and would need changes in the source (unlike the mispelled rigth_p, which shouldn't be used that much). So I won't change it unless a few people around that forum agree with that change: I don't want to be blamed alone for breaking softwares :P
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
-
- Posts: 564
- Joined: Sat Jan 17, 2004 10:22 am
- Location: Sweden
- Contact:
ps2menu ? ps2bor ? keylauncher ? neogeo/cdps2 ? all the dummy games examples such as the tetris, the space invaders, etc ? aww :) Is that all ? :P
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
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:
See, they are extracting it into a short so they can use the defines. It is now simpler.
Code: Select all
paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]);
Code: Select all
paddata = buttons.btns;
At least fix up the right_p and the square_p. No one should complain about those. I doubt anyone are using them anyway.
As an interim solution have a macro to extract the button data:
Then move all code which uses it to use the macro instead. Then one day in the future replace the array of bytes with the short. As long as everyone is using the macro there should be no problem.
As an interim solution have a macro to extract the button data:
Code: Select all
#define PAD_BUTTONS(buttons) (0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]))
-
- Posts: 564
- Joined: Sat Jan 17, 2004 10:22 am
- Location: Sweden
- Contact:
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
Kung VU
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.
Its when you touch text headers, text files, etc... non-code things that gets people all worked up. ;)
Hi Mr. B.! :)
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;
this is what i use:
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;
}
radad,
ok, I downloaded the last ps2sdk (1.2) yesterday, and get some funny recompilation session with my current wip...
the big problem is that the substitution code (following your update to the pad lib) is not working as it miss a little bit mask to work correctly
"paddata = 0xffff ^ buttons.btns;"
else it cause ALL pad buttons to be sawn as pushed together !!
So solution :
1. update pad lib ?
2. update pad sample code (that is not correct) ?
I first thought that it was due to my extraterestrian pad code (that is anyway inherited from the pad sample in the sdk), but since I'm not the only one to report problem with it ...
evilo.
ok, I downloaded the last ps2sdk (1.2) yesterday, and get some funny recompilation session with my current wip...
the big problem is that the substitution code (following your update to the pad lib) is not working as it miss a little bit mask to work correctly
"paddata = 0xffff ^ buttons.btns;"
else it cause ALL pad buttons to be sawn as pushed together !!
So solution :
1. update pad lib ?
2. update pad sample code (that is not correct) ?
I first thought that it was due to my extraterestrian pad code (that is anyway inherited from the pad sample in the sdk), but since I'm not the only one to report problem with it ...
evilo.