Last active
January 12, 2024 15:43
-
-
Save Florin9doi/c4ccbe7fa2e1a62762b75c61b914f71f to your computer and use it in GitHub Desktop.
sceSircs
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
TARGET = testSirc | |
OBJS = sirc.o | |
USE_PSPSDK_LIBC = 1 | |
INCDIR = | |
CFLAGS = -O2 -G0 -Wall | |
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti | |
ASFLAGS = $(CFLAGS) | |
EXTRA_TARGETS = EBOOT.PBP | |
PSP_EBOOT_TITLE = testSirc | |
LIBDIR = | |
LDFLAGS = -mno-crt0 -nostartfiles | |
LIBS = -lpspsircs | |
PSPSDK=$(shell psp-config --pspsdk-path) | |
include $(PSPSDK)/lib/build.mak |
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
/* | |
* PSP Software Development Kit - https://github.com/pspdev | |
* ----------------------------------------------------------------------- | |
* Licensed under the BSD license, see LICENSE in PSPSDK root for details. | |
* | |
* main.c - Infrared Remote example | |
* | |
* Copyright (c) 2005 Marcus R. Brown <[email protected]> | |
* Copyright (c) 2005 James Forshaw <[email protected]> | |
* Copyright (c) 2005 John Kelley <[email protected]> | |
* Copyright (c) 2005 Matthew H <[email protected]> | |
* | |
* $$ | |
*/ | |
#include <pspkernel.h> | |
#include <pspdebug.h> | |
#include <pspdisplay.h> | |
#include <pspctrl.h> | |
#include <pspsircs.h> | |
#include <stdlib.h> | |
#include <string.h> | |
PSP_MODULE_INFO("SIRCS", 0, 1, 1); | |
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); | |
#define SIRCS_ADDR_DVD 0x1b5a | |
#define SIRCS_CMD_RESET 0x15 | |
#define SIRCS_CMD_EJECT 0x16 | |
#define SIRCS_CMD_SELECT 0x50 | |
#define SIRCS_CMD_L3 0x51 | |
#define SIRCS_CMD_R3 0x52 | |
#define SIRCS_CMD_START 0x53 | |
#define SIRCS_CMD_UP 0x54 | |
#define SIRCS_CMD_RIGHT 0x55 | |
#define SIRCS_CMD_DOWN 0x56 | |
#define SIRCS_CMD_LEFT 0x57 | |
#define SIRCS_CMD_L2 0x58 | |
#define SIRCS_CMD_R2 0x59 | |
#define SIRCS_CMD_L1 0x5a | |
#define SIRCS_CMD_R1 0x5b | |
#define SIRCS_CMD_TRIANGLE 0x5c | |
#define SIRCS_CMD_CIRCLE 0x5d | |
#define SIRCS_CMD_CROSS 0x5e | |
#define SIRCS_CMD_SQUARE 0x5f | |
void send_code(int type, int dev, int cmd) { | |
struct sircs_data sd; | |
int ret; | |
int count = 20; // this seems like a good number | |
sd.type = type; | |
sd.cmd = cmd & 0x7f; | |
sd.dev = dev & 0x1fff; | |
ret = sceSircsSend(&sd, count); | |
if (ret < 0) { | |
pspDebugScreenPrintf("sceSircsSend returned %d\n", ret); | |
} | |
} | |
/* Exit callback */ | |
int exit_callback(int arg1, int arg2, void *common) { | |
sceKernelExitGame(); | |
return 0; | |
} | |
/* Callback thread */ | |
int CallbackThread(SceSize args, void *argp) { | |
int callbackID = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); | |
sceKernelRegisterExitCallback(callbackID); | |
sceKernelSleepThreadCB(); | |
return 0; | |
} | |
/* Sets up the callback thread and returns its thread id */ | |
int SetupCallbacks(void) { | |
int threadID = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0); | |
if(threadID >= 0) { | |
sceKernelStartThread(threadID, 0, 0); | |
} | |
return threadID; | |
} | |
int main_thread(SceSize args, void *argp) { | |
SceCtrlData pad; | |
u32 buttonsold = 0; | |
int sirc_bits = 20; // # of bits in code, choose from 12, 15 or 20 | |
int i; | |
SetupCallbacks(); | |
pspDebugScreenInit(); | |
sceCtrlSetSamplingCycle(0); | |
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); | |
pspDebugScreenPrintf("Sircs Example\n"); | |
pspDebugScreenPrintf("-------\n"); | |
pspDebugScreenPrintf("This can be used to control a PS2\n"); | |
pspDebugScreenPrintf("Press any button\n\n"); | |
pspDebugScreenPrintf(" ________________________ \n"); | |
pspDebugScreenPrintf(" /_L1_/ \\_R1_\\ \n"); | |
pspDebugScreenPrintf(" / /\\ /\\ \\ \n"); | |
pspDebugScreenPrintf(" | < > [] O | \n"); | |
pspDebugScreenPrintf(" | \\/ X | \n"); | |
pspDebugScreenPrintf(" \\_____ Select Start _____/ \n"); | |
pspDebugScreenPrintf(" \\____\\______________/____/ \n"); | |
do { | |
sceCtrlReadBufferPositive(&pad, 1); | |
if (pad.Buttons != buttonsold) { | |
struct { | |
int psp_button; | |
int sirc_command; | |
} commands[] = { | |
{ PSP_CTRL_SELECT, SIRCS_CMD_SELECT }, | |
{ PSP_CTRL_START, SIRCS_CMD_START }, | |
{ PSP_CTRL_UP, SIRCS_CMD_UP }, | |
{ PSP_CTRL_RIGHT, SIRCS_CMD_RIGHT }, | |
{ PSP_CTRL_DOWN, SIRCS_CMD_DOWN }, | |
{ PSP_CTRL_LEFT, SIRCS_CMD_LEFT }, | |
{ PSP_CTRL_LTRIGGER, SIRCS_CMD_L1 }, | |
{ PSP_CTRL_RTRIGGER, SIRCS_CMD_R1 }, | |
{ PSP_CTRL_TRIANGLE, SIRCS_CMD_TRIANGLE }, | |
{ PSP_CTRL_CIRCLE, SIRCS_CMD_CIRCLE }, | |
{ PSP_CTRL_CROSS, SIRCS_CMD_CROSS }, | |
{ PSP_CTRL_SQUARE, SIRCS_CMD_SQUARE }, | |
}; | |
for (i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { | |
if (pad.Buttons & commands[i].psp_button) { | |
send_code(sirc_bits, SIRCS_ADDR_DVD, commands[i].sirc_command); | |
} | |
} | |
buttonsold = pad.Buttons; | |
} | |
sceDisplayWaitVblankStart(); | |
} while (1); | |
return 0; | |
} | |
int module_start(SceSize argc, void *argv) { | |
SceUID threadID = sceKernelCreateThread("main_thread", main_thread, 0x20, 0x10000, 0, NULL); | |
if (threadID >= 0) { | |
sceKernelStartThread(threadID, argc, argv); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment