Skip to content

Commit

Permalink
fix freecode in hirom returning wrong banks
Browse files Browse the repository at this point in the history
  • Loading branch information
randomdude999 committed Mar 4, 2024
1 parent 73bec0f commit 03cdce1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/asar/libsmw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,17 @@ void WalkMetadata(int loc, void(*func)(int loc, char * name, int len, const unsi

int getsnesfreespace(int size, int target_bank, bool autoexpand, bool respectbankborders, bool align, bool write_rats, int search_start)
{
return pctosnes(getpcfreespace(size, target_bank, autoexpand, respectbankborders, align, write_rats, snestopc(search_start)));
int pcfree = getpcfreespace(size, target_bank, autoexpand, respectbankborders, align, write_rats, snestopc(search_start));
int snesfree = pctosnes(pcfree);
if(snesfree == -1) return -1;
bool isforcode = target_bank == -2;
// not sure if this is ever a concern for other mappers...
if(isforcode && (mapper == hirom || mapper == exhirom)) {
snesfree = snesfree & ~0x400000;
// maybe this should throw an internal error or something instead lol
if((snesfree&0x8000) != 0x8000) return -1;
}
return snesfree;
}

bool openrom(const char * filename, bool confirm)
Expand Down
5 changes: 3 additions & 2 deletions tests/freespace_hirom.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;`+
;`08000 53 54 41 52 01 00 fe ff 01 02
;`08000 53 54 41 52 02 00 fd ff 08 80 80
;`0fff8 53 54 41 52 fd ff 02 00
;`1fffd 03
;`2fff8 53 54 41 52 ff ff 00 00
Expand All @@ -11,7 +11,8 @@ norom ; hack: this disables checksum generation
hirom

freecode cleaned
db $01,$02
codelbl:
dl codelbl

freedata cleaned
skip $fffd
Expand Down

0 comments on commit 03cdce1

Please sign in to comment.