Skip to content

Commit

Permalink
Add basic controller pad test (prints button presses to console)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraembedded authored and JaCzekanski committed Feb 11, 2021
1 parent 5933772 commit 072a2f2
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
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 \
Expand Down
4 changes: 4 additions & 0 deletions input/pad/Makefile
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
99 changes: 99 additions & 0 deletions input/pad/main.cpp
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;
}

0 comments on commit 072a2f2

Please sign in to comment.