Page 1 of 1
NABULIB 2023.04.08.00
Posted: Sun Apr 09, 2023 4:40 am
by DJ Sures
I added a new function to NABULIB that detects if cloud CPM is running. that way, your program can use the IA remote file system call to save/load files from the host PC or use other RetroNET functions. There's an example TEST project in GitHub
Requires the latest cloud cpm bios 8.3 or higher
Example Code
Code: Select all
#define BIN_TYPE BIN_CPM
// Disable the NABULIB keyboard and use the CPM keyboard
#define DISABLE_KEYBOARD_INT
// Disable the HCCA if you're not using filesystem or control ia
#define DISABLE_HCCA_RX_INT
// Disable the VDP if you're making a CPM console app. Console apps can use vt_XXX commands for moving cursor in emulation mode
#define DISABLE_VDP
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "../NABULIB/NABU-LIB.h"
void main() {
puts("");
if (isCloudCPM())
puts("You are running Cloud CPM!");
else
puts("Cloud CPM is not detected");
puts("");
}
Re: NABULIB 2023.04.08.00
Posted: Sun Apr 09, 2023 6:37 am
by productiondave
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
Re: NABULIB 2023.04.08.00
Posted: Sun Apr 09, 2023 7:04 am
by DJ Sures
Noice.
One tip if you can initialize HS = 0 on the declaration statement and not need the multiple ELSE hl=0 statements. It'll be a bit more efficient and use fewer cycles
Re: NABULIB 2023.04.08.00
Posted: Sun Apr 09, 2023 7:15 am
by productiondave
DJ Sures wrote: ↑Sun Apr 09, 2023 7:04 am
Noice.
One tip if you can initialize HS = 0 on the declaration statement and not need the multiple ELSE hl=0 statements. It'll be a bit more efficient and use fewer cycles
Good point. I probably would have landed there eventually, but always good to have a second set of eyes. I'll edit the code above for the casual reader.
Re: NABULIB 2023.04.08.00
Posted: Sun Apr 09, 2023 7:22 pm
by DJ Sures
Like I say in my videos, version 1 is never optimized.
I can review my code a dozen times and always find something to optimize lol