Use the fopen, fseek and fwrite commands to add a rom to m4/romslots.bin (offset = slot * &4000).
To parse just a block of a file you need to use FA_READ|FA_WRITE for fopen flags, then you can fseek into the file and just overwrite a block.
#define FA_READ 0x01
#define FA_WRITE 0x02
#define FA_CREATE_NEW 0x04
Then modify (read/overwrite) m4/romconfig.bin and set the corresponding updateflag to 2 (new rom).
Structure of romconfig.bin:
int totalRoms; // 32
int m4RomNum; // M4 rom to map rom number 0-255
int m4RomEnable; // M4 rom enabled
int romRangeStart; // start mapping roms from
int lowerEnable; // lower rom replacement enabled
int lowerSlot; // which slot maps lowerrom (0-31)
unsigned int reserved[2]; // set to zero for now
then for each rom:
typedef struct
{
char updateflag; // 0 = no rom present (or disabled), 1 = rom present (enabled), 2 = New rom will be flashed into M4 internal flash, 3 = remove rom
char name[32]; // name of rom to be displayed in webinterface
} _romConfig[32];
I guess to check for M4 would be to issue one of the commands, ie. version command and check for a response or scan the roms for the rom name "M4 Board".
But one question form my side: How can I upload a ROM from the CPC side into the M4? (I would like to add that functionality to the ROManager).
A second question: Is there an "official" way of detecting if an M4 is connected to the CPC?