I have a hex file which I would like to import into my sketch to be used as an array.
but I believe I need to use it in the way outlined below (unless someone says otherwise)
Converted into a text file my hex code looks like this.
What I am trying to do is to split this up and, in a loop send out the commands to a chip as a stream.
The first byte (01) is a value (which needs to be converted to decimal) and the 2nd byte (20) is the register.
const byte oplData[2][] = {
{1, 0x20},{8, 0x40}
}
Which then loops as
for (x = 0; x < dataMax; x++) {
setReg(oplData[1][x],oplData[0][x]);
delay(whatever);
}
so my problem is, of course, that it would take me endless hours to format my hex code into the const byte array.
Is there some other/better way I can approach this?
Where is this hex file, where is it supposed to end up and where/why is the Arduino involved?
Seems like the conversion you want done would take but a minute on a PC.
It’s pretty common in situations like this to write a pc-side program in your favorite pc programming language to read the “weird format” file and write C code...
DKWatson:
Where is this hex file, where is it supposed to end up and where/why is the Arduino involved?
Seems like the conversion you want done would take but a minute on a PC.
So the hex file is a modified version of a .vgm file, which is a file that includes a stream of register data pushed to music synthesizer ICs in this case, a Yamaha YMF262 OPL3 chip.
I am simply using the arduino at this point just to set up connection with the chip and play around a bit.
Beyond hardcoding a few registers by hand, I would like to stream the register values from the hex out to the chip in a loop and 'hear the music'
This is a generic parser that is used to read ASCII text files character by character and make changes. As it is set up, it remove from broken sentences and replaces with a space - to take advantage of word wrap.
int main(int argc, char *argv[])
{
int ch; // place to store each character as read
int ch_old;
FILE *fp; // "file pointer"
FILE *temp;
if (argc < 2)
{
printf("Usage: %s filename\n", argv[0]);
exit(EXIT_FAILURE);
}
if ((fp = fopen(argv[1], "r")) == NULL)
{
printf("Can't open %s\n", argv[1]);
exit(EXIT_FAILURE);
}
temp = fopen("temp.txt", "w");
//if (argc == 3) list_threshold = ((int)argv[2] - 48);
while ((ch = getc(fp)) != EOF)
{
if(ch == 13) break;
if(ch == 10)
{
ch = getc(fp);
//if(ch_old == 46 || (ch_old >= 65 && ch_old <= 90))
if(ch_old == COMMA || islower(ch_old)) (putc(32, temp));
else
{
putc(10, temp);
putc(10, temp);
}
}
putc(ch, temp);
ch_old = ch;
}
fclose(fp);
fclose(temp);
return 0;
}