Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5.  
  6. #define SIZE_REGS   48
  7. #define SIZE_TFI    42
  8.  
  9. void cleanup(void);
  10.  
  11. typedef struct
  12. {
  13.     uint8_t version;
  14.     uint8_t system;
  15.     uint8_t instmode;
  16.     uint8_t regs[SIZE_REGS];
  17. } dmppatch;
  18.  
  19. typedef struct
  20. {
  21.     uint8_t regs[SIZE_TFI];
  22. } tfipatch;
  23.  
  24. FILE *fin = NULL;
  25. FILE *fout = NULL;
  26.  
  27. dmppatch *dmp;
  28. tfipatch *tfi;
  29.  
  30. int main(int argc, char *argv[])
  31. {
  32.     int i, j, k;
  33.  
  34.     atexit(cleanup);
  35.  
  36.     if(argc < 3)
  37.     {
  38.         printf("%s in.dmp out.tfi\n",argv[0]);
  39.         return 1;
  40.     }
  41.  
  42.     dmp = malloc(sizeof(dmppatch));
  43.     tfi = malloc(sizeof(tfipatch));
  44.  
  45.     if(!dmp || !tfi)
  46.     {
  47.         printf("Couldn't alloc mem\n");
  48.         return 1;
  49.     }
  50.  
  51.     memset(dmp, 0, sizeof(dmppatch));
  52.     memset(tfi, 0, sizeof(tfipatch));
  53.  
  54.     fin = fopen(argv[1],"rb");
  55.  
  56.     if(!fin)
  57.     {
  58.         puts("Couldn't open file\n");
  59.         return 1;
  60.     }
  61.  
  62.     fread(&dmp->version, 1, 1, fin);
  63.     fread(&dmp->system, 1, 1, fin);
  64.     fread(&dmp->instmode, 1, 1, fin);
  65.  
  66.     if (dmp->version != 11) puts("Warn: not DMP version 11");
  67.     if (dmp->system != 2) puts("Warn: not SYSTEM_GENESIS");
  68.  
  69.     if (dmp->instmode != 1)
  70.     {
  71.         puts("Err: Not a DMP FM instrument");
  72.         return 1;
  73.     }
  74.  
  75.     fread(dmp->regs, 1, SIZE_REGS, fin);
  76.     fclose(fin);
  77.  
  78.     tfi->regs[0] = dmp->regs[2];
  79.     tfi->regs[1] = dmp->regs[1];
  80.  
  81.     for(i = 0; i < 4; i++)
  82.     {
  83.         j = i * 10;
  84.         k = i * 11;
  85.         tfi->regs[2 + j] = dmp->regs[4 + k];
  86.         tfi->regs[3 + j] = dmp->regs[12 + k];
  87.         tfi->regs[4 + j] = dmp->regs[5 + k];
  88.         tfi->regs[5 + j] = dmp->regs[11 + k];
  89.         tfi->regs[6 + j] = dmp->regs[6 + k];
  90.         tfi->regs[7 + j] = dmp->regs[7 + k];
  91.         tfi->regs[8 + j] = dmp->regs[13 + k];
  92.         tfi->regs[9 + j] = dmp->regs[9 + k];
  93.         tfi->regs[10 + j] = dmp->regs[8 + k];
  94.         tfi->regs[11 + j] = dmp->regs[14 + k] & 0x0F;
  95.     }
  96.  
  97.     fout = fopen(argv[argc-1],"wb");
  98.  
  99.     if(!fout)
  100.     {
  101.             printf("Couldn't open %s for writing\n", argv[argc-1]);
  102.             return 1;
  103.     }
  104.  
  105.     fwrite(tfi, SIZE_TFI, 1, fout);
  106.  
  107.     return 0;
  108. }
  109.  
  110. void cleanup(void)
  111. {
  112.     if (tfi) free(tfi);
  113.     if (dmp) free(dmp);
  114.     if (fin) fclose(fin);
  115.     if (fout) fclose(fout);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement