Re: [Tuxnes-devel] GameGenie: Only one code is used.
Brought to you by:
tmmm
From: Jason D. S. <js...@an...> - 2003-11-30 17:19:19
|
I'm not positive I understand the problem, but here goes... Mike Mestnik wrote: > I'm trying to fix this, but I get hung up on how to add to a pointer when parsing a string. So if > you can get this patch to work, much thanx. > > The problem I can't overcome is the call to DecodeGameGenieCode needs ggcode[gamegenie]. It's a > pointer withought a cast. Giving it a cast like (char *) dose nothing. What I need to do is add > gamegenie to the value of (char *)ggcode to get a new pointer that points into the middle, after > the last ',', of ggcode. I do this in 2 places, one is unavoidable unless you rewrite the whole > thing. ggcode[gamegenie] is a char, not a char*. I think you want (ggcode + gamegenie) or &ggcode[gamegenie] so that you have the pointer to the string rather than the first character of it? > + int gamegenie = 0; Technically this should be a size_t. > @@ -1373,8 +1362,9 @@ > showheader = 1; > break; > case 'g': > - gamegenie = 1; > ggcode = optarg; > + for ( gamegenie = strlen(ggcode); gamegenie <= 1; gamegenie-- ) > + if ( ggcode[gamegenie-1] == ',' ) break; Shouldn't the comparison be "gamegenie >= 1"? > @@ -2126,12 +2116,15 @@ > } > > /* enter the Game Genie codes */ > - if (gamegenie) > + while (gamegenie) > { > - ggret = DecodeGameGenieCode (ggcode, &address, &data, &compare); > + char * _ggcode; > + _ggcode = ggcode + gamegenie; > + ggret = DecodeGameGenieCode (_ggcode, &address, &data, &compare); Exactly. (But you don't need the temporary variable; you can just pass ggcode + gamegenie directly.) > @@ -2167,6 +2160,9 @@ > fprintf (stderr, "Game Genie: value at %04X = %02X\n", address, > MAPTABLE[address >> 12][address]); > } > + bzero( ggcode + --gamegenie, 1 + strlen(ggcode) - gamegenie); > + for ( gamegenie = strlen(ggcode); gamegenie <= 1; gamegenie-- ) > + if ( ggcode[gamegenie-1] == ',' ) break; > } I guess this is the loop part (to handle multiple codes, separated by commas), but I don't quite understand it. I'm pretty sure it's not right, though - it doesn't corectly handle the gamegenie==0 case. And again you want >= rather than <=. I'd do something like while (ggcode /* Look at ggcode, not gamegenie. */) { /* ... */ if (gamegenie > 0) { /* Find next code. */ ggcode[--gamegenie] = '\0'; for (gamegenie--; gamegenie >= 1; gamegenie--) if (ggcode[gamegenie-1] == ',') break; } else { /* End loop. */ ggcode = NULL; } Of course, it could be that I'm completely misunderstanding your code. jason short |