Skip to content

Commit

Permalink
Merge pull request #217 from uyjulian/xfromman
Browse files Browse the repository at this point in the history
Add dev9 external flash rom filesystem driver
  • Loading branch information
fjtrujy authored Aug 15, 2021
2 parents 9fd89e2 + 7300b6c commit 2de0ddf
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iop/memorycard/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

SUBDIRS = mcman mcserv
SUBDIRS = mcman mcserv xfromman

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/Rules.make
3 changes: 3 additions & 0 deletions iop/memorycard/mcman/include/mcman.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ int McReadCluster(int port, int slot, int cluster, McCacheEntry **pmce);
int McFlushCache(int port, int slot);
int McSetDirEntryState(int port, int slot, int cluster, int fsindex, int flags);

#define xfromman_IMPORTS_start DECLARE_IMPORT_TABLE(xfromman, 2, 3)
#define xfromman_IMPORTS_end END_IMPORT_TABLE

#define mcman_IMPORTS_start DECLARE_IMPORT_TABLE(mcman, 1, 1)
#define mcman_IMPORTS_end END_IMPORT_TABLE

Expand Down
62 changes: 62 additions & 0 deletions iop/memorycard/mcman/src/exports.tab
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

#ifndef BUILDING_XFROMMAN
DECLARE_EXPORT_TABLE(mcman, 1, 1)
DECLARE_EXPORT(_start)
DECLARE_EXPORT(_dummy)
Expand Down Expand Up @@ -54,5 +56,65 @@ DECLARE_EXPORT_TABLE(mcman, 1, 1)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
END_EXPORT_TABLE
#endif

#ifdef BUILDING_XFROMMAN
DECLARE_EXPORT_TABLE(xfromman, 2, 3)
DECLARE_EXPORT(_start)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_start)
DECLARE_EXPORT(McDetectCard)
DECLARE_EXPORT(McOpen)
DECLARE_EXPORT(McClose)
DECLARE_EXPORT(McRead)
DECLARE_EXPORT(McWrite)
DECLARE_EXPORT(McSeek)
DECLARE_EXPORT(McFormat)
DECLARE_EXPORT(McGetDir)
DECLARE_EXPORT(McDelete)
DECLARE_EXPORT(McFlush)
DECLARE_EXPORT(McChDir)
DECLARE_EXPORT(McSetFileInfo)
DECLARE_EXPORT(McEraseBlock2)
DECLARE_EXPORT(McReadPage)
DECLARE_EXPORT(McWritePage)
DECLARE_EXPORT(McDataChecksum)
DECLARE_EXPORT(McDetectCard2)
DECLARE_EXPORT(McGetFormat)
DECLARE_EXPORT(McGetEntSpace)
DECLARE_EXPORT(McReplaceBadBlock)
DECLARE_EXPORT(McCloseAll)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(McReadPS1PDACard)
DECLARE_EXPORT(McWritePS1PDACard)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(McUnformat)
DECLARE_EXPORT(McRetOnly)
DECLARE_EXPORT(McGetFreeClusters)
DECLARE_EXPORT(McGetMcType)
DECLARE_EXPORT(McSetPS1CardFlag)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(McGetModuleInfo)
DECLARE_EXPORT(McGetCardSpec)
DECLARE_EXPORT(McGetFATentry)
DECLARE_EXPORT(McCheckBlock)
DECLARE_EXPORT(McSetFATentry)
DECLARE_EXPORT(McReadDirEntry)
DECLARE_EXPORT(Mc1stCacheEntSetWrFlagOff)
DECLARE_EXPORT(McCreateDirentry)
DECLARE_EXPORT(McReadCluster)
DECLARE_EXPORT(McFlushCache)
DECLARE_EXPORT(McSetDirEntryState)
DECLARE_EXPORT(_dummy)
END_EXPORT_TABLE
#endif

void _dummy() {}
12 changes: 12 additions & 0 deletions iop/memorycard/mcman/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,28 @@ I_AddDrv
I_DelDrv
ioman_IMPORTS_end

#ifndef BUILDING_XFROMMAN
secrman_IMPORTS_start
I_SecrSetMcCommandHandler
I_SecrSetMcDevIDHandler
I_SecrAuthCard
secrman_IMPORTS_end
#endif

cdvdman_IMPORTS_start
I_sceCdRC
cdvdman_IMPORTS_end

#ifdef BUILDING_XFROMMAN
fls_IMPORTS_start
I_flash_detect
I_flash_get_info
I_flash_page_erase
I_flash_page_read
I_flash_page_write
fls_IMPORTS_end
#endif

stdio_IMPORTS_start
I_printf
stdio_IMPORTS_end
Expand Down
3 changes: 3 additions & 0 deletions iop/memorycard/mcman/src/irx_imports.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
/* Please keep these in alphabetical order! */

#include <cdvdman.h>
#ifdef BUILDING_XFROMMAN
#include <fls.h>
#endif
#include <intrman.h>
#include <ioman.h>
#include <loadcore.h>
Expand Down
42 changes: 42 additions & 0 deletions iop/memorycard/mcman/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ int PS1CardFlag = 1;
union mcman_pagebuf mcman_pagebuf;
union mcman_PS1PDApagebuf mcman_PS1PDApagebuf;

#ifndef BUILDING_XFROMMAN
extern struct irx_export_table _exp_mcman;
#endif
#ifdef BUILDING_XFROMMAN
extern struct irx_export_table _exp_xfromman;
#endif
extern u8 mcman_sio2outbufs_PS1PDA[0x90];

static u8 mcman_cachebuf[MAX_CACHEENTRY * MCMAN_CLUSTERSIZE];
Expand All @@ -63,8 +68,10 @@ MCDevInfo mcman_devinfos[4][MCMAN_MAXSLOT];

u8 mcman_eccdata[512]; // size for 32 ecc

#ifndef BUILDING_XFROMMAN
int (*mcman_sio2transfer)(int port, int slot, sio2_transfer_data_t *sio2data);
int (*mc_detectcard)(int port, int slot);
#endif

// mcman xor table
// clang-format off
Expand Down Expand Up @@ -146,9 +153,11 @@ int mcman_chrpos(char *str, int chr)
//--------------------------------------------------------------
int _start(int argc, const char **argv)
{
#ifndef BUILDING_XFROMMAN
iop_library_t *libptr;
register int i, sio2man_loaded;
void **export_tab;
#endif

#ifdef SIO_DEBUG
sio_init(38400, 0, 0, 0, 0);
Expand All @@ -157,6 +166,7 @@ int _start(int argc, const char **argv)
DPRINTF("mcman: _start...\n");
#endif

#ifndef BUILDING_XFROMMAN
// Get sio2man lib ptr
sio2man_loaded = 0;
libptr = GetLoadcoreInternalData()->let_next;
Expand Down Expand Up @@ -231,12 +241,19 @@ int _start(int argc, const char **argv)
export_tab[51] = (void *)McFlushCache;
export_tab[52] = (void *)McSetDirEntryState;
}
#endif

#ifdef DEBUG
DPRINTF("mcman: registering exports...\n");
#endif
#ifndef BUILDING_XFROMMAN
if (RegisterLibraryEntries(&_exp_mcman) != 0)
return MODULE_NO_RESIDENT_END;
#endif
#ifdef BUILDING_XFROMMAN
if (RegisterLibraryEntries(&_exp_xfromman) != 0)
return MODULE_NO_RESIDENT_END;
#endif

CpuEnableIntr();

Expand Down Expand Up @@ -490,7 +507,12 @@ int McCloseAll(void) // Export #25 XMCMAN only
//--------------------------------------------------------------
int McDetectCard(int port, int slot) // Export #5
{
#ifndef BUILDING_XFROMMAN
return mc_detectcard(port, slot);
#endif
#ifdef BUILDING_XFROMMAN
return mcman_detectcard(port, slot);
#endif
}

//--------------------------------------------------------------
Expand All @@ -504,6 +526,7 @@ int mcman_detectcard(int port, int slot)
#endif
mcdi = (MCDevInfo *)&mcman_devinfos[port][slot];

#ifndef BUILDING_XFROMMAN
if ((mcdi->cardtype == sceMcTypeNoCard) || (mcdi->cardtype == sceMcTypePS2)) {
r = mcman_probePS2Card2(port, slot);
if (r < -9) {
Expand Down Expand Up @@ -553,6 +576,14 @@ int mcman_detectcard(int port, int slot)
return sceMcResSucceed;
}
}
#endif
#ifdef BUILDING_XFROMMAN
r = mcman_probePS2Card2(port, slot);
if (r >= -9) {
mcdi->cardtype = sceMcTypePS2;
return r;
}
#endif

mcdi->cardtype = 0;
mcdi->cardform = 0;
Expand All @@ -574,6 +605,7 @@ int McDetectCard2(int port, int slot) // Export #21 XMCMAN only

mcdi = (MCDevInfo *)&mcman_devinfos[port][slot];

#ifndef BUILDING_XFROMMAN
if ((mcdi->cardtype == sceMcTypeNoCard) || (mcdi->cardtype == sceMcTypePS2)) {
r = mcman_probePS2Card(port, slot);
if (r < -9) {
Expand Down Expand Up @@ -623,6 +655,14 @@ int McDetectCard2(int port, int slot) // Export #21 XMCMAN only
return sceMcResSucceed;
}
}
#endif
#ifdef BUILDING_XFROMMAN
r = mcman_probePS2Card(port, slot);
if (r >= -9) {
mcdi->cardtype = sceMcTypePS2;
return r;
}
#endif

mcdi->cardtype = 0;
mcdi->cardform = 0;
Expand Down Expand Up @@ -2529,8 +2569,10 @@ int mcman_setPS1devinfos(int port, int slot)
if (r < 0)
return -14;

#ifndef BUILDING_XFROMMAN
if (mcman_sio2outbufs_PS1PDA[1] != 0)
return -15;
#endif

if (mcman_PS1PDApagebuf.byte[0] != 0x4d)
return sceMcResNoFormat;
Expand Down
16 changes: 16 additions & 0 deletions iop/memorycard/mcman/src/mcdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,20 @@ void *mcman_mcops[17] = {

// driver descriptor
static iop_device_t mcman_mcdev = {
#ifndef BUILDING_XFROMMAN
"mc",
#endif
#ifdef BUILDING_XFROMMAN
"xfrom",
#endif
IOP_DT_FS,
1,
#ifndef BUILDING_XFROMMAN
"Memory Card",
#endif
#ifdef BUILDING_XFROMMAN
"External flash rom",
#endif
(struct _iop_device_ops *)&mcman_mcops
};

Expand Down Expand Up @@ -158,8 +168,14 @@ int mcman_modloadcb(char *filename, int *port, int *slot)
//--------------------------------------------------------------
void mcman_unit2card(u32 unit)
{
#ifndef BUILDING_XFROMMAN
mcman_mc_port = unit & 1;
mcman_mc_slot = (unit >> 1) & (MCMAN_MAXSLOT - 1);
#endif
#ifdef BUILDING_XFROMMAN
mcman_mc_port = 0;
mcman_mc_slot = 0;
#endif

// original mcman/xmcman code below is silly and I doubt it
// can support more than 2 units anyway...
Expand Down
12 changes: 12 additions & 0 deletions iop/memorycard/mcman/src/mcman-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <stdio.h>
#include <errno.h>
#include <io_common.h>
#ifdef BUILDING_XFROMMAN
#include <fls.h>
#endif
#include "sio2man_imports.h"

#ifdef SIO_DEBUG
Expand All @@ -34,7 +37,12 @@
#define DPRINTF(args...) printf(args)
#endif

#ifndef BUILDING_XFROMMAN
#define MODNAME "mcman_cex"
#endif
#ifdef BUILDING_XFROMMAN
#define MODNAME "xfromman"
#endif
#define MODVER 0x20b

typedef struct _MCCacheDir {
Expand Down Expand Up @@ -89,8 +97,10 @@ typedef struct { // size = 48
#define MAX_FDHANDLES 3

// internal functions prototypes
#ifndef BUILDING_XFROMMAN
int mcsio2_transfer(int port, int slot, sio2_transfer_data_t *sio2data);
int mcsio2_transfer2(int port, int slot, sio2_transfer_data_t *sio2data);
#endif
void long_multiply(u32 v1, u32 v2, u32 *HI, u32 *LO);
int mcman_chrpos(char *str, int chr);
void mcman_wmemset(void *buf, int size, int value);
Expand All @@ -104,7 +114,9 @@ int mcman_dread(int fd, io_dirent_t *dirent);
int mcman_getstat(int port, int slot, char *filename, io_stat_t *stat);
int mcman_getmcrtime(sceMcStDateTime *time);
void mcman_initPS2com(void);
#ifndef BUILDING_XFROMMAN
void sio2packet_add(int port, int slot, int cmd, u8 *buf);
#endif
int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf);
int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf);
int mcman_cardchanged(int port, int slot);
Expand Down
Loading

0 comments on commit 2de0ddf

Please sign in to comment.