-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic controller pad test (prints button presses to console)
- Loading branch information
1 parent
5933772
commit 072a2f2
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
TOPTARGETS = build clean | ||
|
||
IMAGES = common \ | ||
input/pad \ | ||
cdrom/disc-swap \ | ||
cdrom/getloc \ | ||
cdrom/timing \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TARGET = pad.elf | ||
#CFLAGS = -g -msoft-float -O2 -D__PLAYSTATION__ -fno-builtin -fdata-sections -ffunction-sections -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare | ||
|
||
include ../../common-test.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <psxapi.h> | ||
#include <psxgpu.h> | ||
#include <psxetc.h> | ||
#include <psxpad.h> | ||
#include <io.h> | ||
|
||
#define SCR_W 320 | ||
#define SCR_H 240 | ||
|
||
static DISPENV disp; | ||
static DRAWENV draw; | ||
|
||
static char padBuffer[2][34]; | ||
static unsigned short buttons = 0xffff, prevButtons = 0xffff; | ||
|
||
static bool BUTTON(uint16_t button) | ||
{ | ||
return (buttons & button) == 0 && ((prevButtons & button) != 0); | ||
} | ||
|
||
static void ButtonUpdate(void) | ||
{ | ||
prevButtons = buttons; | ||
buttons = ((PADTYPE*)padBuffer[0])->btn; | ||
} | ||
|
||
int main() | ||
{ | ||
printf("PAD test (PAD1)\n"); | ||
|
||
ResetGraph(0); | ||
SetDefDispEnv(&disp, 0, 0, SCR_W, SCR_H); | ||
SetDefDrawEnv(&draw, 0, 0, SCR_W, SCR_H); | ||
|
||
PutDispEnv(&disp); | ||
PutDrawEnv(&draw); | ||
SetDispMask(1); | ||
|
||
InitPAD(padBuffer[0], 34, padBuffer[1], 34); | ||
StartPAD(); | ||
ChangeClearPAD(0); | ||
|
||
while (1) | ||
{ | ||
if (BUTTON(PAD_UP)) { | ||
printf("PAD_UP\n"); | ||
} | ||
if (BUTTON(PAD_DOWN)) { | ||
printf("PAD_DOWN\n"); | ||
} | ||
if (BUTTON(PAD_LEFT)) { | ||
printf("PAD_LEFT\n"); | ||
} | ||
if (BUTTON(PAD_RIGHT)) { | ||
printf("PAD_RIGHT\n"); | ||
} | ||
if (BUTTON(PAD_SQUARE)) { | ||
printf("PAD_SQUARE\n"); | ||
} | ||
if (BUTTON(PAD_TRIANGLE)) { | ||
printf("PAD_TRIANGLE\n"); | ||
} | ||
if (BUTTON(PAD_CROSS)) { | ||
printf("PAD_X\n"); | ||
} | ||
if (BUTTON(PAD_CIRCLE)) { | ||
printf("PAD_CIRCLE\n"); | ||
} | ||
if (BUTTON(PAD_SELECT)) { | ||
printf("PAD_SEL\n"); | ||
} | ||
if (BUTTON(PAD_START)) { | ||
printf("PAD_START\n"); | ||
} | ||
if (BUTTON(PAD_L3)) { | ||
printf("PAD_L3\n"); | ||
} | ||
if (BUTTON(PAD_R3)) { | ||
printf("PAD_R3\n"); | ||
} | ||
if (BUTTON(PAD_L2)) { | ||
printf("PAD_L2\n"); | ||
} | ||
if (BUTTON(PAD_R2)) { | ||
printf("PAD_R2\n"); | ||
} | ||
if (BUTTON(PAD_L1)) { | ||
printf("PAD_L1\n"); | ||
} | ||
if (BUTTON(PAD_R1)) { | ||
printf("PAD_R1\n"); | ||
} | ||
VSync(0); | ||
ButtonUpdate(); | ||
} | ||
return 0; | ||
} |