Skip to content

Commit

Permalink
Misc Hack to allow different tiles on overworlds.
Browse files Browse the repository at this point in the history
1. Enable overworld tile edits in the ObjectTable.
2. Create "hidden" palette entries which can be enabled/disabled
depending on whether the hack is enabled.
3. Add hack entries to the configuration.
4. Add a MiscellaneousHacks::CheckConfig to enable/disable things in the
configuraiton based on hacks.
  • Loading branch information
Chris Frantz committed Apr 6, 2019
1 parent d76c54e commit e4a018d
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 48 deletions.
3 changes: 3 additions & 0 deletions app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,9 @@ void Z2Edit::ProcessMessage(const std::string& msg, const void* extra) {
tile_transform_->Refresh();
} else if (msg == "loadpostprocess") {
LoadPostProcess(reinterpret_cast<intptr_t>(extra));
} else if (msg == "overworld_tile_hack") {
object_table_->Init();
palette_editor_->Init();
} 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]);
Expand Down
8 changes: 4 additions & 4 deletions content/maps.textpb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
map {
name: "west_hyrule"
name: "west_hyrule overworld"
type: OVERWORLD
connector: { bank: 1 address: 0x861f }
palette: { bank: -1 address: 0x845b }
Expand All @@ -11,7 +11,7 @@ map {
subworld: 0
}
map {
name: "death_mountain"
name: "death_mountain overworld"
type: OVERWORLD
connector: { bank: 1 address: 0xa0fc }
palette: { bank: -1 address: 0x845b }
Expand All @@ -23,7 +23,7 @@ map {
subworld: 1
}
map {
name: "east_hyrule"
name: "east_hyrule overworld"
type: OVERWORLD
connector: { bank: 2 address: 0x861f }
palette: { bank: -1 address: 0x845b }
Expand All @@ -35,7 +35,7 @@ map {
subworld: 0
}
map {
name: "maze_island"
name: "maze_island overworld"
type: OVERWORLD
connector: { bank: 2 address: 0xa0fc }
palette: { bank: -1 address: 0x845b }
Expand Down
52 changes: 52 additions & 0 deletions content/overworld_tiles.textpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
overworld_tiles {
name: "Vanilla (Single overworld tile/palette set)"
hack: [
{address { bank:0 address:0x81a3 } data: [ 0x8d, 0x25, 0x07 ]},
{address { bank:0 address:0x8980 } data: [ 0xbd, 0xa3, 0x87 ]},
{address { bank:0 address:0x8c97 } data: [ 0xbd, 0xa3, 0x87 ]},

{address { bank:0 address:0x8aa8 } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:0 address:0x8ab1 } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:0 address:0x8aba } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:0 address:0x8ac3 } data: [ 0xbd, 0xe3, 0x87 ]},

{address { bank:0 address:0x8bb3 } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:0 address:0x8bbc } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:0 address:0x8bc6 } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:0 address:0x8bcf } data: [ 0xbd, 0xe3, 0x87 ]},
{address { bank:-1 address:0xc051 } data: [ 0x58, 0xc4 ]},
{address { bank:0 address:0xbb00 } data: [
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
]}
]
}
overworld_tiles {
name: "Per Overworld Tile and Palette Sets"
hack: [
{address { bank:0 address:0x81a3 } data: [ 0x4c, 0x08, 0xbb ]},

{address { bank:0 address:0x81a3 } data: [ 0x4c, 0x08, 0xbb ]},
{address { bank:0 address:0x8980 } data: [ 0xbd, 0x40, 0x7a ]},
{address { bank:0 address:0x8c97 } data: [ 0xbd, 0x40, 0x7a ]},

{address { bank:0 address:0x8aa8 } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:0 address:0x8ab1 } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:0 address:0x8aba } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:0 address:0x8ac3 } data: [ 0xbd, 0x80, 0x7a ]},

{address { bank:0 address:0x8bb3 } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:0 address:0x8bbc } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:0 address:0x8bc6 } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:0 address:0x8bcf } data: [ 0xbd, 0x80, 0x7a ]},
{address { bank:-1 address:0xc051 } data: [ 0x90, 0x7a ]},

{address { bank:0 address:0xbb00 } data: [
0x80,0xbb,0x00,0xbc,0x80,0xbc,0x00,0x00,0x8d,0x25,0x07,0xee,0x26,0x07,0xee,0x36,
0x07,0xad,0x06,0x07,0x0a,0xa8,0xb9,0x00,0xbb,0x85,0x0e,0xb9,0x01,0xbb,0x85,0x0f,
0xa0,0x00,0xb1,0x0e,0x99,0x40,0x7a,0xc8,0x10,0xf8,0x60,0xff,0xff,0xff,0xff,0xff
]}

]
}
6 changes: 6 additions & 0 deletions content/palettes.textpb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ palettes {
name: "Overworld"
palette { name: "Overworld" address: { bank: -1 address: 0xc45b } }
palette { name: "Sprites" address: { bank: -1 address: 0xc46b } }
palette { name: "West Hyrule" address: { bank: 0 address: 0xbbd3 } hidden: true }
palette { name: "West Sprites" address: { bank: 0 address: 0xbbe3 } hidden: true }
palette { name: "DM/Maze" address: { bank: 0 address: 0xbc53 } hidden: true }
palette { name: "DM/Maze Sprites" address: { bank: 0 address: 0xbc63 } hidden: true }
palette { name: "East Hyrule" address: { bank: 0 address: 0xbcd3 } hidden: true }
palette { name: "East Sprites" address: { bank: 0 address: 0xbce3 } hidden: true }
}
palettes {
name: "West Hyrule"
Expand Down
149 changes: 126 additions & 23 deletions hacked-roms/overworld_tiles.z2edit
Original file line number Diff line number Diff line change
@@ -1,15 +1,85 @@
set ibase 16
bcopy 0:bd00 0:87a3 50
set bank 0
bcopy 0:bd50 7:c458 24
bcopy 0:bd80 0:bd00 80
bcopy 0:be00 0:bd00 80
wwp bf00 bd00 bd80 be00

asm 81a3
jmp tile_palette_copy_routine
charclear 11:88 true
charclear 11:89 true
charclear 11:8a true
charclear 11:8b true
charclear 11:8c true
charclear 11:8d true
charclear 11:8e true
charclear 11:8f true
charclear 11:90 true
charclear 11:91 true
charclear 11:92 true
charclear 11:93 true
charclear 11:94 true
charclear 11:95 true
charclear 11:96 true
charclear 11:97 true
charclear 11:98 true
charclear 11:99 true
charclear 11:9a true
charclear 11:9b true
charclear 11:9c true
charclear 11:9d true
charclear 11:9e true
charclear 11:9f true
charclear 11:a0 true
charclear 11:a1 true
charclear 11:a2 true
charclear 11:a3 true
charclear 11:a4 true
charclear 11:a5 true
charclear 11:a6 true
charclear 11:a7 true
charclear 11:a8 true
charclear 11:a9 true
charclear 11:aa true
charclear 11:ab true
charclear 11:ac true
charclear 11:ad true
charclear 11:ae true
charclear 11:af true
charclear 11:b0 true
charclear 11:b1 true
charclear 11:b2 true
charclear 11:b3 true
charclear 11:b4 true
charclear 11:b5 true
charclear 11:b6 true
charclear 11:b7 true
charclear 11:b8 true
charclear 11:b9 true
charclear 11:ba true
charclear 11:bb true
charclear 11:bc true
charclear 11:bd true
charclear 11:be true
charclear 11:bf true
charclear 11:c0 true
charclear 11:c1 true
charclear 11:c2 true
charclear 11:c3 true

# Copy original game tile and palette maps to free space
# Make 3 copies: west, dm/mz, east.
bcopy 0:bc00 0:87a3 50
bcopy 0:bc50 7:c458 24
bcopy 0:bc80 0:bc00 80
bcopy 0:bb80 0:bc00 80

asm b=0 0
OV_TILES = $bb00
OV_TILES1 = $bb01

RAM_TILES = $7a40
RAM_TPAL = $7a80
RAM_PALETTE = $7a90

.org OV_TILES
.dw $bb80,$bc00,$bc80,0

.org $bf10
tile_palette_copy_routine:
sta $0725
inc $0726
Expand All @@ -18,31 +88,64 @@ tile_palette_copy_routine:
lda $0706 ; overworld index
asl
tay
lda $bf00,y
lda OV_TILES,y
sta $e
lda $bf01,y
lda OV_TILES1,y
sta $f

ldy #0
loop:
lda ($0e,y)
sta $6940,y
sta RAM_TILES,y
iny
bpl loop
rts
.end

wwp 8981 6940
wwp 8c98 6940
; Patch the overworld-init routine to use our new tables
.org $81a3
jmp tile_palette_copy_routine

; Patch loads to our new RAM address
.org $8980
lda RAM_TILES,x
.org $8c97
lda RAM_TILES,x

wwp 8aa9 6980
wwp 8ab2 6980
wwp 8abb 6980
wwp 8ac4 6980
.org $8aa8
lda RAM_TPAL,x
.org $8ab1
lda RAM_TPAL,x
.org $8aba
lda RAM_TPAL,x
.org $8ac3
lda RAM_TPAL,x

wwp 8bb4 6980
wwp 8bbd 6980
wwp 8bc7 6980
wwp 8bd0 6980
.org $8bb3
lda RAM_TPAL,x
.org $8bbc
lda RAM_TPAL,x
.org $8bc6
lda RAM_TPAL,x
.org $8bcf
lda RAM_TPAL,x

wwp b=7 c051 6990
.org $bc00
.db $88,$89,$88,$89
.db $8a,$8b,$8a,$8b
.db $8c,$8d,$8c,$8d
.db $8e,$8f,$8e,$8f
.db $90,$91,$90,$91
.db $92,$93,$92,$93
.db $94,$95,$94,$95
.db $96,$97,$96,$97
.db $98,$99,$98,$99
.db $9a,$9b,$9a,$9b
.db $9c,$9d,$9c,$9d
.db $9e,$9f,$9e,$9f
.db $a0,$a1,$a0,$a1
.db $a2,$a3,$a2,$a3
.db $a4,$a5,$a4,$a5
.db $a6,$a7,$a6,$a7
.end
# Patch PPU macro table in bank 7
wwp b=7 c051 7a90
80 changes: 80 additions & 0 deletions imwidget/misc_hacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ bool MiscellaneousHacks::DrawMiscHacks() {
[&]() { return ri.spell_cast(); },
[&](int n) { return ri.spell_cast(n); });

Hack("Overworld Tiles", ri.overworld_tiles_size(),
[&]() { return ri.overworld_tiles(); },
[&](int n) { return ri.overworld_tiles(n); });

return false;
}

Expand Down Expand Up @@ -195,6 +199,79 @@ bool MiscellaneousHacks::DrawDynamicBanks() {
return false;
}

void MiscellaneousHacks::CheckConfig() {
auto* ri = ConfigLoader<RomInfo>::MutableConfig();
if (EnabledIndex([&]() { return ri->overworld_tiles(); }) > 0) {
auto *p = ri->mutable_palettes(0);
p->mutable_palette(0)->set_hidden(true);
p->mutable_palette(1)->set_hidden(true);
p->mutable_palette(2)->set_hidden(false);
p->mutable_palette(3)->set_hidden(false);
p->mutable_palette(4)->set_hidden(false);
p->mutable_palette(5)->set_hidden(false);
p->mutable_palette(6)->set_hidden(false);
p->mutable_palette(7)->set_hidden(false);
ri->mutable_map(0)->mutable_objtable(0)->set_address(0xbb80);
ri->mutable_map(1)->mutable_objtable(0)->set_address(0xbc00);
ri->mutable_map(2)->mutable_objtable(0)->set_address(0xbc80);
ri->mutable_map(3)->mutable_objtable(0)->set_address(0xbc00);
*ri->mutable_map(0)->mutable_palette() = p->palette(2).address();
*ri->mutable_map(1)->mutable_palette() = p->palette(4).address();
*ri->mutable_map(2)->mutable_palette() = p->palette(6).address();
*ri->mutable_map(3)->mutable_palette() = p->palette(4).address();

int size = 128*3;
int i;
for(i=0; i<size; i++) {
if (mapper_->ReadPrgBank(0, 0xbb80+i) != 0xff)
break;
}
if (i == size) {
for(i=0; i<0x50; i++) {
mapper_->WritePrgBank(0, 0xbb80+i, mapper_->ReadPrgBank(0, 0x87a3+i));
mapper_->WritePrgBank(0, 0xbc00+i, mapper_->ReadPrgBank(0, 0x87a3+i));
mapper_->WritePrgBank(0, 0xbc80+i, mapper_->ReadPrgBank(0, 0x87a3+i));
}
for(i=0; i<0x24; i++) {
mapper_->WritePrgBank(0, 0xbbd0+i, mapper_->ReadPrgBank(-1, 0xc458+i));
mapper_->WritePrgBank(0, 0xbc50+i, mapper_->ReadPrgBank(-1, 0xc458+i));
mapper_->WritePrgBank(0, 0xbcd0+i, mapper_->ReadPrgBank(-1, 0xc458+i));
}
}
} else {
auto *p = ri->mutable_palettes(0);
p->mutable_palette(0)->set_hidden(false);
p->mutable_palette(1)->set_hidden(false);
p->mutable_palette(2)->set_hidden(true);
p->mutable_palette(3)->set_hidden(true);
p->mutable_palette(4)->set_hidden(true);
p->mutable_palette(5)->set_hidden(true);
p->mutable_palette(6)->set_hidden(true);
p->mutable_palette(7)->set_hidden(true);
ri->mutable_map(0)->mutable_objtable(0)->set_address(0x87a3);
ri->mutable_map(1)->mutable_objtable(0)->set_address(0x87a3);
ri->mutable_map(2)->mutable_objtable(0)->set_address(0x87a3);
ri->mutable_map(3)->mutable_objtable(0)->set_address(0x87a3);
*ri->mutable_map(0)->mutable_palette() = p->palette(0).address();
*ri->mutable_map(1)->mutable_palette() = p->palette(0).address();
*ri->mutable_map(2)->mutable_palette() = p->palette(0).address();
*ri->mutable_map(3)->mutable_palette() = p->palette(0).address();
}
}

template<class GETALL>
int MiscellaneousHacks::EnabledIndex(GETALL getall) {
int index = 0;
for(const auto& hack: getall()) {
if (MemcmpHack(hack.hack(0))) {
return index;
}
index++;
}
// If we couldn't identify the hack, return -1
return -1;
}


template<class GETALL, class GET>
int MiscellaneousHacks::Hack(const char* hackname, int n,
Expand All @@ -213,6 +290,9 @@ int MiscellaneousHacks::Hack(const char* hackname, int n,
ImGui::PushItemWidth(400);
if (ImGui::Combo(hackname, &method, names, len)) {
PutGameHack(get(method));
CheckConfig();
ImApp::Get()->ProcessMessage("overworld_tile_hack",
reinterpret_cast<void*>(-1));
}
ImGui::PopItemWidth();
return method;
Expand Down
Loading

0 comments on commit e4a018d

Please sign in to comment.