Last active
September 28, 2021 12:30
-
-
Save superctr/f6b2ddfc4334473165a6385284905565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note: setting SSG-EG to 100 to enable AM is not supported in old versions of ctrmml/mdsdrv | |
// please set this to 0 for compatibility | |
#include <cstdio> | |
#include <cstdlib> | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <regex> | |
#include <map> | |
#define ALG m[64] | |
#define FB m[65] | |
#define AR (31-m[op+3]) | |
#define DR (31-m[op+4]) | |
#define SR (31-m[op+6]) | |
#define RR (15-m[op+7]) | |
#define SL (15-m[op+5]) | |
#define TL (127-m[op+0]) | |
#define KS m[op+10] | |
#define ML m[op+1] | |
#define DT (m[op+2] > 0 ? (m[op+2]) : (4 + (-m[op+2]))) | |
#define SSG ((m[op+9] > 0 ? (m[op+9] + 7) : 0) | m[op+8] * 100) | |
void extract(std::string& s) | |
{ | |
std::map<int, int> m; | |
std::regex e (R"!!(<\s*Param\s*id=\s*"([^"]*)"\s*value\s*=\s*"([^"]*)")!!"); // matches words beginning by "sub" | |
// default constructor = end-of-sequence: | |
std::regex_token_iterator<std::string::iterator> rend; | |
int submatches[] = { 1, 2 }; | |
std::regex_token_iterator<std::string::iterator> c ( s.begin(), s.end(), e, submatches ); | |
while (c!=rend) | |
{ | |
int id = strtof(c->str().c_str(), NULL) + 0.5; | |
c++; | |
int val = strtof(c->str().c_str(), NULL) + 0.5; | |
c++; | |
m[id] = val; | |
} | |
printf("@1 fm %d %d\n", ALG, FB); | |
for(int op=0; op<64; op+=16) | |
{ | |
printf(" %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d \n", | |
AR, DR, SR, RR, SL, TL, KS, ML, DT, SSG); | |
} | |
} | |
int main(int argc, char* argv[]) | |
{ | |
if(argc > 1) | |
{ | |
if(std::ifstream is{argv[1], std::ios::binary | std::ios::ate}) | |
{ | |
auto size = is.tellg(); | |
std::string str(size, '\0'); | |
is.seekg(0); | |
if(is.read(&str[0],size)) | |
extract(str); | |
return 0; | |
} | |
} | |
printf("fermatap to ctrmml patch converter\n"); | |
printf("thanks to MovieMovies1 and plgDavid\n"); | |
return -1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment