Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- #define SIZE_REGS 48
- #define SIZE_TFI 42
- void cleanup(void);
- typedef struct
- {
- uint8_t version;
- uint8_t system;
- uint8_t instmode;
- uint8_t regs[SIZE_REGS];
- } dmppatch;
- typedef struct
- {
- uint8_t regs[SIZE_TFI];
- } tfipatch;
- FILE *fin = NULL;
- FILE *fout = NULL;
- dmppatch *dmp;
- tfipatch *tfi;
- int main(int argc, char *argv[])
- {
- int i, j, k;
- atexit(cleanup);
- if(argc < 3)
- {
- printf("%s in.dmp out.tfi\n",argv[0]);
- return 1;
- }
- dmp = malloc(sizeof(dmppatch));
- tfi = malloc(sizeof(tfipatch));
- if(!dmp || !tfi)
- {
- printf("Couldn't alloc mem\n");
- return 1;
- }
- memset(dmp, 0, sizeof(dmppatch));
- memset(tfi, 0, sizeof(tfipatch));
- fin = fopen(argv[1],"rb");
- if(!fin)
- {
- puts("Couldn't open file\n");
- return 1;
- }
- fread(&dmp->version, 1, 1, fin);
- fread(&dmp->system, 1, 1, fin);
- fread(&dmp->instmode, 1, 1, fin);
- if (dmp->version != 11) puts("Warn: not DMP version 11");
- if (dmp->system != 2) puts("Warn: not SYSTEM_GENESIS");
- if (dmp->instmode != 1)
- {
- puts("Err: Not a DMP FM instrument");
- return 1;
- }
- fread(dmp->regs, 1, SIZE_REGS, fin);
- fclose(fin);
- tfi->regs[0] = dmp->regs[2];
- tfi->regs[1] = dmp->regs[1];
- for(i = 0; i < 4; i++)
- {
- j = i * 10;
- k = i * 11;
- tfi->regs[2 + j] = dmp->regs[4 + k];
- tfi->regs[3 + j] = dmp->regs[12 + k];
- tfi->regs[4 + j] = dmp->regs[5 + k];
- tfi->regs[5 + j] = dmp->regs[11 + k];
- tfi->regs[6 + j] = dmp->regs[6 + k];
- tfi->regs[7 + j] = dmp->regs[7 + k];
- tfi->regs[8 + j] = dmp->regs[13 + k];
- tfi->regs[9 + j] = dmp->regs[9 + k];
- tfi->regs[10 + j] = dmp->regs[8 + k];
- tfi->regs[11 + j] = dmp->regs[14 + k] & 0x0F;
- }
- fout = fopen(argv[argc-1],"wb");
- if(!fout)
- {
- printf("Couldn't open %s for writing\n", argv[argc-1]);
- return 1;
- }
- fwrite(tfi, SIZE_TFI, 1, fout);
- return 0;
- }
- void cleanup(void)
- {
- if (tfi) free(tfi);
- if (dmp) free(dmp);
- if (fin) fclose(fin);
- if (fout) fclose(fout);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement