 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Nov 23, 2004 9:00 am Post subject: 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). |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Nov 23, 2004 10:46 pm Post subject: |
|
|
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:
| Code: | 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;
|
I tested this functionality with the following code:
| Code: | #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;
}
|
Can others please test it to make the changes are correct?
Last edited by radad on Thu Nov 25, 2004 9:23 am; edited 1 time in total |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Wed Nov 24, 2004 10:20 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Wed Nov 24, 2004 11:18 am Post subject: |
|
|
sorry, here is cvs unified diff:
| Code: | 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;
|
|
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Mon Dec 13, 2004 12:29 pm Post subject: |
|
|
| If everyone agrees with the changes I would like to get it checked in. Could someone please do it for me? Or should I get cvs write access myself? |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Mon Dec 13, 2004 4:46 pm Post subject: |
|
|
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... _________________ 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. |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Mon Dec 13, 2004 4:59 pm Post subject: |
|
|
| On that topic, when would be a good time to fix the design? |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Dec 14, 2004 9:40 am Post subject: |
|
|
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:
| Code: | | paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]); |
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. |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Tue Dec 14, 2004 4:48 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Wed Dec 15, 2004 1:56 am Post subject: |
|
|
Heh. No matter what you do in cvs someone will complain. :)
Fix the spelling error. If nobody complains (much), then do the bigger change. |
|
| Back to top |
|
 |
blackdroid
Joined: 17 Jan 2004 Posts: 564 Location: Sweden
|
Posted: Wed Dec 15, 2004 2:27 am Post subject: |
|
|
99% of nothing is still 0 pixel, cant honestly figure out if there is anything else thatn the pad sample that actually uses the libpad _________________ Kung VU |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Wed Dec 15, 2004 2:53 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Wed Dec 15, 2004 9:28 am Post subject: |
|
|
I agree with your concerns but the fix is simple. Most apps have copied the pad example:
| Code: | | paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]); |
The fix is to replace it with this:
| Code: | | paddata = buttons.btns; |
See, they are extracting it into a short so they can use the defines. It is now simpler. |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Wed Dec 15, 2004 9:35 am Post subject: |
|
|
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:
| Code: | | #define PAD_BUTTONS(buttons) (0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1])) |
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. |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Wed Dec 15, 2004 12:07 pm Post subject: |
|
|
| Someone should get this radad guy some cvs write access, too. :) |
|
| Back to top |
|
 |
blackdroid
Joined: 17 Jan 2004 Posts: 564 Location: Sweden
|
Posted: Wed Dec 15, 2004 11:33 pm Post subject: |
|
|
| 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 |
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. _________________ Kung VU |
|
| Back to top |
|
 |
evilo

Joined: 22 Apr 2004 Posts: 230
|
Posted: Thu Dec 16, 2004 12:00 am Post subject: |
|
|
| yeah, if it can help to have a nice & clean sdk, it worth the pain to make some minor modifications (this one or others) to source code using it. But be sure to document it correctly with the next official release (big warning to avoid bad side-effect) |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Dec 21, 2004 9:18 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Dec 21, 2004 10:14 pm Post subject: |
|
|
| 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. |
All you did was change code, right ? Don't sweat it. Things will be fine.
Its when you touch text headers, text files, etc... non-code things that gets people all worked up. ;)
Hi Mr. B.! :) |
|
| Back to top |
|
 |
BraveDog
Joined: 30 Dec 2004 Posts: 29 Location: Cleveland
|
Posted: Thu Dec 30, 2004 3:01 am Post subject: |
|
|
| 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.
I updated my emulator to work with this.
-BraveDog |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Sun Jan 02, 2005 9:51 pm Post subject: |
|
|
| radad wrote: | I agree with your concerns but the fix is simple. Most apps have copied the pad example:
| Code: | | paddata = 0xffff ^ ((buttons.btns[0] << 8) | buttons.btns[1]); |
The fix is to replace it with this:
| Code: | | paddata = buttons.btns; |
See, they are extracting it into a short so they can use the defines. It is now simpler. |
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!
this is what i use:
| Code: |
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;
}
|
|
|
| Back to top |
|
 |
evilo

Joined: 22 Apr 2004 Posts: 230
|
Posted: Sun Jan 02, 2005 10:59 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
radad
Joined: 19 May 2004 Posts: 246 Location: Melbourne, Australia
|
Posted: Tue Jan 04, 2005 9:01 am Post subject: |
|
|
| You are correct. Sorry for that. I have fixed it up in cvs now. It would be nice if it could be updated in the 1.2 release also. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|