Skip to content

Commit 74ba264

Browse files
committed
Clean up MMC constants
1 parent 77e7d0c commit 74ba264

File tree

4 files changed

+102
-64
lines changed

4 files changed

+102
-64
lines changed

src/DSi_NWifi.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,17 +619,17 @@ void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val)
619619
}
620620

621621

622-
void DSi_NWifi::SendCMD(u8 cmd, u32 param)
622+
void DSi_NWifi::SendCMD(MMCCommand cmd, u32 param)
623623
{
624624
switch (cmd)
625625
{
626-
case 12:
626+
case MMCCommand::StopTransmission:
627627
// stop command
628628
// CHECKME: does the SDIO controller actually send those??
629629
// DSi firmware sets it to send them
630630
return;
631631

632-
case 52: // IO_RW_DIRECT
632+
case MMCCommand::IORWDirect:
633633
{
634634
u32 func = (param >> 28) & 0x7;
635635
u32 addr = (param >> 9) & 0x1FFFF;
@@ -654,7 +654,7 @@ void DSi_NWifi::SendCMD(u8 cmd, u32 param)
654654
}
655655
return;
656656

657-
case 53: // IO_RW_EXTENDED
657+
case MMCCommand::IORWExtended:
658658
{
659659
u32 addr = (param >> 9) & 0x1FFFF;
660660

@@ -691,7 +691,7 @@ void DSi_NWifi::SendCMD(u8 cmd, u32 param)
691691
Log(LogLevel::Warn, "NWIFI: unknown CMD %d %08X\n", cmd, param);
692692
}
693693

694-
void DSi_NWifi::SendACMD(u8 cmd, u32 param)
694+
void DSi_NWifi::SendACMD(MMCAppCommand cmd, u32 param)
695695
{
696696
Log(LogLevel::Warn, "NWIFI: unknown ACMD %d %08X\n", cmd, param);
697697
}
@@ -1629,4 +1629,4 @@ void DSi_NWifi::MSTimer(u32 param)
16291629
DSi.ScheduleEvent(Event_DSi_NWifi, true, 33611, 0, 0);
16301630
}
16311631

1632-
}
1632+
}

src/DSi_NWifi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class DSi_NWifi : public DSi_SDDevice
3535

3636
void DoSavestate(Savestate* file);
3737

38-
void SendCMD(u8 cmd, u32 param);
39-
void SendACMD(u8 cmd, u32 param);
38+
void SendCMD(MMCCommand cmd, u32 param);
39+
void SendACMD(MMCAppCommand cmd, u32 param);
4040

4141
void ContinueTransfer();
4242

src/DSi_SD.cpp

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void DSi_SDHost::FinishTX(u32 param)
364364
{
365365
if (StopAction & (1<<8))
366366
{
367-
if (dev) dev->SendCMD(12, 0);
367+
if (dev) dev->SendCMD(MMCCommand::StopTransmission, 0);
368368
}
369369

370370
// CHECKME: presumably IRQ2 should not trigger here, but rather
@@ -453,7 +453,7 @@ void DSi_SDHost::CheckRX()
453453
{
454454
if (StopAction & (1<<8))
455455
{
456-
if (dev) dev->SendCMD(12, 0);
456+
if (dev) dev->SendCMD(MMCCommand::StopTransmission, 0);
457457
}
458458

459459
// CHECKME: presumably IRQ2 should not trigger here, but rather
@@ -625,8 +625,8 @@ void DSi_SDHost::Write(u32 addr, u16 val)
625625
// except DSi boot2 manually sends an APP_CMD prefix AND sets the next command to be ACMD
626626
switch ((Command >> 6) & 0x3)
627627
{
628-
case 0: dev->SendCMD(cmd, Param); break;
629-
case 1: /*dev->SendCMD(55, 0);*/ dev->SendCMD(cmd, Param); break;
628+
case 0: dev->SendCMD((MMCCommand) cmd, Param); break;
629+
case 1: /*dev->SendCMD(55, 0);*/ dev->SendCMD((MMCCommand) cmd, Param); break;
630630
default:
631631
Log(LogLevel::Warn, "%s: unknown command type %d, %02X %08X\n", SD_DESC, (Command>>6)&0x3, cmd, Param);
632632
break;
@@ -665,7 +665,7 @@ void DSi_SDHost::Write(u32 addr, u16 val)
665665
case 0x024: SDClock = val & 0x03FF; return;
666666
case 0x026:
667667
BlockLen16 = val & 0x03FF;
668-
if (BlockLen16 > 0x200) BlockLen16 = 0x200;
668+
if (BlockLen16 > MMC_MAXIMUM_BLOCK_SIZE) BlockLen16 = MMC_MAXIMUM_BLOCK_SIZE;
669669
return;
670670
case 0x028: SDOption = val & 0xC1FF; return;
671671

@@ -841,9 +841,9 @@ void DSi_MMCStorage::Reset()
841841

842842
memset(SSR, 0, 64);
843843

844-
BlockSize = 512;
844+
BlockSize = MMC_DEFAULT_BLOCK_SIZE;
845845
RWAddress = 0;
846-
RWCommand = 0;
846+
RWCommand = MMCCommand::Reset;
847847
}
848848

849849
void DSi_MMCStorage::DoSavestate(Savestate* file)
@@ -861,26 +861,27 @@ void DSi_MMCStorage::DoSavestate(Savestate* file)
861861

862862
file->Var32(&BlockSize);
863863
file->Var64(&RWAddress);
864-
file->Var32(&RWCommand);
864+
865+
file->Var32((u32*) &RWCommand);
865866

866867
// TODO: what about the file contents?
867868
}
868869

869-
void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
870+
void DSi_MMCStorage::SendCMD(MMCCommand cmd, u32 param)
870871
{
871872
if (CSR & (1<<5))
872873
{
873874
CSR &= ~(1<<5);
874-
return SendACMD(cmd, param);
875+
return SendACMD((MMCAppCommand) cmd, param);
875876
}
876877

877878
switch (cmd)
878879
{
879-
case 0: // reset/etc
880+
case MMCCommand::Reset:
880881
Host->SendResponse(CSR, true);
881882
return;
882883

883-
case 1: // SEND_OP_COND
884+
case MMCCommand::GetOCR:
884885
// CHECKME!!
885886
// also TODO: it's different for the SD card
886887
if (std::holds_alternative<DSi_NAND::NANDImage>(Storage))
@@ -897,16 +898,16 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
897898
}
898899
return;
899900

900-
case 2:
901-
case 10: // get CID
901+
case MMCCommand::AllGetCID:
902+
case MMCCommand::GetCID:
902903
Host->SendResponse(*(u32*)&CID[12], false);
903904
Host->SendResponse(*(u32*)&CID[8], false);
904905
Host->SendResponse(*(u32*)&CID[4], false);
905906
Host->SendResponse(*(u32*)&CID[0], true);
906-
if (cmd == 2) SetState(0x02);
907+
if (cmd == MMCCommand::AllGetCID) SetState(0x02);
907908
return;
908909

909-
case 3: // get/set RCA
910+
case MMCCommand::GetRCA:
910911
if (holds_alternative<DSi_NAND::NANDImage>(Storage))
911912
{
912913
RCA = param >> 16;
@@ -920,81 +921,81 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
920921
}
921922
return;
922923

923-
case 6: // MMC: 'SWITCH'
924+
case MMCCommand::Switch:
924925
// TODO!
925926
Host->SendResponse(CSR, true);
926927
return;
927928

928-
case 7: // select card (by RCA)
929+
case MMCCommand::Select:
929930
Host->SendResponse(CSR, true);
930931
return;
931932

932-
case 8: // set voltage
933+
case MMCCommand::SetVoltage:
933934
Host->SendResponse(param, true);
934935
return;
935936

936-
case 9: // get CSD
937+
case MMCCommand::GetCSD:
937938
Host->SendResponse(*(u32*)&CSD[12], false);
938939
Host->SendResponse(*(u32*)&CSD[8], false);
939940
Host->SendResponse(*(u32*)&CSD[4], false);
940941
Host->SendResponse(*(u32*)&CSD[0], true);
941942
return;
942943

943-
case 12: // stop operation
944+
case MMCCommand::StopTransmission:
944945
SetState(0x04);
945946
if (auto* nand = get_if<DSi_NAND::NANDImage>(&Storage))
946947
FileFlush(nand->GetFile());
947-
RWCommand = 0;
948+
RWCommand = MMCCommand::Reset;
948949
Host->SendResponse(CSR, true);
949950
return;
950951

951-
case 13: // get status
952+
case MMCCommand::GetCSR:
952953
Host->SendResponse(CSR, true);
953954
return;
954955

955-
case 16: // set block size
956+
case MMCCommand::SetBlockLength:
956957
BlockSize = param;
957-
if (BlockSize > 0x200)
958+
if (BlockSize > MMC_MAXIMUM_BLOCK_SIZE)
958959
{
959960
// TODO! raise error
960961
Log(LogLevel::Warn, "!! SD/MMC: BAD BLOCK LEN %d\n", BlockSize);
961-
BlockSize = 0x200;
962+
BlockSize = MMC_DEFAULT_BLOCK_SIZE;
962963
}
963964
SetState(0x04); // CHECKME
964965
Host->SendResponse(CSR, true);
965966
return;
966967

967-
case 17: // read single block
968-
case 18: // read multiple blocks
968+
case MMCCommand::ReadSingleBlock:
969+
case MMCCommand::ReadMultipleBlocks:
969970
//printf("READ_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize);
970971
RWAddress = param;
971972
if (OCR & (1<<30))
972973
{
973974
RWAddress <<= 9;
974-
BlockSize = 512;
975+
BlockSize = MMC_DEFAULT_BLOCK_SIZE;
975976
}
976-
RWCommand = 18;
977+
RWCommand = cmd;
977978
Host->SendResponse(CSR, true);
978979
RWAddress += ReadBlock(RWAddress);
979980
SetState(0x05);
980981
return;
981982

982-
case 24: // write single block
983-
case 25: // write multiple blocks
983+
case MMCCommand::WriteSingleBlock:
984+
case MMCCommand::WriteMultipleBlocks:
984985
//printf("WRITE_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize);
985986
RWAddress = param;
986987
if (OCR & (1<<30))
987988
{
988989
RWAddress <<= 9;
989-
BlockSize = 512;
990+
BlockSize = MMC_DEFAULT_BLOCK_SIZE;
990991
}
991-
RWCommand = 25;
992+
RWCommand = cmd;
992993
Host->SendResponse(CSR, true);
993994
RWAddress += WriteBlock(RWAddress);
994995
SetState(0x04);
995996
return;
996997

997-
case 55: // appcmd prefix
998+
case MMCCommand::AppCommand:
998999
CSR |= (1<<5);
9991000
Host->SendResponse(CSR, true);
10001001
return;
@@ -1003,21 +1004,21 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
10031004
Log(LogLevel::Warn, "MMC: unknown CMD %d %08X\n", cmd, param);
10041005
}
10051006

1006-
void DSi_MMCStorage::SendACMD(u8 cmd, u32 param)
1007+
void DSi_MMCStorage::SendACMD(MMCAppCommand cmd, u32 param)
10071008
{
10081009
switch (cmd)
10091010
{
1010-
case 6: // set bus width (TODO?)
1011+
case MMCAppCommand::SetBusWidth:
10111012
//printf("SET BUS WIDTH %08X\n", param);
10121013
Host->SendResponse(CSR, true);
10131014
return;
10141015

1015-
case 13: // get SSR
1016+
case MMCAppCommand::GetSSR:
10161017
Host->SendResponse(CSR, true);
10171018
Host->DataRX(SSR, 64);
10181019
return;
10191020

1020-
case 41: // set operating conditions
1021+
case MMCAppCommand::SetOCR:
10211022
// CHECKME:
10221023
// DSi boot2 sets this to 0x40100000 (hardcoded)
10231024
// then has two codepaths depending on whether bit30 did get set
@@ -1029,11 +1030,11 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param)
10291030
SetState(0x01);
10301031
return;
10311032

1032-
case 42: // ???
1033+
case MMCAppCommand::SetCardDetect: // ???
10331034
Host->SendResponse(CSR, true);
10341035
return;
10351036

1036-
case 51: // get SCR
1037+
case MMCAppCommand::GetSCR:
10371038
Host->SendResponse(CSR, true);
10381039
Host->DataRX(SCR, 8);
10391040
return;
@@ -1044,21 +1045,21 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param)
10441045

10451046
void DSi_MMCStorage::ContinueTransfer()
10461047
{
1047-
if (RWCommand == 0) return;
1048+
if (RWCommand == MMCCommand::Reset) return;
10481049

10491050
u32 len = 0;
10501051

10511052
switch (RWCommand)
10521053
{
1053-
case 17: // single block read
1054-
RWCommand = 0;
1055-
case 18: // multiple block read
1054+
case MMCCommand::ReadSingleBlock:
1055+
RWCommand = MMCCommand::Reset;
1056+
case MMCCommand::ReadMultipleBlocks:
10561057
len = ReadBlock(RWAddress);
10571058
break;
10581059

1059-
case 24: // single block write
1060-
RWCommand = 0;
1061-
case 25: // multiple block write
1060+
case MMCCommand::WriteSingleBlock:
1061+
RWCommand = MMCCommand::Reset;
1062+
case MMCCommand::WriteMultipleBlocks:
10621063
len = WriteBlock(RWAddress);
10631064
break;
10641065
}
@@ -1071,7 +1072,7 @@ u32 DSi_MMCStorage::ReadBlock(u64 addr)
10711072
u32 len = BlockSize;
10721073
len = Host->GetTransferrableLen(len);
10731074

1074-
u8 data[0x200];
1075+
u8 data[MMC_MAXIMUM_BLOCK_SIZE];
10751076
if (auto* sd = std::get_if<FATStorage>(&Storage))
10761077
{
10771078
sd->ReadSectors((u32)(addr >> 9), 1, data);
@@ -1090,8 +1091,8 @@ u32 DSi_MMCStorage::WriteBlock(u64 addr)
10901091
u32 len = BlockSize;
10911092
len = Host->GetTransferrableLen(len);
10921093

1093-
u8 data[0x200];
1094-
if (len < 0x200)
1094+
u8 data[MMC_MAXIMUM_BLOCK_SIZE];
1095+
if (len < MMC_DEFAULT_BLOCK_SIZE)
10951096
{
10961097
if (auto* sd = get_if<FATStorage>(&Storage))
10971098
{

0 commit comments

Comments
 (0)