Home › Forums › Destiny of an Emperor › Destiny of an Emperor RH Guide ( MOVED! to http://doaerhguide.wikidot.com )
Tagged: Battles, Destiny of an Editor, Destiny of an Emperor, Destiny of an Emperor hacking, Destiny of an Emperor Mods, Destiny of an Emperor Rom, DoaE rom, DoaE Rom hacking, FCEUX, Feidian, Graphics, hacking DoaE, Map, NES ROM hacking, nes8 template, Portraits, ROM Hacking, ROM hacking information
- This topic has 985 replies, 17 voices, and was last updated 2 years, 9 months ago by
MiDKnighT.
-
AuthorPosts
-
November 8, 2011 at 4:03 am #39790
MiDKnighT
ModeratorI thought I had switched to the new ROM pages before. Are you sure you're switching to the right page?
The pages are:
Hex Page Hex Address
0 10
1 4010
2 8010
3 C010
4 10010
5 14010
6 18010
7 1C010
8 20010
9 24010
A 28010
B 2C010
C 30010
D 34010
E 38010
F 3C010
10 40010
11 44010
12 48010
13 4C010
14 50010
15 54010
16 58010
17 5C010
18 60010
19 64010
1A 68010
1B 6C010
1C 70010
1D 74010
1E 78010
1F 7C010
I'll have to test it later.
November 8, 2011 at 4:26 am #39791ludmeister
ParticipantMiDKnighT–
Yeah, I was switching to the right page… I just don't think that the NES memory was holding. I did manage to get page switching to work by using page 1C as a launchpad to get at page 0B… which has a fair amount of free space open. Seemed to be a nasty hack, but it gets the job done. So far I haven't written any new code beyond the page switching, but I've given myself about 240 bytes of space to play around with. :P
Thanks though, you don't have take your time working with the page switching, it's not urgent.
When all else fails... manipulate the source code.
November 8, 2011 at 2:16 pm #39792MiDKnighT
ModeratorQuote:When you page switch in ROM, how do you get the RAM from $2000 to $7fff to stay in memory? My page switching works… but it totally wipes out the memory I'm trying to work with.OK I just tested it and see what you mean. The memory at $0000-$1FFF stays but $2000 to $7fff gets zapped. Comparing:
Good Page Switch:
00:BFE0:A9 0C LDA #$0C
00:BFE2:20 82 C4 JSR $C482
00:C482:85 44 STA $0044 = #$0C
00:C484:85 ED STA $00ED = #$0C
00:C486:A9 01 LDA #$01
00:C488:85 EB STA $00EB = #$01
00:C48A:A5 ED LDA $00ED = #$0C
00:C48C:20 B7 C4 JSR $C4B7
00:C4B7:8D F9 FF STA $FFF9 = #$AC A=0C X=35 Y=00
00:C4BA:4A LSR
00:C4BB:8D F9 FF STA $FFF9 = #$AC A=06 X=35 Y=00
00:C4BE:4A LSR
00:C4BF:8D F9 FF STA $FFF9 = #$AC A=03 X=35 Y=00
00:C4C2:4A LSR
00:C4C3:8D F9 FF STA $FFF9 = #$AC A=01 X=35 Y=00
00:C4C6:4A LSR
00:C4C7:8D F9 FF STA $FFF9 = #$AC A=00 X=35 Y=00
00:C4CA:60 RTS
00:C48F:A5 EB LDA $00EB = #$01
00:C491:D0 06 BNE $C499
00:C493:20 60 C4 JSR $C460
00:C496:4C 86 C4 JMP $C486
00:C499:A9 00 LDA #$00
00:C49B:85 EB STA $00EB = #$00
00:C49D:60 RTS
Bad Page Switch:
00:BFE0:A9 1E LDA #$1E
00:BFE2:20 82 C4 JSR $C482
00:C482:85 44 STA $0044 = #$1E
00:C484:85 ED STA $00ED = #$1E
00:C486:A9 01 LDA #$01
00:C488:85 EB STA $00EB = #$01
00:C48A:A5 ED LDA $00ED = #$1E
00:C48C:20 B7 C4 JSR $C4B7
00:C4B7:8D F9 FF STA $FFF9 = #$AC A=1E X=35 Y=00
00:C4BA:4A LSR
00:C4BB:8D F9 FF STA $FFF9 = #$AC A=0F X=35 Y=00
00:C4BE:4A LSR
00:C4BF:8D F9 FF STA $FFF9 = #$AC A=07 X=35 Y=00
00:C4C2:4A LSR
00:C4C3:8D F9 FF STA $FFF9 = #$AC A=03 X=35 Y=00
00:C4C6:4A LSR
00:C4C7:8D F9 FF STA $FFF9 = #$AC A=01 X=35 Y=00
00:C4CA:60 RTS
00:C48F:A5 EB LDA $00EB = #$01
00:C491:D0 06 BNE $C499
00:C493:20 60 C4 JSR $C460
00:C496:4C 86 C4 JMP $C486
00:C499:A9 00 LDA #$00
00:C49B:85 EB STA $00EB = #$00
00:C49D:60 RTS
My guess is that the JSR $C4B7 subroutine needs another round to get down to 0. Perhaps a loop is in order…
EDIT: I tried a loop which *should* work:
00:C4B7:8D F9 FF STA $FFF9 = #$AC
00:C4BA:4A LSR
00:C4BB:8D F9 FF STA $FFF9 = #$AC
00:C4BE:D0 FA BNE $C4BA
00:C4C0:60 RTS
but it broke the game something fierce… 8O Back to the drawing board… Maybe we need our own page switch subroutine stored in memory somewhere for switching to expanded ROM pages.
November 8, 2011 at 6:03 pm #39793ludmeister
ParticipantQuote:Maybe we need our own page switch subroutine stored in memory somewhere for switching to expanded ROM pages.Yuck! But that theory about needing an extra round of…
00:C4C6:4A LSR
00:C4C7:8D F9 FF STA $FFF9 = #$AC A=01 X=35 Y=00
… seems to make sense to me. If only we could squeeze 4 more bytes in there to test the theory…
When all else fails... manipulate the source code.
November 8, 2011 at 6:29 pm #39794MiDKnighT
ModeratorWell, I know why my loop wasn't working now. Every page switch requires at least 4 passes through:
00:C4C6:4A LSR
00:C4C7:8D F9 FF STA $FFF9 = #$AC A=01 X=35 Y=00
Lowered numbered page numbers were hitting 0 before the 4 passes were up which is why my loop broke. Not sure how many times we'd need to do it for new pages…5? 6? 8? won't work at all? Dunno… Something to play with…
November 8, 2011 at 6:41 pm #39795MiDKnighT
ModeratorOh sweet, Meteorstrike wrote about this function here –> http://faqs.ign.com/articles/974/974431p1.html
Quote:IV. C – Helper Function – Function $C4B7
This function seems to do nothing for us, but upon further analysis through a
debugger, we can see that this function is, in part, responsible for doing a ROM
page swap. Essentially, the caller of this function will want to access a
specific ROM page that is not currently loaded into ($8000 -> $FFFF). This
function, in combination with some other ones we will soon analyze, will load a
specific ROM page into memory, so we can access the data we want.
For purposes of this FAQ, this code is irrelevant, but we still want to analyze
what it's doing, since we need to know exactly what memory these functions
manipulate if we are to fully understand what the caller function is doing.
// Function $C4B7
// Start Address = $C4B7
// End Address = $C4CA
// Input = [A]
// Output = [A]
// Summary:
// Return (A = A / 16)
00:C4B7:8D F9 FF STA $FFF9
00:C4BA:4A LSR
00:C4BB:8D F9 FF STA $FFF9
00:C4BE:4A LSR
00:C4BF:8D F9 FF STA $FFF9
00:C4C2:4A LSR
00:C4C3:8D F9 FF STA $FFF9
00:C4C6:4A LSR
00:C4C7:8D F9 FF STA $FFF9
00:C4CA:60 RTS
Again, for purposes of this FAQ, the only thing this accomplishes is to reduce
the Accumulator Register to (A / 16) as described in the summary.
A/16 eh? Do we need A/32?
November 8, 2011 at 6:41 pm #39796ludmeister
ParticipantAs long as we have a 512K ROM– that is, pages through 1F, we'd only need 5 passes (divide by 32). In the remote chance that we'd expand the ROM size to 1024K, we'd have pages through 3F, and that would require 6 passes (divide by 64).
We might be able to implement a loop in place of the LSRs and STAs, with a counter counting from 4 down past zero, to shift right 5 times… if we can determine that what is in register X or Y is an arbitrary value. What do you think about this?
When all else fails... manipulate the source code.
November 8, 2011 at 6:45 pm #39797MiDKnighT
ModeratorQuote:We might be able to implement a loop in place of the LSRs and STAs, with a counter counting from 4 down past zero, to shift right 5 times… if we can determine that what is in register X or Y is an arbitrary value. What do you think about this?I thought about that too. First problem is space. I'm having trouble fitting what I need in C4B7-C4CA. X and Y may be important as they are holding stuff when a page switch is called.
November 8, 2011 at 6:46 pm #39798MiDKnighT
ModeratorI'm going to attempt 8 passes via a loop and see what happens.
EDIT: Oh wait, I see your point now. 5 passes would give us 1/32.
November 8, 2011 at 6:47 pm #39799ludmeister
ParticipantAlternately… why is it storing the Accumulator in $FFF9 between shifts? It seems majorly over-redundant-muchly. Could we commandeer three of those bytes, and Shift as many times as we need (NOP'ing the rest)? That would seem to be the path of least resistance… if it works.
When all else fails... manipulate the source code.
November 8, 2011 at 6:55 pm #39800MiDKnighT
ModeratorQuote:Alternately… why is it storing the Accumulator in $FFF9 between shifts? It seems majorly over-redundant-muchly.I think this is the meat of page switching. From my testing so far it MUST store the accumulator in $FFF9 each time as it is page switching. Notice in the trace output above that $FFF9 keeps getting reset back to #$AC. I think this is the emulator swapping pages.
So in theory any normal game page requires 4 passes, any new page requires 5 passes. Sounds like a CMP is in order…
EDIT: Aggg…space is so tight to try to work with this…
November 8, 2011 at 7:38 pm #39801ludmeister
ParticipantAs an aside, MiDKnight… are you aware of anything that might be affected by putting code in the space 0x2f210 to 0x2f30f? This is where I'm putting the heavy-lifting for my Agility-based multi-striking code.
I have it written (at least, a first stab), but can't modify my ROM until I get home… I'm at work and all that :wink:
When all else fails... manipulate the source code.
November 8, 2011 at 7:42 pm #39802MiDKnighT
ModeratorNope I'm not aware of anything. Trial and error to make sure you don't break something I guess…
I've got an idea on the C4B7 thing…
00:C4B7:86 BF STX $00BF = #$02
00:C4B9:A2 05 LDX #$05
00:C4BB:8D F9 FF STA $FFF9 = #$AC
00:C4BE:4A LSR
00:C4BF:CA DEX
00:C4C0:E0 00 CPX #$00
00:C4C2:D0 F7 BNE $C4BB
00:C4C4:D0 F5 BNE $C4BB
00:C4C6:A6 BF LDX $00 = #$02
00:C4C8:60 RTS
Basically it's looping 4 times then going a 5th time if the accumulator is still not 0. The game runs fine with this in place but haven't tried switching to a higher page yet.
November 8, 2011 at 9:52 pm #39803sonic.penguin
ModeratorWatching you guys go through this stuff is like watching a unicorn eating an icecream cone while doing the hula. It's mesmerizing… :nod:
November 8, 2011 at 10:25 pm #39804MiDKnighT
ModeratorDoing the 5 time 1/32 thing did not work for keeping the memory on a page switch. I'm thinking it has to do with the ROM format which is MMC1. I'm surprised that the portraits and sprites work ok with this memory thing. Hopefully we can use the additional ROM pages for more than just portraits and sprites…
I'm going to try and expand the original destiny rom using this utility (NFlate) to see if it has the same problem:
http://www.romhacking.net/utilities/425/
EDIT: Didn't work with that either.
Time to read up…
http://tuxnes.sourceforge.net/mappers-0.80.txt
http://wiki.nesdev.com/w/index.php/MMC1
http://www.romhacking.net/forum/index.php?topic=11884.0
-
AuthorPosts
- You must be logged in to reply to this topic.

