Thanks DJ,
Here is a snippet of code I am working on that seems to work fine. This is just dev code right now, but it proves the point and shows how to save integers into files over retroNet.
Hopefully this additional example will be helpful for people.
Code: Select all
/* Fetch the high score from disk*/
uint16_t getHighScore() {
int hs = 0;
#if BIN_TYPE == BIN_CPM
if (isCloudCPM()) { // We want to save the high score data back to the host PC as a discreet file in the STORE folder.
uint8_t rnfp = rn_fileOpen(9, "snake.dat", OPEN_FILE_FLAG_READONLY, 0xFF);
uint16_t bytesRead = rn_fileHandleRead(rnfp, &hs, 0, 0, sizeof(hs));
rn_fileHandleClose(rnfp);
} else { // We want to use regular old CP/M to store the file into the local file store.
FILE * fp = fopen("snake.dat", "r");
if (fp) {
fscanf(fp, "%d", &hs);
} else {
hs = 0;
}
fclose(fp);
}
#else // We are not building for CPM / probably NABU Native build - so return hs with it's initial value = 0 for the saved high score.
#endif
return hs;
}
/* Write the high score to disk*/
void setHighScore(uint16_t hs) {
#if BIN_TYPE == BIN_CPM
if (isCloudCPM()) { //We want to fetch the high score data from a file stored on the host PC.
uint8_t rnfp = rn_fileOpen(9, "snake.dat", OPEN_FILE_FLAG_READWRITE, 0xFF);
rn_fileHandleEmptyFile(rnfp);
rn_fileHandleInsert(rnfp, 0, 0, sizeof(hs), &hs);
rn_fileHandleClose(rnfp);
} else { //We want to fetch the data from the local file store managed by CPM.
FILE * fp = fopen("snake.dat", "w");
fprintf(fp, "%d", hs);
fclose(fp);
}
#else
(void)hs; // We are not building for CPM / probably NABU Native build - so do nothing at all.
#endif
}
And after a short game, the file created in the IA Store folder on my host PC looks like this for a score of 17.
Code: Select all
hexdump /mnt/c/dev/nabu/Nabu\ Internet\ Adapter/Store/snake.dat -C
00000000 11 00 |..|
00000002