Skip to content

Commit

Permalink
ninjapassx9: fix -Wdeprecated-declarations warning
Browse files Browse the repository at this point in the history
  • Loading branch information
lifehackerhansol committed Nov 12, 2024
1 parent 528a8f6 commit d061361
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 105 deletions.
66 changes: 33 additions & 33 deletions source/ninjapassx9/source/io_sd_card.dldi.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const unsigned int READY_TIMEOUT = 1000;
const unsigned int blockSize = 512; // bytes

// General-purpose buffer
static uint8 scratch[0x1000];
static u8 scratch[0x1000];


//extern void DumpMemory(unsigned char* data, int bytes);
Expand All @@ -47,16 +47,16 @@ static uint8 scratch[0x1000];
#define min2(a, b) ((a) < (b) ? (a) : (b))


void SDSendCommand(enum SDCommand sdCmd, uint32 arg, uint8* response)
void SDSendCommand(enum SDCommand sdCmd, u32 arg, u8* response)
{
// Each byte in var represents one bit -- bit 0 of var[x]. Thus, each group
// of eight bytes in var is "effectively" one byte from the SD card
//

static uint8 var[0x200];
static u8 var[0x200];
// Send the SD command (0x60)
// 0x80 words = 0x200 bytes
X9CardIO(0x60, sdCmd, arg, 0xA1586000, (uint32*)var, 0x80);
X9CardIO(0x60, sdCmd, arg, 0xA1586000, (u32*)var, 0x80);

// Skips the first 7 effective bytes (k = 0x30)
// 0x30 is the size in bits of an SD-mode response
Expand Down Expand Up @@ -96,8 +96,8 @@ void SDSendCommand(enum SDCommand sdCmd, uint32 arg, uint8* response)

if(min2(start, end) == start)
{
const uint8* end_ptr = &(var[end]);
uint8* ptr = &(var[start]);
const u8* end_ptr = &(var[end]);
u8* ptr = &(var[start]);

int bit = 7;
int j = 0;
Expand All @@ -119,7 +119,7 @@ void SDSendCommand(enum SDCommand sdCmd, uint32 arg, uint8* response)
}

//coto: added proper retry-ability @ bool _X9SD_writeSectors
bool SDWriteSingleBlock(uint32 address, const void* buffer)
bool SDWriteSingleBlock(u32 address, const void* buffer)
{
// Preemptively send the data before issuing the command so
// that the X9 can compute the CRC
Expand All @@ -131,7 +131,7 @@ bool SDWriteSingleBlock(uint32 address, const void* buffer)

// Uses 512 bytes of scratch
// Overwrites scratch
X9CardIO(0x63, 0, 0, 0xB15863FA, (uint32*)scratch, 0x80);
X9CardIO(0x63, 0, 0, 0xB15863FA, (u32*)scratch, 0x80);

int idx = 0;

Expand All @@ -140,7 +140,7 @@ bool SDWriteSingleBlock(uint32 address, const void* buffer)
{
if(idx == 0){
// Repeat SD command to absorb current data
X9CardIO(0x62, 0, 0, 0xA1586000, (uint32*)scratch, 0x80);
X9CardIO(0x62, 0, 0, 0xA1586000, (u32*)scratch, 0x80);
}

if((idx < 0x200) && !(scratch[idx] & 0x10)){
Expand All @@ -164,7 +164,7 @@ bool SDWriteSingleBlock(uint32 address, const void* buffer)
{
if(idx == 0){
// Repeat SD command?
X9CardIO(0x62, 0, 0, 0xA1586000, (uint32*)scratch, 0x80);
X9CardIO(0x62, 0, 0, 0xA1586000, (u32*)scratch, 0x80);
}

if((idx < 0x200) && (scratch[idx] & 0x10)){
Expand All @@ -186,15 +186,15 @@ bool SDWriteSingleBlock(uint32 address, const void* buffer)
}


bool SDReadSingleBlock(uint32 address, void* destination)
bool SDReadSingleBlock(u32 address, void* destination)
{

// scratch is split in two halves

// 0x60: send an SD command
// 0xA3586000 means we don't expect the standard response? (but data) -- serial vs 4-bit? length?
// 0x200 words = 0x800 bytes
X9CardIO(0x60, (uint8)ReadSingleBlock, address, 0xA1586000, (uint32*)scratch, 0x80);
X9CardIO(0x60, (u8)ReadSingleBlock, address, 0xA1586000, (u32*)scratch, 0x80);

// Search for the start of data
unsigned int k = 0;
Expand All @@ -204,7 +204,7 @@ bool SDReadSingleBlock(uint32 address, void* destination)
while(k == 0x200)
{
// Continue reading data from SD card
X9CardIO(0x62, 0, address, 0xA1586000, (uint32*)scratch, 0x80);
X9CardIO(0x62, 0, address, 0xA1586000, (u32*)scratch, 0x80);

// Keep searching for the response-data
for(k = 0; k < 0x200 && (scratch[k] & 0xf0); ++k)
Expand All @@ -213,14 +213,14 @@ bool SDReadSingleBlock(uint32 address, void* destination)

// // Read another chunk because the full 512 bytes haven't yet been received
// if(0x800 - k < 0x400) // k > 0x400
// X9CardIO(0x62, 0, address, 0xA3586000, (uint32*)&scratch[0x800], 0x200);
X9CardIO(0x62, 0, address, 0xA2586000, (uint32*)&scratch[0x200], 0x100);
// X9CardIO(0x62, 0, address, 0xA3586000, (u32*)&scratch[0x800], 0x200);
X9CardIO(0x62, 0, address, 0xA2586000, (u32*)&scratch[0x200], 0x100);

unsigned int readIdx = k + 1; // just after the 0xf0
unsigned int end = readIdx + 0x400; // read 0x400 half-bytes, or 0x200 bytes

// IO is done with half-bytes: reconstruct full bytes
uint8* dest = (uint8*)destination;
u8* dest = (u8*)destination;
for(; readIdx < end; readIdx+= 2)
*dest++ = (scratch[readIdx] & 0xF0) | (scratch[readIdx+1] >> 4);

Expand All @@ -229,13 +229,13 @@ bool SDReadSingleBlock(uint32 address, void* destination)
// NOTE: SDSendCommand uses 0xA1586000 and gets a response
// the data-transfer commands use 0xA3586000 and expect no response...
// Get the response from the SD-card (always after the transfer)
X9CardIO(0x62, 0, address, 0xA1586000, (uint32*)scratch, 0x80);
X9CardIO(0x62, 0, address, 0xA1586000, (u32*)scratch, 0x80);

return true;
}

//
//bool SDReadMultipleBlocks(uint32 address, unsigned int count, void* destination)
//bool SDReadMultipleBlocks(u32 address, unsigned int count, void* destination)
//{
// if(count == 1)
// return SDReadSingleBlock(address, destination);
Expand All @@ -244,13 +244,13 @@ bool SDReadSingleBlock(uint32 address, void* destination)
//
// const unsigned int readChunkSize = 0x200;
//
// uint8 buffer[0x1000];// split in two halves
// uint8* dest = (uint8*)destination;
// u8 buffer[0x1000];// split in two halves
// u8* dest = (u8*)destination;
//
// // 0x60: send an SD command
// // 0xA3586000 means we don't expect the standard response? (but data) -- serial vs 4-bit? length?
// // 0x200 words = 0x800 bytes
// X9CardIO(0x60, (uint8)ReadMultipleBlocks, address, 0xA1586000, (uint32*)buffer, readChunkSize/sizeof(uint32));
// X9CardIO(0x60, (u8)ReadMultipleBlocks, address, 0xA1586000, (u32*)buffer, readChunkSize/sizeof(u32));
//
// // Search for the start of data
// unsigned int readIdx = 0;
Expand All @@ -261,7 +261,7 @@ bool SDReadSingleBlock(uint32 address, void* destination)
// while(readIdx == readChunkSize)
// {
// // Continue reading data from SD card
// X9CardIO(0x62, 0, address, 0xA1586000, (uint32*)buffer, readChunkSize/sizeof(uint32));
// X9CardIO(0x62, 0, address, 0xA1586000, (u32*)buffer, readChunkSize/sizeof(u32));
//
// // Keep searching for the response-data
// for(readIdx = 0; readIdx < readChunkSize && (buffer[readIdx] & 0xf0); ++readIdx)
Expand All @@ -281,28 +281,28 @@ bool SDReadSingleBlock(uint32 address, void* destination)
// // Read the remaining blocks before the last
// while(bytesRemaining > blockSize)
// {
// X9CardIO(0x62, 0, address, 0xA1586000, (uint32*)buffer, blockSize*2/sizeof(uint32));
// X9CardIO(0x62, 0, address, 0xA1586000, (u32*)buffer, blockSize*2/sizeof(u32));
// for(unsigned int idx = 0; idx < 2*blockSize; idx+= 2)
// *dest++ = (buffer[idx] & 0xF0) | (buffer[idx+1] >> 4);
//
// bytesRemaining-= blockSize;
// }
//
// // Read the last block
// X9CardIO(0x62, 0, address, 0xA2586000, (uint32*)buffer, bytesRemaining*2/sizeof(uint32)+1);
// X9CardIO(0x62, 0, address, 0xA2586000, (u32*)buffer, bytesRemaining*2/sizeof(u32)+1);
// for(unsigned int idx = 0; idx < 2*bytesRemaining; idx+= 2)
// *dest++ = (buffer[idx] & 0xF0) | (buffer[idx+1] >> 4);
// }
// else
// {
// for(; readIdx < readChunkSize; readIdx+= 2)
// *dest++ = (buffer[readIdx] & 0xF0) | (buffer[readIdx+1] >> 4);
// uint8 remainder = buffer[readChunkSize-1] & 0xF0;
// u8 remainder = buffer[readChunkSize-1] & 0xF0;
//
// // Read the remaining blocks before the last
// while(bytesRemaining > blockSize)
// {
// X9CardIO(0x62, 0, address, 0xA1586000, (uint32*)buffer, blockSize*2/sizeof(uint32));
// X9CardIO(0x62, 0, address, 0xA1586000, (u32*)buffer, blockSize*2/sizeof(u32));
//
// *dest++ = remainder | (buffer[0] >> 4);
//
Expand All @@ -314,7 +314,7 @@ bool SDReadSingleBlock(uint32 address, void* destination)
// }
//
// // Read the last block
// X9CardIO(0x62, 0, address, 0xA2586000, (uint32*)buffer, bytesRemaining*2/sizeof(uint32)+1);
// X9CardIO(0x62, 0, address, 0xA2586000, (u32*)buffer, bytesRemaining*2/sizeof(u32)+1);
// *dest++ = remainder | (buffer[0] >> 4);
// for(unsigned int idx = 1; idx < 2*bytesRemaining; idx+= 2)
// *dest++ = (buffer[idx] & 0xF0) | (buffer[idx+1] >> 4);
Expand All @@ -323,19 +323,19 @@ bool SDReadSingleBlock(uint32 address, void* destination)
// // Stop the transfer
// SDSendCommand(AbortReadWrite, 0, buffer);
// // Get the response from the SD-card (always after the transfer)
//// X9CardIO(0x62, 0, address, 0xA1586000, (uint32*)buffer, 0x80);
//// X9CardIO(0x62, 0, address, 0xA1586000, (u32*)buffer, 0x80);
//
// return true;
//}
//
//
//bool SDInitialize(uint32* relativeCardAddress)
//bool SDInitialize(u32* relativeCardAddress)
//{
// if(!relativeCardAddress)
// return false;
//
// unsigned int attempts;
// uint8 response[0x20];
// u8 response[0x20];
//
// DO_DEBUG(iprintf("CMD0: "));
// // CMD0 initialize (reset)
Expand Down Expand Up @@ -419,17 +419,17 @@ bool SDReadSingleBlock(uint32 address, void* destination)
//}


inline void SDSendAppCommand(enum SDAppCommand sdAppCmd, uint32 arg, uint8* response)
inline void SDSendAppCommand(enum SDAppCommand sdAppCmd, u32 arg, u8* response)
{
SDSendCommand((enum SDCommand)sdAppCmd,arg,response);
}

inline void SDBroadcastCommand(enum SDCommand sdCmd, uint32 arg, uint8* response)
inline void SDBroadcastCommand(enum SDCommand sdCmd, u32 arg, u8* response)
{
SDSendCommand((enum SDCommand)(sdCmd|Broadcast),arg,response);
}

inline void SDBroadcastAppCommand(enum SDAppCommand sdAppCmd, uint32 arg, uint8* response)
inline void SDBroadcastAppCommand(enum SDAppCommand sdAppCmd, u32 arg, u8* response)
{
SDSendCommand((enum SDCommand)(sdAppCmd|Broadcast),arg,response);
}
90 changes: 45 additions & 45 deletions source/ninjapassx9/source/io_sd_card.dldi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,41 @@ freely, subject to the following restrictions:

typedef struct
{
const uint8 csdStructure : 2;
const uint8 reserved1 : 6;
const uint8 dataReadAccessTime1 : 8; // TAAC
const uint8 dataReadAccessTime2 : 8; // NSAC
const uint8 maxDataTransferRate : 8;
const uint16 cardCommandClasses : 12;
const uint8 maxReadDataBlockLength : 4;
const uint8 allowPartialRead : 1;
const uint8 allowWriteMisalign : 1;
const uint8 allowReadMisalign : 1;
const uint8 dsrImplemented : 1;
const uint8 reserved2 : 2;
const uint16 deviceSize : 12;
const uint8 maxReadCurrentMin : 3;
const uint8 maxReadCurrentMax : 3;
const uint8 maxWriteCurrentMin : 3;
const uint8 maxWriteCurrentMax : 3;
const uint8 sizeMultiplier : 3;
const uint8 allowEraseSingleBlock : 1;
const uint8 eraseSectorSize : 7;
const uint8 writeProtectGroupSize : 7;
const uint8 writeProtectGroupEnabled : 1;
const uint8 reserved3 : 2;
const uint8 writeSpeedFactor : 3;
const uint8 maxWriteLength : 4;
const uint8 allowPartialWrite : 1;
const uint8 reserved4 : 5;
const uint8 fileFormatGroup : 1;
const uint8 copyFlag : 1;
const uint8 permanentWriteProtection : 1;
uint8 temporaryWriteProtection : 1;
const uint8 fileFormat : 2;
uint8 reserved5 : 2;
uint8 crc7 : 7; // Used to ensure this header was transferred properly
const uint8 direction : 1; // 1 == from card to host
const u8 csdStructure : 2;
const u8 reserved1 : 6;
const u8 dataReadAccessTime1 : 8; // TAAC
const u8 dataReadAccessTime2 : 8; // NSAC
const u8 maxDataTransferRate : 8;
const u16 cardCommandClasses : 12;
const u8 maxReadDataBlockLength : 4;
const u8 allowPartialRead : 1;
const u8 allowWriteMisalign : 1;
const u8 allowReadMisalign : 1;
const u8 dsrImplemented : 1;
const u8 reserved2 : 2;
const u16 deviceSize : 12;
const u8 maxReadCurrentMin : 3;
const u8 maxReadCurrentMax : 3;
const u8 maxWriteCurrentMin : 3;
const u8 maxWriteCurrentMax : 3;
const u8 sizeMultiplier : 3;
const u8 allowEraseSingleBlock : 1;
const u8 eraseSectorSize : 7;
const u8 writeProtectGroupSize : 7;
const u8 writeProtectGroupEnabled : 1;
const u8 reserved3 : 2;
const u8 writeSpeedFactor : 3;
const u8 maxWriteLength : 4;
const u8 allowPartialWrite : 1;
const u8 reserved4 : 5;
const u8 fileFormatGroup : 1;
const u8 copyFlag : 1;
const u8 permanentWriteProtection : 1;
u8 temporaryWriteProtection : 1;
const u8 fileFormat : 2;
u8 reserved5 : 2;
u8 crc7 : 7; // Used to ensure this header was transferred properly
const u8 direction : 1; // 1 == from card to host
} CSDRegister;

typedef struct
Expand Down Expand Up @@ -103,8 +103,8 @@ typedef struct
bool start : 1;
bool direction : 1;
int commandIndex : 6;
uint16 newRCA : 16;
uint16 cardStatusError : 16;
u16 newRCA : 16;
u16 cardStatusError : 16;
int crc7 : 7;
bool end : 1;
} SDResponseR6;
Expand Down Expand Up @@ -155,15 +155,15 @@ enum SDState
extern "C"{
#endif

extern void SDSendCommand(enum SDCommand sdCmd, uint32 arg, uint8* response);
extern bool SDInitialize(uint32* relativeCardAddress);
extern bool SDWriteSingleBlock(uint32 address, const void* buffer);
extern bool SDReadSingleBlock(uint32 address, void* destination);
extern bool SDReadMultipleBlocks(uint32 address, unsigned int count, void* destination);
extern void SDSendCommand(enum SDCommand sdCmd, u32 arg, u8* response);
extern bool SDInitialize(u32* relativeCardAddress);
extern bool SDWriteSingleBlock(u32 address, const void* buffer);
extern bool SDReadSingleBlock(u32 address, void* destination);
extern bool SDReadMultipleBlocks(u32 address, unsigned int count, void* destination);

extern void SDSendAppCommand(enum SDAppCommand sdAppCmd, uint32 arg, uint8* response);
extern void SDBroadcastCommand(enum SDCommand sdCmd, uint32 arg, uint8* response);
extern void SDBroadcastAppCommand(enum SDAppCommand sdAppCmd, uint32 arg, uint8* response);
extern void SDSendAppCommand(enum SDAppCommand sdAppCmd, u32 arg, u8* response);
extern void SDBroadcastCommand(enum SDCommand sdCmd, u32 arg, u8* response);
extern void SDBroadcastAppCommand(enum SDAppCommand sdAppCmd, u32 arg, u8* response);

#ifdef __cplusplus
}
Expand Down
10 changes: 5 additions & 5 deletions source/ninjapassx9/source/io_x9_card.dldi.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ freely, subject to the following restrictions:
NOTE: buffer must be aligned to a 4 byte boundary
*/
void X9CardPolledWrite(uint32 flags, const uint32* buffer, const uint8* command)
void X9CardPolledWrite(u32 flags, const u32* buffer, const u8* command)
{
cardWriteCommand(command);
REG_ROMCTRL = flags;
Expand All @@ -60,7 +60,7 @@ void X9CardPolledWrite(uint32 flags, const uint32* buffer, const uint8* command)
while(REG_ROMCTRL & CARD_BUSY);
}

void X9CardWriteData(uint8 arg1, uint32 arg2, const void* buffer)
void X9CardWriteData(u8 arg1, u32 arg2, const void* buffer)
{
x9Command[7] = 0x64;
x9Command[6] = (arg2>>24)&0xFF;
Expand All @@ -72,10 +72,10 @@ void X9CardWriteData(uint8 arg1, uint32 arg2, const void* buffer)
x9Command[0] = arg1;

if(((int)(buffer) % 4) == 0)
X9CardPolledWrite(0xC1586000, (uint32*)buffer, x9Command);
X9CardPolledWrite(0xC1586000, (u32*)buffer, x9Command);
else
{
tonccpy((uint8*)x9Buffer, (const uint8*)buffer, 512);
X9CardPolledWrite(0xC1586000, (uint32*)x9Buffer, x9Command);
tonccpy((u8*)x9Buffer, (const u8*)buffer, 512);
X9CardPolledWrite(0xC1586000, (u32*)x9Buffer, x9Command);
}
}
Loading

0 comments on commit d061361

Please sign in to comment.