DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions | Variables
decode.c File Reference
#include <stdio.h>
#include <string.h>
#include "decode.h"

Functions

void genie_decode (const char *code, struct patch *result)
 Decode a Game Genie Code.
void hex_decode (const char *code, struct patch *result)
 "Decode" an address/data pair into a structure.
void decode (const char *code, struct patch *result)
 THIS is the function you call from the MegaDrive or whatever.

Variables

static char genie_chars [] = "AaBbCcDdEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz0O1I2233445566778899"
 Decode a Game Genie code into an M68000 address/data pair.

Function Documentation

void decode ( const char *  code,
struct patch result 
)

THIS is the function you call from the MegaDrive or whatever.

This figures out whether it's a genie or hex code, depunctuates it, and calls the proper decoder.

Parameters:
[in]codeGame Genie or hex code.
[out]resultThe resulting address:data pair is returned in the struct patch pointed to by result. If an error results, both the address and data will be set to -1.
void genie_decode ( const char *  code,
struct patch result 
)

Decode a Game Genie Code.

This function converts a Game Genie code to an address:data pair. The code is given as an 8-character string, like "BJX0SA1C". It need not be null terminated, since only the first 8 characters are taken. It is assumed that the code is already made of valid characters, i.e. there are no Q's, U's, or symbols. If such a character is encountered, the function will return with a warning on stderr.

The resulting address:data pair is returned in the struct patch pointed to by result. If an error results, both the address and data will be set to -1.

Parameters:
[in]code8 character Game Genie code.
[out]resultThe resulting address:data pair is returned in the struct patch pointed to by result. If an error results, both the address and data will be set to -1.
void hex_decode ( const char *  code,
struct patch result 
)

"Decode" an address/data pair into a structure.

This is for "012345:ABCD" type codes. You're more likely to find Genie codes circulating around, but there's a chance you could come on to one of these. Which is nice, since they're MUCH easier to implement ;) Once again, the input should be depunctuated already.

Parameters:
[in]code8 character Game Genie code.
[out]resultThe resulting address:data pair is returned in the struct patch pointed to by result. If an error results, both the address and data will be set to -1.

Variable Documentation

char genie_chars[] = "AaBbCcDdEeFfGgHhJjKkLlMmNnPpRrSsTtVvWwXxYyZz0O1I2233445566778899"
static

Decode a Game Genie code into an M68000 address/data pair.

The Game Genie code is made of the characters ABCDEFGHJKLMNPRSTVWXYZ0123456789 (notice the missing I, O, Q and U). Where A = 00000, B = 00001, C = 00010, ... , on to 9 = 11111.

These come out to a very scrambled bit pattern like this: (SCRA-MBLE is just an example)

S C R A - M B L E 01111 00010 01110 00000 01011 00001 01010 00100 ijklm nopIJ KLMNO PABCD EFGHd efgha bcQRS TUVWX

Our goal is to rearrange that to this:

0000 0101 1001 1100 0100 0100 : 1011 0000 0111 1000 ABCD EFGH IJKL MNOP QRST UVWX : abcd efgh ijkl mnop

which in Hexadecimal is 059C44:B078. Simple, huh? ;)

So, then, we dutifully change memory location 059C44 to B078! (of course, that's handled by a different source file :)