Skip to content

Commit

Permalink
Fix 'Emulate' from Maze Island overworld.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Frantz committed Apr 19, 2020
1 parent 46fc8cf commit 565ca88
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
9 changes: 6 additions & 3 deletions app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ void Z2Edit::SpawnEmulator(
uint8_t palace_code,
uint8_t connector,
uint8_t room,
uint8_t page) {
uint8_t page,
uint8_t prev_region) {

uint8_t facing = (page < 3) ? 0 : 1;
LOGF(INFO, "StartEmulator:");
Expand All @@ -967,7 +968,7 @@ void Z2Edit::SpawnEmulator(
0xa9, region, // LDA #region
0x8d, 0x06, 0x07, // STA $0706
0xa9, world, // LDA #world
0x8d, 0x07, 0x07, // STA $0706
0x8d, 0x07, 0x07, // STA $0707
0xa9, town_code, // LDA #town_code
0x8d, 0x6b, 0x05, // STA $056b
0xa9, palace_code, // LDA #palace_code
Expand All @@ -980,6 +981,8 @@ void Z2Edit::SpawnEmulator(
0x8d, 0x5c, 0x07, // STA $075c
0xa9, facing, // LDA #facing
0x8d, 0x01, 0x07, // STA $0701
0xa9, prev_region, // LDA #prev_region
0x8d, 0x0a, 0x07, // STA $070a
0x60, // RTS
};
uint16_t addr = 0xaa3f & 0x3FFF;
Expand Down Expand Up @@ -1013,7 +1016,7 @@ void Z2Edit::ProcessMessage(const std::string& msg, const void* extra) {
editor_->Refresh();
} else if (msg == "emulate_at") {
const uint8_t* p = reinterpret_cast<const uint8_t*>(extra);
SpawnEmulator(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
SpawnEmulator(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]);
} else {
console_.AddLog("[error] Unknown message %s(%p)", msg.c_str(), extra);
}
Expand Down
2 changes: 1 addition & 1 deletion app.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Z2Edit: public ImApp {
void SpawnEmulator();
void SpawnEmulator(uint8_t bank, uint8_t region, uint8_t world,
uint8_t town_code, uint8_t palace_code, uint8_t connector,
uint8_t room, uint8_t page);
uint8_t room, uint8_t page, uint8_t prev_region);
int EncodedText(int ch);
bool ParseChr(const std::string& a, int* bank, uint8_t *addr);

Expand Down
22 changes: 18 additions & 4 deletions imwidget/map_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,27 @@ void OverworldConnector::StartEmulator() {
uint8_t overworld = dest_overworld_ ? dest_overworld_ : overworld_;
if (dest_world_ == 0) {
// Hack - there is no overworld bank table.
bank += overworld / 2;
if (overworld == 1) {
// overworld 1 can mean both DM or MZ. Try to determine which
// by examining the owning overworld.
bank = 1 + overworld_ / 2;
} else {
bank = 1 + overworld / 2;
}
}
if (subworld_) overworld = subworld_;

uint8_t params[] = { bank, overworld, uint8_t(dest_world_), town_code,
palace_code, connector, uint8_t(map_),
uint8_t(entry_) };
uint8_t params[] = {
bank,
overworld,
uint8_t(dest_world_),
town_code,
palace_code,
connector,
uint8_t(map_),
uint8_t(entry_),
uint8_t(overworld_),
};
ImApp::Get()->ProcessMessage("emulate_at", params);

}
Expand Down
1 change: 1 addition & 0 deletions imwidget/simplemap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void SimpleMap::StartEmulator(int screen) {
uint8_t(1), // connector: we don't know
uint8_t(map_.area()), // map number
uint8_t(screen), // start screen
uint8_t(map_.overworld()), // prev_overworld
};
ImApp::Get()->ProcessMessage("emulate_at", params);
}
Expand Down

0 comments on commit 565ca88

Please sign in to comment.