Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *NESGenie(const char *Input, char *Output) {
- char Key[] = "APZLGITYEOXUKSVN", Upper[512];
- int i, Addr=0, Data=0, Compare=0;
- strcpy(Upper, Input);
- for(i=0;Upper[i];i++)
- Upper[i] = toupper(Upper[i]);
- if(strlen(Input) == 6 || strlen(Input) == 8) {
- char n[strlen(Input)];
- for(i=0;Input[i];i++) {
- char *Find = strchr(Key, Upper[i]);
- if(!Find) return "Unrecognized character in code";
- n[i] = Find - Key;
- }
- Addr = 0x8000 + (((n[3] & 7) << 12) | ((n[5] & 7) << 8) | ((n[4] & 8) << 8) \
- | ((n[2] & 7) << 4) | ((n[1] & 8) << 4) | (n[4] & 7) | (n[3] & 8));
- if(strlen(Input) == 6) {
- Data = ((n[1] & 7) << 4) | ((n[0] & 8) << 4) | (n[0] & 7) | (n[5] & 8);
- sprintf(Output, "%.4x %.2x", Addr, Data);
- return Output;
- } else {
- Data = ((n[1] & 7) << 4) | ((n[0] & 8) << 4) | (n[0] & 7) | (n[7] & 8);
- Compare = ((n[7] & 7) << 4) | ((n[6] & 8) << 4) | (n[6] & 7) | (n[5] & 8);
- sprintf(Output, "%.4x %.2x %.2x", Addr, Data, Compare);
- return Output;
- }
- } else if(strlen(Input) == 7 || strlen(Input) == 10) {
- int UseCompare = (strlen(Input)==10);
- Addr = strtol(Input+0, NULL, 16);
- Data = strtol(Input+5, NULL, 16);
- if(!UseCompare) {
- Output[0] = Key[(Data>>4 & 8) | (Data & 7)];
- Output[1] = Key[(Addr>>4 & 8) | (Data>>4 & 7)];
- Output[2] = Key[8 | (Addr>>4 & 7)];
- Output[3] = Key[(Addr & 8) | (Addr>>12 & 7)];
- Output[4] = Key[(Addr>>8 & 8) | (Addr & 7)];
- Output[5] = Key[(Data & 8) | (Addr>>8 & 7)];
- Output[6] = 0;
- return Output;
- } else {
- Compare = strtol(Input+8, NULL, 16);
- Output[0] = Key[(Data>>4 & 8) | (Data & 7)];
- Output[1] = Key[(Addr>>4 & 8) | (Data>>4 & 7)];
- Output[2] = Key[8 | (Addr>>4 & 7)];
- Output[3] = Key[(Addr & 8) | (Addr>>12 & 7)];
- Output[4] = Key[(Addr>>8 & 8) | (Addr & 7)];
- Output[5] = Key[(Compare & 8) | (Addr>>8 & 7)];
- Output[6] = Key[(Compare>>4 & 8) | (Compare & 7)];
- Output[7] = Key[(Data & 8) | (Compare>>4 & 7)];
- Output[8] = 0;
- return Output;
- }
- } else {
- return "Invalid syntax?";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement