Skip to content

Commit

Permalink
Shorten the enemy list in bank 5.
Browse files Browse the repository at this point in the history
In most banks, z2edit moves code and data packed into the enemy list
area to allow the full 1K to be used as enemy list.

In bank 5, the "goto victory" code overlaps the enemy list.  Since bank
5 is already pretty full and only has 63 rooms (instead of the usual
126), set the list size for bank 5 to 688 bytes to not overwrite the
victory code.
  • Loading branch information
Chris Frantz committed Apr 26, 2019
1 parent d29cd47 commit 3ab4dec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nes/enemylist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ void EnemyListPack::Unpack(int bank) {
const auto& misc = ConfigLoader<RomInfo>::GetConfig().misc();

bank_ = bank;
// In bank5, the victory sequence starts at 0x8b50, so we have fewer
// bytes available for the enemy list.
// In the other banks, I've taken pains to move things around, but
// bank5 is pretty full and has only 63 rooms instead of 126, so
// ~half the space should be enough.
size_ = (bank == 5) ? 688 : 1024;
area_.resize(126, 0);

LoadEncounters();
Expand All @@ -73,7 +79,7 @@ void EnemyListPack::Unpack(int bank) {
Address pointer = mapper_->ReadAddr(addr, 2*n);
uint16_t pa = pointer.address();
if (pa >= misc.enemy_data_ram() &&
pa < misc.enemy_data_ram() + 1024) {
pa < misc.enemy_data_ram() + size_) {
ReadOne(i, pointer);
}
}
Expand Down Expand Up @@ -103,7 +109,7 @@ bool EnemyListPack::Pack() {

List& entry = entry_[addr];
if (entry.newaddr == 0) {
if (packed.size() + entry.data.size() > 1024) {
if (packed.size() + entry.data.size() > size_) {
LOGF(ERROR, "Out of space for enemy list at %d", i);
return false;
}
Expand All @@ -127,7 +133,7 @@ bool EnemyListPack::Pack() {
}

// And copy the enemy lists to the rom
packed.resize(1024, 0);
packed.resize(size_, 0);
Address addr;
addr.set_bank(bank_);
addr.set_address(misc.enemy_data_rom());
Expand Down
1 change: 1 addition & 0 deletions nes/enemylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EnemyListPack {
Mapper* mapper_;
int newareas_;
int bank_;
size_t size_;

struct List {
uint16_t newaddr;
Expand Down

0 comments on commit 3ab4dec

Please sign in to comment.