tutorial:file_operations

This is an old revision of the document!


File Operations

In most software applications that require large sets of data or interaction which cannot be expressed before compile time, we use files to store large sets of data and other information that we may require for our programs. These files and folders can be accessed by our program in order to carry out the program's intended purpose. This could be configuration files in formats like JSON, INI, PROPERTIES, TOML, etc. or maybe textures for your games and applications or audio for music playback and so many more uses!

On the PSP, the files are stored on your memory stick. It uses the FAT file system and allows you to create, modify, and delete files pretty freely. You also have other spaces such as Flash memory which is meant for OS and system storage, and UMDs which can also store data. In this context, we're looking at just the Memory Stick. The drive name of the Memory Stick is ms0 (memory stick 0 - as if we could have a PSP with more than 1). The PSP uses Unix-styled line separators with '/' instead of Windows' '\'. The PSP file system is rather simple and easy to use and is exposed through the sceIo module. This “file manager” allows you to interact directly with the disk through Unix-like syscalls. Fortunately, C, C++, and Zig all have file abstractions through their respective standard libraries. Rust has an experimental standard library for the PSP but I have been advised to wait for it to be finished before attempting to use it. Our application will create and open a file, write some data, read it back, and then exit.

main.c

// The beginning is covered elsewhere
int main() {
    setupCallbacks();
 
    FILE* file = fopen("test.txt", "w");
    fprintf(file, "1 2 3! Hello PSP!");
    fclose(file);
 
    FILE* file2 = fopen("test.txt", "r");
    char arr[19] = {0};
    fread(arr, sizeof(char), 18, file2);
    fclose(file2);
 
    pspDebugScreenInit();
    pspDebugScreenPrintf("%s", arr);
}

main.cpp

 

main.rs

 

main.zig

 
  • tutorial/file_operations.1605824315.txt.gz
  • Last modified: 2020/11/19 22:18
  • by iridescence