Trouble using DualShock controllers

BIOS, Controllers, Memory Cards, Serial I/O, Parallel I/O, etc.
Post Reply
User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Trouble using DualShock controllers

Post by LameGuy64 » October 15th, 2014, 12:58 pm

On a real console, this controller prototype I made works fine but for some reason, it crashes on a emulator (no$psx to be exact) after exactly 3 frames have passed... Have I done something wrong on how I initialize the controller library or what?

Also, I don't know how to control the vibrators of the controller or automatically activate analog mode when such a controller is detected... The docs lack enough detail on how to pull this off and Sony's controller example is completely broken (missing files) which doesn't help much with this situation.

Code: Select all

#include <stdio.h>
#include <sys/types.h>
#include <libgte.h>
#include <libgpu.h>
#include <libetc.h>
#include <libapi.h>
#include <libpad.h>
#include <libmcrd.h>


// Pad info struct (to simplify things a lot)
typedef struct {
	u_char   status;		// Always 0 if a controller is detected
	u_char   psize:4;
	u_char   type:4;
	
	struct {
		u_short select:1;
		u_short l3:1;
		u_short r3:1;
		u_short start:1;
		u_short up:1;
		u_short left:1;
		u_short down:1;
		u_short right:1;
		u_short l2:1;
		u_short r2:1;
		u_short l1:1;
		u_short r1:1;
		u_short triangle:1;
		u_short circle:1;
		u_short cross:1;
		u_short square:1;
	} button;
	
	u_char   rstickx;
	u_char   rsticky;
	u_char   lstickx;
	u_char   lsticky;
	
} PADINFO;


char	PadBuff[2][34];	// Buffer to store 34 bytes worth of pad data

// For controlling the vibrators of a DualShock controller (can't get it to work though)
u_char	PadActAlign[] = { 0x00, 0x01, 0xff, 0xff, 0xff, 0xff };
u_char	PadAct[6] = {0};


// Very basic display stuff
DISPENV	disp;
DRAWENV draw;
RECT	crect;
int		bnum=0;


int main() {
	
	int  i,result,count;
	long Slot1result, Slot2result, CardCmd=0;
	
	PADINFO PadStats[2];
	
	
	// Reset GPU
	ResetGraph(0);
	
	// Setup font environment
	FntLoad(960, 0);
	FntOpen(0, 0, 320, 240, 0, 512);

	
	// Init controller
	PadInitDirect(&PadBuff[0][0], &PadBuff[1][0]);
	PadSetAct(0x00, PadAct, 6);
	PadSetActAlign(0x00, PadActAlign);
	PadStartCom();
	
	
	// Main loop
	while(1) {
		
		ClearImage(&crect, 0, 64, 0);
		FntPrint("\n\n %d\n", count);
		
		for (i=0; i<2; i++) {
			
			// Copy pad data from the buffers to one of the PADINFO structs for easy interpretation
			memcpy((u_char*)&PadStats[i], (u_char*)&PadBuff[i][0], sizeof(PadStats));
			*(u_short*)&PadStats[i].button ^= 0xffff;
			
			if (PadStats[i].status == 0) {
				
				FntPrint(" CONTROLLER %d DATA:\n", i+1);
				FntPrint("  STAT:%d\n", PadStats[i].status);
				FntPrint("  TYPE:%d - ", PadStats[i].type);
				switch(PadStats[i].type) {
					case 4:
						FntPrint("16-BUTTON PAD\n");
						break;						
					case 5:
						FntPrint("ANALOG JOYSTICK\n");
						break;
					case 7:
						FntPrint("ANALOG CONTROLLER\n");
						break;
					default:
						FntPrint("UNKNOWN/NOT SUPPORTED\n");
						break;
				}
				
				switch(PadStats[i].type) {
					case 5:
					case 7:
						FntPrint("  RGT ANALOG X:%d\n", PadStats[i].rstickx);
						FntPrint("  RGT ANALOG Y:%d\n", PadStats[i].rsticky);
						FntPrint("  LFT ANALOG X:%d\n", PadStats[i].lstickx);
						FntPrint("  LFT ANALOG Y:%d\n", PadStats[i].lsticky);
						
						if (i==0) {
							if (PadStats[i].button.l3) PadAct[0] = 255;
							if (PadStats[i].button.r3) PadAct[1] = 255;
						}
						
					case 4:
						FntPrint("\n ");
						if (PadStats[i].button.up)			FntPrint("UP ");
						if (PadStats[i].button.down)		FntPrint("DOWN ");
						if (PadStats[i].button.left)		FntPrint("LEFT ");
						if (PadStats[i].button.right)		FntPrint("RIGHT ");
						
						if (PadStats[i].button.cross)		FntPrint("CROSS ");
						if (PadStats[i].button.square)		FntPrint("SQUARE ");
						if (PadStats[i].button.circle)		FntPrint("CIRCLE ");
						if (PadStats[i].button.triangle)	FntPrint("TRIANGLE ");
						
						if (PadStats[i].button.start)		FntPrint("START ");
						if (PadStats[i].button.select)		FntPrint("SELECT ");
						if (PadStats[i].button.l1)			FntPrint("L1 ");
						if (PadStats[i].button.r1)			FntPrint("R1 ");
						if (PadStats[i].button.l2)			FntPrint("L2 ");
						if (PadStats[i].button.r2)			FntPrint("R2 ");
						if (PadStats[i].button.l3)			FntPrint("L3 ");
						if (PadStats[i].button.r3)			FntPrint("R3 ");
						
						break;
						
				}
				
				
				FntPrint("\n\n");
				
			} else {
				FntPrint(" NO CONTROLLER DETECTED IN PORT %d\n", i+1);
			}
			
		}
		
		crect.w = 320;	crect.h = 240;
		crect.x = 0;	crect.y = 256*(bnum);
		SetDefDispEnv(&disp, 0, 256*(1-bnum), 320, 240);
		SetDefDrawEnv(&draw, 0, 256*(bnum), 320, 240);
		bnum ^= 1;
		
		FntFlush(-1);
		DrawSync(0);
		
		VSync(0);
		PutDispEnv(&disp);
		PutDrawEnv(&draw);
		SetDispMask(1);
		
		count = (count+1)%60;
		
	}
	
}
Any useful help will be gladly appreciated!
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » October 15th, 2014, 6:18 pm

Code: Select all

SCEE Dual Shock Technical Article #1
Author: Mike Kavallierou (Mike_Kavallierou@*.*.com)

Revision History
Created         Can't remember
Modified        11/08/98 -      Added actuator loading checks to
				multitap sample
                                added some FAQ's
Modified        22/12/98 -      Added correct handling of other expanded
				controllers and detection of JogCon to
				multitap sample

Archive created: pkzip -r -P dualshck.zip *.* 
================================================================

This archive contains Dualsh.doc, an overview of the
Dual Shock controller.


Directory Structure
===================

DROPOUT
Document and source code detailing how to get around
the problem of the Dual Shock dropping out of analog mode
during a games' execution.

MULTITAP
Using multiple Dual Shock controllers
DUALSHCK.ZIP
You do not have the required permissions to view the files attached to this post.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » October 16th, 2014, 11:48 am

Thanks! That should be enough for solving my controller issues.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests