Skip to content

Commit

Permalink
testbdm
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Aug 22, 2024
1 parent c189809 commit f716b3a
Show file tree
Hide file tree
Showing 25 changed files with 346 additions and 10 deletions.
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.SILENT:

BDM ?= 1

EE_OBJ_DIR = obj/
EE_INC_DIR = include/
EE_BIN_DIR = bin/
Expand All @@ -10,6 +12,7 @@ EE_BIN = $(EE_BIN_DIR)SMS.elf
EE_INCS = -I$(EE_INC_DIR) -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I$(PS2SDK)/ports/include -I$(PS2SDK)/sbv/include
EE_LDFLAGS = -L$(PS2SDK)/sbv/lib -L$(PS2SDK)/ee/lib -L$(PS2SDK)/ports/lib -L$(EE_SRC_DIR)/lzma2
EE_LIBS = -lpatches -lc -lkernel -lmf
EE_CFLAGS := -Dmemset=mips_memset -Dmemcpy=mips_memcpy -D_EE -O2 -G8192 -mgpopt -Wall -mno-check-zero-division

EE_OBJS = main.o SMS_OS.o SMS_GS_0.o SMS_GS_1.o SMS_GS_2.o SMS_Timer.o \
SMS_MP123Core.o SMS_FileContext.o SMS_H263.o \
Expand All @@ -36,6 +39,17 @@ EE_OBJS = main.o SMS_OS.o SMS_GS_0.o SMS_GS_1.o SMS_GS_2.o SMS_Timer.o
SMS_JPEGData.o SMS_JPEG.o SMS_Rescale.o SMS_MPEGInit.o \
lzma2.o xz_crc32.o xz_dec_lzma2.o xz_dec_stream.o

ifeq ($(BDM),1)
IRX_DIR = irx/
IOP_OBJS = bdm_irx.o bdmfs_fatfs_irx.o usbd_irx.o usbmass_bd_irx.o sio2man_irx.o \
mx4sio_bd_irx.o mcman_irx.o mcserv_irx.o \
padman_irx.o iomanx_irx.o
# filexio_irx.o -lfileXio
EE_LIBS += -lmc -lpadx
EE_OBJS += $(IOP_OBJS)
EE_CFLAGS += -DBDM
endif

EE_OBJS := $(EE_OBJS:%=$(EE_OBJ_DIR)%)

all: $(EE_OBJ_DIR) $(EE_BIN_DIR) $(EE_BIN)
Expand All @@ -47,6 +61,15 @@ $(EE_OBJ_DIR):
$(EE_BIN_DIR):
@$(MKDIR) -p $(EE_BIN_DIR)

vpath %.irx $(IRX_DIR)

$(EE_OBJ_DIR)%_irx.c: %.irx
bin2c $< $@ $(*F)_irx
@sed 's/aligned(16)/aligned(16), section(\"data\")/' -i $@

$(EE_OBJ_DIR)%.o : $(EE_OBJ_DIR)%.c
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@

$(EE_OBJ_DIR)%.o : $(EE_SRC_DIR)%.c
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@

Expand Down Expand Up @@ -84,5 +107,3 @@ clean:
@rm -f -r $(EE_BIN_DIR) $(EE_OBJ_DIR)

include $(PS2SDK)/Defs.make

EE_CFLAGS := -Dmemset=mips_memset -Dmemcpy=mips_memcpy -D_EE -O2 -G8192 -mgpopt -Wall -mno-check-zero-division
2 changes: 2 additions & 0 deletions include/SMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ typedef unsigned int size_t;

#include <tamtypes.h>

#include <stdio.h>

extern unsigned char* g_pSPRTop;
extern void* g_pSynthBuffer;
extern int g_XShift;
Expand Down
31 changes: 31 additions & 0 deletions include/SMS_MC.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
#ifndef __SMS_MC_H
#define __SMS_MC_H

#ifdef BDM
#include <libmc.h>

#define MC_Sync(x) mcSync(0, NULL, x)
#define MC_OpenS mcOpen
#define MC_SeekS mcSeek
#define MC_ReadS mcRead
#define MC_CloseS mcClose

#define SMS_MCTable sceMcTblGetDir

#define SMS_MCIcon mcIcon
#define m_Header head
#define m_Title title
#define m_Offset nlOffset
#define m_Trans trans
#define m_ClrBg bgCol
#define m_LightDir lightDir
#define m_LightCol lightCol
#define m_LightAmb lightAmbient
#define m_View view
#define m_Copy copy
#define m_Del del

#define MC_GetInfo mcGetInfo
#define MC_GetDir mcGetDir

#define MC_Init(x...) mcInit(MC_TYPE_XMC)

#else
typedef struct SMS_MCTable {

struct {
Expand Down Expand Up @@ -86,4 +116,5 @@ int MC_SeekS ( int, int, int );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* bdm */
#endif /* __SMS_MC_H */
59 changes: 59 additions & 0 deletions include/SMS_PAD.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,64 @@
#ifndef __SMS_PAD_H
#define __SMS_PAD_H

#ifdef BDM
#include <libpad.h>
int ReadCombinedPadStatus(void);
int ReadPadStatus(int port, int slot);
int ReadPadStatus_raw(int port, int slot);
int ReadCombinedPadStatus_raw(void);
void PadDeinitPads(void);
void PadInitPads(void);
#define SMS_PadButtonStatus padButtonStatus
#define PAD_Init() PadInitPads()
#define PAD_Quit() PadDeinitPads()

#define PAD_OpenPort(a,b,c) //padPortOpen(a,b,c)
#define PAD_ClosePort(a,b) //padPortClose(a,b)

#define PAD_ReqState padGetReqState
#define PAD_SetReqState padSetReqState
#define PAD_State padGetState
#define PAD_Read ReadPadStatus_raw
#define PAD_SetMainMode padSetMainMode

#define SMS_PAD_LEFT PAD_LEFT
#define SMS_PAD_DOWN PAD_DOWN
#define SMS_PAD_RIGHT PAD_RIGHT
#define SMS_PAD_UP PAD_UP
#define SMS_PAD_START PAD_START
#define SMS_PAD_R3 PAD_R3
#define SMS_PAD_L3 PAD_L3
#define SMS_PAD_SELECT PAD_SELECT
#define SMS_PAD_SQUARE PAD_SQUARE
#define SMS_PAD_CROSS PAD_CROSS
#define SMS_PAD_CIRCLE PAD_CIRCLE
#define SMS_PAD_TRIANGLE PAD_TRIANGLE
#define SMS_PAD_R1 PAD_R1
#define SMS_PAD_L1 PAD_L1
#define SMS_PAD_R2 PAD_R2
#define SMS_PAD_L2 PAD_L2

#define SMS_PAD_STATE_DISCONN PAD_STATE_DISCONN
#define SMS_PAD_STATE_FINDPAD PAD_STATE_FINDPAD
#define SMS_PAD_STATE_FINDCTP1 PAD_STATE_FINDCTP1
#define SMS_PAD_STATE_EXECCMD PAD_STATE_EXECCMD
#define SMS_PAD_STATE_STABLE PAD_STATE_STABLE
#define SMS_PAD_STATE_ERROR PAD_STATE_ERROR

#define SMS_PAD_RSTAT_COMPLETE PAD_RSTAT_COMPLETE
#define SMS_PAD_RSTAT_FAILED PAD_RSTAT_FAILED
#define SMS_PAD_RSTAT_BUSY PAD_RSTAT_BUSY

#define SMS_PAD_MMODE_DIGITAL PAD_MMODE_DIGITAL
#define SMS_PAD_MMODE_DUALSHOCK PAD_MMODE_DUALSHOCK

#define SMS_PAD_MMODE_UNLOCK PAD_MMODE_UNLOCK
#define SMS_PAD_MMODE_LOCK PAD_MMODE_LOCK

#define SMS_PAD_STATE_FINDCTP1 PAD_STATE_FINDCTP1
#else

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
Expand Down Expand Up @@ -90,4 +148,5 @@ int PAD_SetMainMode ( int, int, int, int );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* bdm */
#endif /* __SMS_PAD_H */
Binary file added irx/bdm.irx
Binary file not shown.
Binary file added irx/bdmfs_fatfs.irx
Binary file not shown.
Binary file added irx/filexio.irx
Binary file not shown.
Binary file added irx/iomanx.irx
Binary file not shown.
Binary file added irx/mcman.irx
Binary file not shown.
Binary file added irx/mcserv.irx
Binary file not shown.
Binary file added irx/mx4sio_bd.irx
Binary file not shown.
Binary file added irx/padman.irx
Binary file not shown.
Binary file added irx/sio2man.irx
Binary file not shown.
Binary file added irx/usbd.irx
Binary file not shown.
Binary file added irx/usbmass_bd.irx
Binary file not shown.
10 changes: 9 additions & 1 deletion src/SMS_Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ int SMS_LoadConfig ( void ) {

MC_GetInfo ( g_MCSlot, 0, &lRes, &lRes, &lRes );
MC_Sync ( &lRes );
printf("lRes=%d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", lRes);

if ( lRes > -2 ) {

Expand Down Expand Up @@ -324,8 +325,15 @@ int SMS_SaveConfig ( void ) {

MC_GetInfo ( g_MCSlot, 0, &lRes, &lRes, &lRes );
MC_Sync ( &lRes );

printf("lRes=%d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", lRes);
#ifdef BDM
if ( lRes > -5 ) { /* returns a value of -4 first attempt then 0 on second implying its undetected but then the same card..
weird SMS_LoadConfig() is fine.. -1 then 0 (new card, same card)..(its called twice in guiinit)..
_saveipc_handler() in SMS_GUIMenuSMS.c & SMS_SaveConfig() in SMS_Config.c have the same result.
calling MC_GetInfo() & MC_Sync() outside of SMS_LoadConfig() returns -4 on first attempt. */
#else
if ( lRes > -2 ) {
#endif

SMS_MCTable lDir __attribute__( ( aligned( 64 ) ) );

Expand Down
6 changes: 5 additions & 1 deletion src/SMS_FileContext.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#include "SMS_FileContext.h"
#include "SMS_Sounds.h"
#include "SMS_GUI.h"

#include <malloc.h>
#include <string.h>
Expand Down Expand Up @@ -1435,7 +1436,10 @@ static int STIO_Stream ( FileContext* apCtx, unsigned int aStartPos, unsigned in
) retVal = lnRead;
#else /* PS2 */
fioLseek ( lpPriv -> m_FD, apCtx -> m_CurPos, SEEK_SET );
retVal = lnRead = fioRead ( lpPriv -> m_FD, apCtx -> m_pBuff[ 0 ], apCtx -> m_BufSize );
printf ( "STIO_Stream->read()\n" );
printf ( "fp=%s fs=%d\n", apCtx->m_pPath, apCtx->m_Size );
retVal = lnRead = fioRead ( lpPriv -> m_FD, apCtx -> m_pBuff[ 0 ], apCtx -> m_BufSize ); //mx stuck here
printf ( "STIO_Stream->read() finshed\n" );
#endif /* _WIN32 */
apCtx -> m_pPos = apCtx -> m_pBuff[ 0 ];
apCtx -> m_pEnd = apCtx -> m_pPos + retVal;
Expand Down
11 changes: 11 additions & 0 deletions src/SMS_FileDir.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ void SMS_FileDirInit ( char* apPath ) {
char* lpPtr;
SMS_ListNode* lpNode;

#ifdef BDM
if ( g_CMedia == 0 && ( g_IOPFlags & SMS_IOPF_UMS ) ) g_pUSB[ 4 ] = g_CUnit + '0';
#else
if ( g_CMedia == 0 && ( g_IOPFlags & SMS_IOPF_UMS ) ) g_pUSB[ 3 ] = g_CUnit + '0';
#endif

GUI_Status ( STR_READING_MEDIA.m_pStr );

Expand All @@ -239,7 +243,14 @@ void SMS_FileDirInit ( char* apPath ) {

strcpy ( g_CWD, g_pDevName[ g_CMedia ] );

/*#ifdef BDM
if ( g_CMedia == 0 ) *( unsigned int* )&g_CWD[ 5 ] = 0x0000003A;
else *( unsigned int* )&g_CWD[ 4 ] = 0x0000003A;
#else
*( unsigned int* )&g_CWD[ 4 ] = 0x0000003A;
#endif*/

strcat (g_CWD, ":" );

if ( g_CMedia == 2 ) {

Expand Down
24 changes: 20 additions & 4 deletions src/SMS_GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ static unsigned char s_PadBuf0[ 256 ] __attribute__( ( aligned( 64 ), sectio
unsigned char g_PadBuf1[ 256 ] __attribute__( ( aligned( 64 ), section( ".data" ) ) );
static unsigned char s_Stack [ 4096 ] __attribute__( ( aligned( 16 ), section( ".data" ) ) );

#ifdef BDM
unsigned int g_MassFlags;
#endif

static void ( *QueryPad ) ( void );

static void QueryPad0 ( void );
Expand Down Expand Up @@ -365,6 +369,10 @@ static int _gui_thread ( void* apParam ) {

DiskType lDiskType;

#ifdef BDM
s_DevFlags |= g_MassFlags;
#endif

if ( s_DevFlags & DEVF_NETWORK ) {

s_DevFlags &= ~DEVF_NETWORK;
Expand All @@ -379,28 +387,36 @@ static int _gui_thread ( void* apParam ) {

s_Event |= ( GUI_MSG_MOUNT_BIT | GUI_MSG_USB | ( 0LL << 56 ) );
s_DevFlags &= ~DEVF_USB_CONNECT_0;

#ifdef BDM
g_MassFlags &= ~DEVF_USB_CONNECT_0;
#endif
goto raiseEvent;

} else if ( s_DevFlags & DEVF_USB_CONNECT_1 ) {

s_Event |= ( GUI_MSG_MOUNT_BIT | GUI_MSG_USB | ( 1LL << 56 ) );
s_DevFlags &= ~DEVF_USB_CONNECT_1;

#ifdef BDM
g_MassFlags &= ~DEVF_USB_CONNECT_1;
#endif
goto raiseEvent;

} else if ( s_DevFlags & DEVF_USB_CONNECT_2 ) {

s_Event |= ( GUI_MSG_MOUNT_BIT | GUI_MSG_USB | ( 2LL << 56 ) );
s_DevFlags &= ~DEVF_USB_CONNECT_2;

#ifdef BDM
g_MassFlags &= ~DEVF_USB_CONNECT_2;
#endif
goto raiseEvent;

} else if ( s_DevFlags & DEVF_USB_CONNECT_3 ) {

s_Event |= ( GUI_MSG_MOUNT_BIT | GUI_MSG_USB | ( 3LL << 56 ) );
s_DevFlags &= ~DEVF_USB_CONNECT_3;

#ifdef BDM
g_MassFlags &= ~DEVF_USB_CONNECT_3;
#endif
goto raiseEvent;

} else if ( s_DevFlags & DEVF_USB_DISCONNECT_0 ) {
Expand Down
4 changes: 4 additions & 0 deletions src/SMS_GUIDevMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ static int GUIDevMenu_HandleMount ( GUIDevMenu* apMenu, unsigned int aMount, u64

if ( !lDevID ) {
unsigned char lUnitID = ( aMsg >> 56 ) & 15;
#ifdef BDM
lDevName[ 4 ] = lUnitID + '0';
#else
lDevName[ 3 ] = lUnitID + '0';
#endif
lpItem -> m_UnitID = lUnitID;
} /* end if */

Expand Down
7 changes: 7 additions & 0 deletions src/SMS_GUIMenuSMS.c
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,14 @@ static void _saveipc_handler ( GUIMenu* apMenu, int aDir ) {
MC_GetInfo ( g_MCSlot, 0, &lRes, &lRes, &lRes );
MC_Sync ( &lRes );

#ifdef BDM
if ( lRes > -5 ) { /* returns a value of -4 first attempt then 0 on second implying its undetected but then the same card..
weird SMS_LoadConfig() is fine.. -1 then 0 (new card, same card)..(its called twice in guiinit)..
_saveipc_handler() in SMS_GUIMenuSMS.c & SMS_SaveConfig() in SMS_Config.c have the same result.
calling MC_GetInfo() & MC_Sync() outside of SMS_LoadConfig() returns -4 on first attempt. */
#else
if ( lRes > -2 ) {
#endif

SMS_MCTable lTbl __attribute__( ( aligned( 64 ) ) );

Expand Down
7 changes: 7 additions & 0 deletions src/SMS_History.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ void SMS_HistoryLoad ( void ) {
unsigned short lSize;
SMS_ListNode* lpNode;

#ifdef BDM
int x;
if ( MC_ReadS ( lFD, &lSize, 2 ) == 0 ) {
MC_Sync ( &x );
if ( x != 2 ) break;
#else
if ( MC_ReadS ( lFD, &lSize, 2 ) == 2 ) {
#endif
lpNode = SMS_ListPushBackBuf ( s_pHst, lSize + 1 );
MC_ReadS ( lFD, _STR( lpNode ), lSize );
MC_ReadS ( lFD, &lpNode -> m_Param, 8 );
Expand Down
Loading

0 comments on commit f716b3a

Please sign in to comment.