Skip to content

platform: clean up Acekard platforms and implement DMA#163

Merged
Gericom merged 13 commits into
LNH-team:developfrom
lifehackerhansol:rpg-dma
Jun 13, 2026
Merged

platform: clean up Acekard platforms and implement DMA#163
Gericom merged 13 commits into
LNH-team:developfrom
lifehackerhansol:rpg-dma

Conversation

@lifehackerhansol

@lifehackerhansol lifehackerhansol commented Apr 20, 2026

Copy link
Copy Markdown
Contributor
  • Added a "IoRpgPlatformSpecifics" struct which defines some platform-specific magic numbers to use in patch codes
  • Merged all patch codes into acekard-common directory, leveraging IoRpgPlatformSpecifics to inject magic numbers as needed
  • Optimized a few routines to reduce patch code space
  • Implemented DMA support

@Gericom

Gericom commented May 3, 2026

Copy link
Copy Markdown
Contributor

The dma patch code you added looks very similar. Can we avoid duplication?

@lifehackerhansol

Copy link
Copy Markdown
Contributor Author

Not really, because of the different parameters each platform needs:

  • R4iDSN commands start with 0xAB, while others start with 0xD5
  • AKRPG card state command returns its "state" in the lower nibble, while the rest returns it in the upper nibble

We could programmatically patch those instructions I suppose, but I haven't tried it.

@Gericom

Gericom commented May 3, 2026

Copy link
Copy Markdown
Contributor

Not really, because of the different parameters each platform needs:

* R4iDSN commands start with 0xAB, while others start with 0xD5

* AKRPG card state command returns its "state" in the lower nibble, while the rest returns it in the upper nibble

We could programmatically patch those instructions I suppose, but I haven't tried it.

I guess another option could be to create an .inc file with the code with some #ifdefs. And then in the actual .s files, set the corresponding ifdef and #include the .inc file.

@lifehackerhansol lifehackerhansol changed the title platform: add DMA support for the RPG family of flashcarts platform: clean up Acekard platforms and implement DMA May 10, 2026
@lifehackerhansol

Copy link
Copy Markdown
Contributor Author

I guess another option could be to create an .inc file with the code with some #ifdefs. And then in the actual .s files, set the corresponding ifdef and #include the .inc file.

I went with a slightly different solution inspired by compactflash-common, and unified all patches under acekard-common.

@lifehackerhansol lifehackerhansol force-pushed the rpg-dma branch 2 times, most recently from b9973f9 to ec463ab Compare May 29, 2026 08:05
Comment thread arm9/source/patches/platform/acekard-common/IoRpgDefinitions.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgDefinitions.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgReadSdDmaPatchCode.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgReadSdDmaPatchCode.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgReadSdDmaPatchCode.s Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgSdHelperPatchCode.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgSdReadLoopPatchCode.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgReadSdDmaPatchCode.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgLoaderPlatform.h Outdated
Comment thread arm9/source/patches/platform/acekard-common/IoRpgSdHelperPatchCode.h Outdated
…e shift

The C0 command (read SD state) returns the "state" in different bits of
the response:
- lower halfbyte on AKRPG
- upper halfbyte everywhere else

This is defined in the PlatformSpecifics struct, so use that to patch
the code on the fly instead of using a register to pass this through.
Most of the code is the same, except for the command sent to the card.
Use the new PlatformSpecifics struct to change this on the fly.
Now that SdWaitForState no longer requires passing a platform-specific
parameter, the patch code becomes exactly the same.
Most of the code is the same, except for the command sent to the card.
Use the new PlatformSpecifics struct to change this on the fly.
- push r0-r1 to stack before the sdsc shift
- use r1 for readSd SDSC shift now that it's free, freeing up a register
- keep r4 as 0x040001a0 across routine
- use r4=0x040001A0 from previous subroutine
- use mov/lsls instead of ldr pc, removing unnecessary pool usage
- we can assume that when starting the transfer, the previous command
  used (SdWaitForState) set our MCCNT1 to 0xA7406004, since we need
  0xA1406004 we can just strb the 0xA1 instead of loading entire u32
  from pool
- Use r4=0x040001A0 from previous subroutine to reduce pool usage
@Gericom Gericom merged commit f955c63 into LNH-team:develop Jun 13, 2026
17 checks passed
@lifehackerhansol lifehackerhansol deleted the rpg-dma branch June 13, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants