Read/Write to/from SD [Vega] This code will do the following: 1. Create a directory on the SD called "/demo" 2. Create a file on the SD called "example.txt" at the "/demo" directory then Open it with Write Permissions 3. Write the contents "Hello!" to the SD file. (a size of 6 bytes) 4. Close the file. 5. Reopen the file with Read permissions. Dump the contents to memory (for Dolphin step by step analysis if desired). 6. Close the file. 7. Shutdown the Console/Emulation. Instructions: Enter into Stage builder, code will then execute. NTSC-U C201EB24 00000022 48000029 413A2F64 656D6F00 413A2F64 656D6F2F 6578616D 706C652E 74787400 48656C6C 6F210000 7FE802A6 3FC0803E 7FE3FB78 63CCC0CC 7D8803A6 4E800021 2C03FFFF 418000B8 387F0008 388D8180 63CCBEB8 7D8803A6 4E800021 2C030000 4182009C 7C661B78 7C7D1B78 387F001C 38800001 38A00006 63CCBF98 7D8803A6 4E800021 2C030006 40820074 7FA3EB78 63CCBE8C 7D8803A6 4E800021 2C030000 4082005C 387F0008 388D8170 63CCBEB8 7D8803A6 4E800021 2C030000 41820040 7C661B78 7C7D1B78 3C608000 60631500 38800001 38A00006 63CCBEE4 7D8803A6 4E800021 2C030006 40820014 7FA3EB78 63CCBE8C 7D8803A6 4E800021 3D80801E 618C26D8 7D8803A6 4E800020 00000000 Code Creator: Vega Source: #Address (NTSC-U) = 8001EB24 .macro call_link address ori r12, r30, \address@l mtlr r12 blrl .endm .macro _OSShutdownToSBY lis r12, 0x801E ori r12, r12, 0x26D8 mtlr r12 blr .endm .set FAFclose, 0xBE8C .set FAFopen, 0xBEB8 .set FAFread, 0xBEE4 .set FAFwrite, 0xBF98 .set FAMkdir, 0xC0CC #r31 = LUT Pointer #r30 = FA functions upper 16 bits #r29 = Fd pointer backup #Set Lookup Table for file path strings and file contents bl lookup_table .string "A:/demo" .string "A:/demo/example.txt" .string "Hello!" .zero 1 #For alignment lookup_table: mflr r31 #Set Lookup table pointer #Set FA functions upper 16 bits lis r30, 0x803E #Make new directory mr r3, r31 call_link FAMkdir cmpwi r3, -1 #r3 return 0 for new directory made, and returns -1 if directory always exists. All other negative numbers are errors. blt- the_end #FAFopen allows you to create+open a file in one go. Obviously we will open with Write Permissions. addi r3, r31, 8 subi r4, r13, 32384 #FAFopen is diff than ISFS_Open, it needs a pointer to the ASCii of "r" (read) or "w" (write). Lucky for us, the game alreadys keeps this data at a constant spot in reference to r13. There's other values you can use such as "a" (append). call_link FAFopen cmpwi r3, 0 #FAFOpen returns a File Descriptor POINTER, returns 0 if unsucessful beq- the_end #Write the file #r3 buffer #r4 size (put this as 1) #r5 count (amount of bytes) #r6 fd pointer mr r6, r3 #Place fd pointer in r6 arg for FAFwrite mr r29, r3 #Backup fd pointer addi r3, r31, 0x001C #Buffer (memory pointer where contents to be written reside at) li r4, 1 li r5, 6 #Amount of bytes to write call_link FAFwrite cmpwi r3, 6 #Return value should match r5 arg's value bne- the_end #Close the file mr r3, r29 call_link FAFclose cmpwi r3, 0 #Return of 0 = success bne- the_end #Reopen file with Read Permissions addi r3, r31, 8 subi r4, r13, 32400 #Pointer to "r" (read) in reference to r13 call_link FAFopen cmpwi r3, 0 beq- the_end #Read the file #Uses the same args as FAFwrite but r3 is where the contents will be dumped instead of pointing to contents that will be used for the write mr r6, r3 mr r29, r3 lis r3, 0x8000 #Dumping contents of fiel to 0x80001500 ori r3, r3, 0x1500 li r4, 1 li r5, 6 call_link FAFread cmpwi r3, 6 #Same return rules as FAFwrite bne- the_end #Close the file mr r3, r29 call_link FAFclose #No need for the return check since we are at the end. #Shutdown console/dolphin the_end: _OSShutdownToSBY