@@ -183,16 +183,30 @@ int parse_arg_value(const char *arg, bool absolute, const struct Symbol *symbols
183
183
return parse_number (arg , 0 );
184
184
}
185
185
186
+ // Symbols may take the low or high part
187
+ enum { SYM_WHOLE , SYM_LOW , SYM_HIGH } part = SYM_WHOLE ;
188
+ if (arg [0 ] == '<' ) {
189
+ part = SYM_LOW ;
190
+ arg ++ ;
191
+ } else if (arg [0 ] == '>' ) {
192
+ part = SYM_HIGH ;
193
+ arg ++ ;
194
+ }
195
+
186
196
// Symbols evaluate to their offset or address, plus an optional offset mod
187
197
int offset_mod = 0 ;
188
198
char * plus = strchr (arg , '+' );
189
199
if (plus ) {
190
200
offset_mod = parse_number (plus , 0 );
191
201
* plus = '\0' ;
192
202
}
203
+
204
+ // Symbols evaluate to their offset or address
193
205
const char * sym_name = !strcmp (arg , "@" ) ? patch_name : arg ; // "@" is the current patch label
194
206
const struct Symbol * symbol = symbol_find (symbols , sym_name );
195
- return (absolute ? symbol -> offset : symbol -> address ) + offset_mod ;
207
+
208
+ int value = (absolute ? symbol -> offset : symbol -> address ) + offset_mod ;
209
+ return part == SYM_LOW ? value & 0xff : part == SYM_HIGH ? value >> 8 : value ;
196
210
}
197
211
198
212
void interpret_command (char * command , const struct Symbol * current_hook , const struct Symbol * symbols , struct Buffer * patches , FILE * restrict new_rom , FILE * restrict orig_rom , FILE * restrict output ) {
@@ -344,6 +358,12 @@ struct Buffer *process_template(const char *template_filename, const char *patch
344
358
345
359
// The ROM checksum will always differ
346
360
buffer_append (patches , & (struct Patch ){0x14e , 2 });
361
+ // The Stadium data (see stadium.c) will always differ
362
+ unsigned int rom_size = (unsigned int )xfsize ("" , orig_rom );
363
+ if (rom_size == 128 * 0x4000 ) {
364
+ unsigned int stadium_size = 24 + 6 + 2 + 128 * 2 * 2 ;
365
+ buffer_append (patches , & (struct Patch ){rom_size - stadium_size , stadium_size });
366
+ }
347
367
348
368
// Fill in the template
349
369
const struct Symbol * current_hook = NULL ;
@@ -413,7 +433,7 @@ struct Buffer *process_template(const char *template_filename, const char *patch
413
433
int compare_patch (const void * patch1 , const void * patch2 ) {
414
434
unsigned int offset1 = ((const struct Patch * )patch1 )-> offset ;
415
435
unsigned int offset2 = ((const struct Patch * )patch2 )-> offset ;
416
- return offset1 > offset2 ? 1 : offset1 < offset2 ? -1 : 0 ;
436
+ return ( offset1 > offset2 ) - ( offset1 < offset2 ) ;
417
437
}
418
438
419
439
bool verify_completeness (FILE * restrict orig_rom , FILE * restrict new_rom , struct Buffer * patches ) {
0 commit comments