[Coco] SuperIDE and CF Cards

Luis Antoniosi (CoCoDemus) retrocanada76 at gmail.com
Wed Jul 10 09:59:29 EDT 2013


dd just works on cygwin. But there is a catch: I always use megabyte block
copy:


Using a 256mb C-9 stock CF to extract its image:

dd if=/dev/sdb1 of=cfimage.img bs=1M count=245

to put an image on it:

dd if=cfimage.img of=/dev/sdb1 bs=1M count=245


Of course you should look at proc/partitions to see which one is your local
cf card. In my case is /dev/sdb1:

cat /proc/partitions


You can also use toolshed to handle files on the very first os-9 partition
just like this:

os9 dir /dev/sdb1,
os9 dir makdir /dev/sdb1,EXTRAS
os9 copy file /dev/sdb1,EXTRAS/file

and so on.

but to get/put a hdbdos image on it you should use my command line tool:

side put image.dsk 240 /dev/sdb1

side get image.dsk 240 /dev/sdb1

of course, supposing you are using default 0x052ddc offset.

Compile the following program on cygwin: gcc side.cpp -o side and put it on
/usr/local/bin:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char g_imageFilename[1024];
char g_cfDevice[1024];

#define OPMODE_GET 0
#define OPMODE_PUT 1

int g_opMode = -1;
int g_imageNumber = -1;
int g_hdbdosOffset = 0x52ddc;

int g_numOfDrives = 256;
int g_numOfSectors = 500700;

void printError(const char *msg)
{
printf(msg);

printf("Side 1.0\nHDB-DOS virtual disk tool for Cloud9 SuperIDE CF
cards\n");
printf("Author: Luis F. Antoniosi - felipe.antoniosi at gmail.com\n");
printf("\nUsage:\n\n");
printf("\nside [get|put] <hdb-dos image> <drive number> <cf device|image
file> [options]\n\n");
printf("where options are:\n\n");
printf("-s <total number of sectors> : Default 500700\n");
printf("-d <total number of drives>  : Default 256\n");
printf("\nExamples:\n\n");
printf("side get disk10.dsk 10 /dev/sdb1\n");
printf("side put games03.dsk 35 /dev/sdb1\n");

exit(1);
}

void parseParams(int argc, char **argv)
{
if (argc < 5)
{
printError("Error: missing parameters\n");
}

if (strcmp(argv[1], "get") == 0)
{
g_opMode = OPMODE_GET;
}
else
if (strcmp(argv[1], "put") == 0)
{
g_opMode = OPMODE_PUT;
}

strncpy(g_imageFilename, argv[2], 1023);
g_imageNumber = atoi(argv[3]);
strncpy(g_cfDevice, argv[4], 1023);

for (int i = 5; i < argc; ++i)
{
if (strcmp(argv[i], "-d") == 0)
{
if (++i < argc)
{
g_numOfDrives = atoi(argv[i]);
}
}
else
if (strcmp(argv[i], "-s") == 0)
{
if (++i < argc)
{
g_numOfSectors = atoi(argv[i]);
}
}
}
}


int main(int argc, char **argv)
{
parseParams(argc, argv);

char cmd[2048];
char disk[630*512];
int skip = (g_numOfSectors - (630 * g_numOfDrives) + g_imageNumber * 630) *
512;
 if (g_opMode == OPMODE_GET)
{
FILE *in = fopen(g_cfDevice, "rb");
FILE *out = fopen(g_imageFilename, "wb");

if (!in)
printError("Error: could not open cf device\n");
if (!out)
printError("Error: could not open image file\n");

fseek(in, skip, SEEK_SET);
char sector[512];
 for(int i = 0; i < 630; i++)
{
fread(sector, 512, 1, in);
fwrite(sector, 256, 1, out);
}
fclose(in);
fclose(out);
}
else
{
FILE *in = fopen(g_imageFilename, "rb");
FILE *out = fopen(g_cfDevice, "r+b");

if (!out)
printError("Error: could not open cf device\n");
if (!in)
printError("Error: could not open image file\n");

fseek(out, skip, SEEK_SET);
char sector[256];

//for(int i = 0; i < 630; i++)
 while(1)
{
fread(sector, 256, 1, in);
 if (feof(in)) break;
 fwrite(sector, 256, 1, out);
fwrite(sector, 256, 1, out);
}
 fclose(in);
fclose(out);
}

return 0;
}



More information about the Coco mailing list