FujiNet is a fantastic device for the Atari 8 bit line of computers which provides WiFi, and SD card storage among other things, all over SIO. One of the functions provided is APETIME support, a protocol developed by AtariMax as part of their Atari Peripheral Emulator (APE).
In the last post I demonstrated my BASIC and Action! versions of a program to get the time from the FujiNet device using APETIME. The procedure is documented here (https://github.com/FujiNetWIFI/fujinet-platformio/wiki/Accessing-the-Real-Time-Clock). At the time of this writing there was no complete C example, only an example of the call.
After completing the conversion of my Action! library to C, and starting a new project where I needed to get the time from FujiNet from C, I thought it would be a good time to create a version of the FujiNet time program I had written in BASIC and Action!. This post details my solution. I wrote the routine into a function which can be called from the main program at any point. It only requires passing a pointer to a 6 byte array.
To call the SIO routine, I used inline assembly to execute the jump.
As with my Action! source, the routine that gets the time from FujiNet is the FNGTime() function (FujiNet Get Time). It first sets up the SIO call by assigning appropriate values into the DCB (Device Control Block) memory location. Using CC65 v2.19+ libraries allows setting the DCB via equates using an OS structure as defined in “atari.h” include file, with no need for the Poke function. It sets the buffer location (DBUF), to the address of the byte array passed in.
Last it calls the SIO vector using the SIOV function.
The main routine sets aside 6 bytes of storage, calls the FNGTime() function with the address of the storage array, then prints the result in a friendly fashion.
// ------------------------------------------------------------ // Program: fujitime.c // Desc...: Gets date/time from FujiNet // Author.: Ripdubski // Date...: 2023.02.09 // Notes..: cl65 -v [-O] -t atarixl fujitime.c -o fujitime.xex // ------------------------------------------------------------ // Pull in include files #include <stdio.h> #include <atari.h> #include <conio.h> #include <unistd.h> // ----------------------------------- // Proc..: void SIOV(void) // Desc..: OS SIO Vector // ----------------------------------- void SIOV(void) { __asm__ ("JSR $E459"); } // ----------------------------------- // Proc..: void FNGTime(char *bA) // Desc..: Get date/time from FujiNet // via APETIME protocol // Return: 6 bytes DMYHMS into bA // ----------------------------------- void FNGTime(char *bA) { // Setup SIO call using byte array address // by putting values into the DCB. // APETime=Device 69 ($45), Unit 1 // Time command=147 ($93) // Get 6 bytes, timeout just over 15s OS.dcb.ddevic = 0x45; OS.dcb.dunit = 0x01; OS.dcb.dcomnd = 0x93; OS.dcb.dstats = 0x40; OS.dcb.dbuf = (void *) bA; OS.dcb.dtimlo = 15; OS.dcb.dunuse = 0; OS.dcb.dbyt = (unsigned int) 6; // Call SIO SIOV(); } // ----------------------------------- // Main Routine // ----------------------------------- void main(void) { // Storage for 6 bytes preset to 0 char bDT[7]={ 0, 0, 0, 0, 0, 0 }; // Call time routine with the storage array FNGTime(bDT); // What time is it? printf("\nDate: 20%d.%d.%d\n", bDT[2], bDT[1], bDT[0]); printf("Time: %d:%d:%d\n", bDT[3], bDT[4], bDT[5]); // Wait for a keystroke printf("Press any key to continue...\n"); while (! kbhit()) {}; }
I’m going to include the FNGTime() function in my C library which was converted from my Action! library in 2022. This will happen in a future release.