Romhacking.net

Romhacking => Programming => Topic started by: umaggot on January 04, 2009, 01:50:09 pm

Title: Faxanadu - Assembly
Post by: umaggot on January 04, 2009, 01:50:09 pm
Allow me to preface this by stating that I'm relatively new to assembly, but I've had much success so far. I'm a little embarrassed to be posting this script, as sloppy and inefficient as it is, but I feel at a loss here -- for something that is seemingly very simple. I've been wondering about SubRoutines and JuMPing, and how they may be affecting the code overall. I've rerouted the script from the "use item" segment to an unused area (to add new/unused items) and here's what I have:

LDY $03C1 = #$15 ;Loads the item hex
AND #$11 ;Checks if the item hex is 11 (Is the item a Brown Potion?)
BNE $FCF9 ;If it isn't 11, it branches to the original item use script (Which has been moved)
BRK ;Giving myself free space.
BRK ;Twice. I don't remember why I did this.
JSR $FCED ;Jump to SubRoutine -- Brown Potion used text.
JSR $C8DC ;Removes item picture.
JSR $C4BF ;Removes item.
JMP $C506 ;MP recovery.
RTS ;ReTurn from Subroutine -- back to the original code.


Using any item from Wing Boots, to the Brown Potion is fine -- but items without a script (or with new scripts) beyond the value $11, proceed to use the Brown Potion script. I've confirmed this by corrupting the area where the new scripts point to and pointing the Brown Potion script to that, instead of the original item use script. It refuses to read the new data at all, and simply proceeds beyond the BNE line. This also confirms that the original item use script as I've moved it, isn't the problem -- it's definitely the script that I've posted here.

If you need additional information, feel free to ask. I look forward to and will appreciate any and all assistance with the matter.

I hope that this doesn't belong in "Script Help and Language Discussion Rules", I hope that you'll forgive me if I've posted this in the wrong area. Both boards seem to be "the right board", but as far as I can tell, the other one is mostly for translation help?
Title: Re: Faxanadu - Assembly
Post by: Disch on January 04, 2009, 02:01:23 pm
1)  AND does not do what you might be thinking it does.  It's for bitmasking -- turning off specific bits, and/or isolating bits you're interested in.  It is not for comparing full values.  For that you probably want CMP.

2)  Don't use BRK!  If you just want to fill blank space, use NOP (opcode $EA).  BRK forces an interrupt and is very dangerous unless you know what you're doing.  I'm surprised your game hasn't been crashing -- faxanadu must have an empty IRQ routine.

3)  You're using LDY to load the item index -- but AND (and CMP) both work with A, not Y.  Switch that to LDA and use CMP -- or if you need it to be in Y (like for one of the later JSRs), then use LDY and CPY (CPY = same as CMP, but uses Y instead of A)


To clarify CMP/CPX/CPY for you....

CMP simply compares the value in A with the given value (we'll call it 'm'), and sets Z and C flags appropriately.  You can then check Z (with BNE/BEQ) or C (with BCC/BCS) to jump to different areas depending on the outcome of the CMP.

if Z is set, then A=M
if C is clear, then A<M
if Z is clear, then A != M
if C is set, then A >= M

so....

Code: [Select]
LDA $03C1    ; item index
CMP #$11     ; compare to $11
BEQ index_is_11
BCC index_is_less_than_11
BCS index_is_greater_than_11

CPX and CPY are exactly the same, but with X and Y instead of A
Title: Re: Faxanadu - Assembly
Post by: umaggot on January 04, 2009, 02:26:49 pm
Oh, thank you very much! This is very helpful to know, as the information that I've been following is entirely in technobabble. Would it be alright with you if I credited you in-game for your assistance?

I believe that it should be CPY, as the game pointed out "LDY $03C1 = #$15", which was myself checking an item that was beyond $11 via cheats. When the debugger shows me this value, it's showing me the specific variable of bit "Y" in the RAM at $03C1 as-is at that point in time, correct? I'm not really sure what the difference is between A, Y and X, but I've assumed that these are all their own specific bit-values, their own labels for the relative address(es) -- am I correct?

// Wow, alright. That makes sense! I understand BEQ, but I'm positive that I want it to BNE -- I'll modify this post if I have any problems. It's definately not CPY as I'd thought, so I'll attempt your code.

// That worked! The Brown Potion code is flawless now, thanks again!
Title: Re: Faxanadu - Assembly
Post by: Disch on January 04, 2009, 02:43:44 pm
Oh, thank you very much! This is very helpful to know, as the information that I've been following is entirely in technobabble. Would it be alright with you if I credited you in-game for your assistance?

It wouldn't bother me, no.  But it does seem rather unnecessary.


Quote
I believe that it should be CPY, as the game pointed out "LDY $03C1 = #$15"

Yeah -- if you're using LDY, then you want CPY.

Quote
When the debugger shows me this value, it's showing me the specific variable of bit "Y" in the RAM at $03C1 as-is at that point in time, correct?

Your terminology is a little funky here.  Not like it matters but I'm bored so here's some random ramblings:

- $03C1 is an address
- each address houses one 'byte' of information
- a byte can be any number between $00-$FF
- there are 8 'bits' in a byte
- bits are binary (bit = "binary digit") so each bit can only be either 0 or 1
- A, X, and Y are 'registers', which is just a fancy word meaning they're variables
- A, X, and Y are also one byte in size

Anyway to really answer your question... when it says "LDY $03C1 = #$15", then that means that, at the time the debugger was snapped, the byte at address $03C1 was $15.  It tells you absolutely nothing about the contents of Y (but for that you can look elsewhere in the debugger).

Quote
I'm not really sure what the difference is between A, Y and X, but I've assumed that these are all their own specific bit-values, their own labels for the relative address(es) -- am I correct?

A, X, and Y do not have an address.  And they're all exactly the same.  They're just variables... all they do is hold a number.  The only thing that really makes them different is how they can be used by instructions.  ADC, for example, can only add to A, not to X or Y.  DEX/DEY work with X and Y, but not with A.  You can use X and Y for indexing (LDA $0123,X   STA $0234,Y), but you can't use A for indexing.


EDIT-

Glad to hear you got it working.  :thumbsup:
Title: Re: Faxanadu - Assembly
Post by: creaothceann on January 04, 2009, 03:03:55 pm
If it helps - these 'variables' are small RAM cells in the processor.
Title: Re: Faxanadu - Assembly
Post by: umaggot on January 04, 2009, 03:17:08 pm
Awesome! Thank you for correcting me! I'll keep all of this information in mind, as I definately don't want to spout incorrect information while I blog and record my progress. ;) I'll make sure to keep to this topic incase I have any future inquiries, but I should be good for quite some time now. :)
Title: Re: Faxanadu - Assembly
Post by: umaggot on June 19, 2011, 01:44:10 am
I asked on IRC about necroposting, and I believe I have a good enough reason to, so here goes:

It's me again, it's been a long time. I was wondering if there is a more efficient way to write my code?

Code: [Select]
New code at the bottom of the message.
This code was embarrassing; I realized how many flaws it had on my own.

I already know some things; like if I changed CPX #$FF to #$00, and got rid of the duplicate code, that would reduce the space it takes up. I assume that X only goes up to FF, and the reason that I even bothered putting in a TAY is because I thought somehow, the Y register would help; I could probably get rid of that and just LDA #$00 TAX, which would still take up the same amount of bytes. There's probably an easier way, right? Ultimately, I just want it to load $0390-058F (Though data in $058F is unnecessary) to A and store it to $6000-61FF. The code works, but is too long and I believe it overwrites something important because of its length; I can see through the character's chest when he's climbing ladders, while wearing Studded Mail. (Could that be PPU related?)

This is an older code I've had saved in notepad, by the way; the current version JSRs to load item text, saying "GAME SAVED" instead of printing a mantra.

// Here's what I have so far, new code.

Code: [Select]
A9 00     LDA #$00
AA        TAX
BD 90 03  LDA $0390,X @ $0390 = #$00
9D 00 60  STA $6000,X @ $6000 = #$00
E8        INX
E0 00     CPX #$00
D0 F5     BNE (LDA $0390,X)
BD 90 04  LDA $0490,X @ $0490 = #$00
9D 00 61  STA $6100,X @ $6100 = #$00
E8        INX
E0 00     CPX #$00
D0 F5     BNE (LDA $0490,X)
A9 5E     LDA #$5E ;Item message ID "GAME SAVED"
20 0E 8C  JSR $8C0E ;Display item message
60        RTS

I feel foolish for using so many unnecessary register transfers. Even still, though, I wonder if there was a shorter way to write this.
Title: Re: Faxanadu - Assembly
Post by: snarfblam on June 19, 2011, 10:19:43 am
It would definitely help to have some easy-to-use reference (http://www.obelisk.demon.co.uk/6502/reference.html), so you can look at the details of a particular instruction, or even look over the document to familiarize yourself with the instruction set.

Code: [Select]
A9 00     LDA #$00
AA        TAX
You can load directly to any of the registers (not all addressing modes are available for all registers). So you could change this to
Code: [Select]
LDX #$00



Code: [Select]
E8        INX
E0 00     CPX #$00
D0 F5     BNE (LDA $0390,X)
Another thing to be aware of is that when an instruction modifies a register, it also modifies the processor status flags, which often means you can skip the compare instruction.

The compare instructions (CMP, CPX, CPY) work by setting processor status flags, and the branch instructions branch only if the appropriate processor status flag is set. CPX sets the Z (zero) flag to indicate equal or clears the Z flag to indicate not-equal. BEQ and BNE branch based on the value of the Z flag (BEQ branches if Z is set, BNE branches if Z is clear).

The thing is, INX also affects the Z flag. If INX causes X to be zero, the Z flag is set, and if INX causes X to be non-zero, the Z flag is cleared. So you don't need to compare to zero. The Z flag already tells you whether X is zero, which means you can skip the CPX instruction all together.
Code: [Select]
; In this case you can think if BEQ as "branch if zero" and BNE as "branch if non-zero"
INX
BNE branchTaregt



Another thing I see: you can "interleave" your copy routine. In other words, you can copy more than one byte in the same loop, which means you don't need two loops. This can make some loops trickier or harder to change down the road if you ever need to (i.e. it's less "maintainable"), but in this case it might be a good idea.
Code: [Select]
A9 00     LDA #$00
AA        TAX
BD 90 03  LDA $0390,X @ $0390 = #$00
9D 00 60  STA $6000,X @ $6000 = #$00
E8        INX
E0 00     CPX #$00
D0 F5     BNE (LDA $0390,X)
BD 90 04  LDA $0490,X @ $0490 = #$00
9D 00 61  STA $6100,X @ $6100 = #$00
E8        INX
E0 00     CPX #$00
D0 F5     BNE (LDA $0490,X)
Would become
Code: [Select]
    LDA #$00
    TAX
LoopTop:
    LDA $0390,X  ; Copy byte from first block
    STA $6000,X
    LDA $0490,X  ; Copy byte from second block
    STA $6100,X
    INX
    CPX #$00
    BNE LoopTop



One last thing:
Code: [Select]
20 0E 8C  JSR $8C0E ;Display item message
60        RTS
There's a trick you can use here. Any time you have a JSR that is immediately followed by an RTS, you can change the JSR to a JMP and get rid of the RTS. The result will still be the same. This is called a tail call (http://en.wikipedia.org/wiki/Tail_call).  It works because when you call a subroutine with JMP, the RTS at the end of that subroutine causes the processor to return from your routine.



I'll leave it up to you to put it all together. With all those things combined, you could reduce this routine from 15 instructions to 9.
Title: Re: Faxanadu - Assembly
Post by: umaggot on June 19, 2011, 10:59:58 am
Oh wow, that is a lot of help! Yeah, I caught on to how my instructions were pointless at times eventually; considering the LDA after the TAX was just going to change A anyway, the first LDA was a complete waste! As for JMP, that makes sense! I've been using 6502.org - Opcodes as a reference, but I never honestly understood a decent chunk of it. It did help, but I sometimes need a little more English and a little less machine. So what you're saying, is that the zero flag applies to A, X, and Y -- and not just A? Yeah, that resource you've linked confirms it! Hey, thanks for the help, I'll keep this in mind!

As fascinated as I was to learn so many neat tricks, I've come to feel even more foolish; the bug that makes his chest disappear probably has to do with *what* I'm loading. I'm saving and loading PPU instructions as well. It just hit me like a ton of bricks while I was trying to rule out the cause. I looked at the SRAM and that's when it hit me. I'll work on altering the load code first, so that it doesn't load carelessly. I'm kindof surprised that the PPU is really affected so much by it, considering how often that it changes.

If it somehow isn't fixed after that, then I won't really know what to do.

// Being more specific has naturally lead me to writing a longer load code. Now the game insists on crashing -- so I either overwrote something important, or I did the math wrong on the specified addresses. I've condensed it as much as I could according to your quidelines, but I probably have to find another way. I'm too exhausted to finish up right now, I've been losing sleep on this project. I'll be back and hopefully can report some good news later on.

// Well, then. I think I just figured out what the culprit is. It's either an error in the dump, or a bug that was corrected for the US/EU release. I've spent way too long trying to figure that out!
Title: Re: Faxanadu - Assembly
Post by: umaggot on June 28, 2011, 04:56:43 am
So to bring you up to speed, I'm working on an SRAM hack. It's mostly done, but there's a 15-second delay (ouch!) after the game is saved, and the save icon is written over with a garbled Japanese character. I've been trying to use the cheat feature to figure out if it can somehow be fixed by writing to a relevant address in the RAM, but I'm not getting any bites. I've also been using the debugger to step through the code, but it just goes in a big circle and would take a painfully long time to step through until I'd actually find what's causing the icon to be written over. So just for the sake of curiousity, is there an easier way? I've also looked through SP's disassembly and have tried experimenting with the most relevant bytes that I've seen, but I'm not getting any hits.

// If it helps, I set a break point for $61FF -- and it seems that the cursor blinks AND the game saves repeatedly, during all of those 15 seconds. In reality, it only needs to save once.

July 03, 2011, 01:13:46 am - (Auto Merged - Double Posts are not allowed before 7 days.)
The Faxanadu SRAM (J) Open Beta (http://umaggot.webs.com/preview/Faxanadu%20SRAM%20(J).ips) patch is here!

This patch is for the Japanese version only. It will NOT work on the US/EU versions. This patch will allow you to save the game, when you would've otherwise received a mantra.

If you find any bugs or glitches, *please* let me know! Thank you!

I've already played through it twice, and I've noticed that an armor is replaced at some point in Branch. If I had to take a solid guess, it'll have something to do with obtaining the Battle Suit. I haven't yet tested to see whether or not this is just a bug in my copy of Faxanadu (J), but I am aware that my copy has a bug that prevents a part of the Studded Mail from appearing while climbing a ladder.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 04, 2015, 04:37:24 am
Hi, sorry for waking a topic from the dead, but I would looooooooooooooooove a SRAM version of Faxanadu (US). I've started looking into umaggot's SRAM hack, but I'm still too much of a noob to understand how to re-use his work.

I thought that I could try to implement a save-to-sram-every-clockcycle-routine, just to see if I can save the amount of gold.

Can someone give me some pointers, I would to learn more. And yes I've been checking 6502.org as well  ;)
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 04, 2015, 09:34:28 am
Hey there, frsj8112. (and everyone) I'm sorry I've been out of the game for so long. My website is currently down (presumably due to inactivity), but I'll be restoring it at some point. I haven't worked on this in ages, but I have every intent of finishing my work and releasing both a retranslation, and a normal "US" version with SRAM and all of my bugfixes (which includes anything that needed fixing as mentioned in this topic -- all of those bugs have been addressed since). I'm sorry for the wait.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 04, 2015, 09:52:49 am
Awesome umaggot!!

I'd really love to see SRAM functionality in the US version, have you hacked that ROM too?  :angel:
Title: Re: Faxanadu - Assembly
Post by: 90s Retro Gamer on April 04, 2015, 11:57:06 am
Allow me to preface this by stating that I'm relatively new to assembly, but I've had much success so far. I'm a little embarrassed to be posting this script, as sloppy and inefficient as it is, but I feel at a loss here -- for something that is seemingly very simple. I've been wondering about SubRoutines and JuMPing, and how they may be affecting the code overall. I've rerouted the script from the "use item" segment to an unused area (to add new/unused items) and here's what I have:

LDY $03C1 = #$15 ;Loads the item hex
AND #$11 ;Checks if the item hex is 11 (Is the item a Brown Potion?)
BNE $FCF9 ;If it isn't 11, it branches to the original item use script (Which has been moved)
BRK ;Giving myself free space.
BRK ;Twice. I don't remember why I did this.
JSR $FCED ;Jump to SubRoutine -- Brown Potion used text.
JSR $C8DC ;Removes item picture.
JSR $C4BF ;Removes item.
JMP $C506 ;MP recovery.
RTS ;ReTurn from Subroutine -- back to the original code.


Using any item from Wing Boots, to the Brown Potion is fine -- but items without a script (or with new scripts) beyond the value $11, proceed to use the Brown Potion script. I've confirmed this by corrupting the area where the new scripts point to and pointing the Brown Potion script to that, instead of the original item use script. It refuses to read the new data at all, and simply proceeds beyond the BNE line. This also confirms that the original item use script as I've moved it, isn't the problem -- it's definitely the script that I've posted here.

If you need additional information, feel free to ask. I look forward to and will appreciate any and all assistance with the matter.

I hope that this doesn't belong in "Script Help and Language Discussion Rules", I hope that you'll forgive me if I've posted this in the wrong area. Both boards seem to be "the right board", but as far as I can tell, the other one is mostly for translation help?

Umaggot, see if you can find the line of code with the Pendant bug. The Pendant item is supposed to increase your strength but instead it decreases it.

Someone made a hack fixing this issue.
http://www.romhacking.net/hacks/753/

You can disassemble the patched ROM and compare your assembly with this one.
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 04, 2015, 07:09:53 pm
Quote
I'd really love to see SRAM functionality in the US version, have you hacked that ROM too?

I could probably make a US patch by using the US version as a base when creating a patch from the JP version. There would be a bit of the original code copied over, as well.

Quote
Umaggot, see if you can find the line of code with the Pendant bug. The Pendant item is supposed to increase your strength but instead it decreases it.

Someone made a hack fixing this issue.

That someone was I, and it has been already fixed for the Retranslation and general bugfix patches. :) In addition, there were a few armor and shield bugs (items being replaced because the game was checking for amount of shields instead of armor, AND vice-versa! ...also swords!) that I've ironed out.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 06, 2015, 02:36:48 am
OK I've made "some" progress with the US rom.

I've implemented umaggots LOAD Routine in the US rom approximatly where the "Mantra is in the wrong" text is located.
Then I managed to find a JSR which is activated when A or B is pressed down.
I then JSR:ed to umaggot's LOAD-routine and then the data from my copied .sav-file is transfered to $0390 etc. So that does work :-)

But then the game crashes and won't boot up to the game.
umaggots check for if the .sav-file is empty and if so, jump back to the title screen does in fact work.

Title: Re: Faxanadu - Assembly
Post by: umaggot on April 06, 2015, 07:29:56 am
It's checking for 4 bytes, identified as name data. The US version doesn't allow you to create name data, so it fails the SRAM check.

// Except... you copied the .sav from the JP version? ... I have no idea.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 06, 2015, 07:31:01 am
OK, what can be done to go around that? :-)
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 06, 2015, 07:44:24 am
I believe the check is in the first 4 bytes of SRAM. Look for a line scanning the area, and disable the branch. It's looking for 00 bytes, so we're possibly looking for BEQ. Change the BEQ:XX bytes to NOP.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 06, 2015, 08:17:27 am
Yes I used the sav-file that was generated by saving-in-game with your hack.

Here's the rom with your hack implemented and with an empty .sav-file

https://youtu.be/3YnPN85az5Q

And here it is with a non-empty .sav (generated from the japanese version)

https://youtu.be/2ZbM82CKCH8
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 06, 2015, 09:13:00 am
What I see is that it indeed is loading data, however, certain addresses between the US and JP version are different, so it's trying to branch/jmp/jsr to JP code instead of US code. Look for the death/respawn routine, and look for a jmp or jsr from the end of my load routine. Modify the address to match the US respawn routine.

// Alternatively, look for the end of the US password successful checksum routine.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 06, 2015, 09:54:06 am
Your routine ends with JMP 8271 and that routine seems to be the same in both us and jap versions.

I think i need to check that checksum-routine. Any ideas about where to start looking?
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 06, 2015, 10:26:52 am
Unmodified US version, input a valid password, make a save state. Use the trace logger, and set a breakpoint for... gold. Something, anything that would be loaded. If you have further questions, we should discuss this via e-mail or PM.

// Regarding my hack, I plan to disassemble my project and put the disassembly on my phone. I have two hours per work day (generally) between work and home (I'm pretty busy. :-X) that I can use to look at the code. I'm hoping that I can get dcc6502 running on Windows 7, but will look into dosbox if all else fails.

// SmartRENES... I'll try that.

// So far... no luck. I just want a comprehensive disassembly of my hack, showing each line in ASM (Like FCEUX), in TXT or HTML format.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 06, 2015, 11:20:59 am
yes, some success! :-)
https://youtu.be/Jjxt3FNAfZQ
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 07, 2015, 07:40:14 am
Alright, forget that foolishness. So what we have here is a crash. If you talk to the smoker in Eolis, he says "It looks like the end is near."

Here's the interesting part: A normal RTS opcode will send the game to crash, by making it read 00:1100 (from 0F:F44D). I'm guessing this may have something to do with the stack. I'm also guessing that the stack can be thrown off by things like an uneven amount of PLA/PHA opcodes being run in a row. If I'm missing something important in my observations, please let me know. :-[

// Also, as of 2-10-2014 (with the latest update being 2-11-2014), here are most of the dialogue routines across banks 0F, 0C, and 10:

Spoiler:
10:BECB JMP Dialogue Routine
10:BECB:EA EA EA NOP
10:BECE:4C 8D BF JMP $BF8D ; JuMP to Dialogue Routine at 10:BF8D
10:BED1:AD 15 02 LDA $0215 = #$04 ; LoaD Page End Countdown to A
10:BED4:F0 2A BEQ $BF00 ; If equal to #$00, branch to PLB Checks at 0F:BF00
10:BED6:60 RTS -----------------------------------------
10:BED7 Page Post
10:BED7:98 TYA ; Transfer Y to A
10:BED8:E9 1F SBC #$1F ; SuBtract #$1F and Carry Flag from A
10:BEDA:8D 16 02 STA $0216 = #$02 ; STore A to Letter Position
10:BEDD:D0 11 BNE $BEF0 ; Branch if Not Equal to #$00, to Skip PLB at 10:BEF0
10:BEDF:AD 17 02 LDA $0217 = #$00 ; LoaD Line Position to A
10:BEE2:C9 04 CMP #$04 ; Is Line Position #$04?
10:BEE4:90 0A BCC $BEF0 ; If less than #$04, branch to Skip PLB at 10:BEF0
10:BEE6:AD 15 02 LDA $0215 = #$04 ; LoaD Page End Countdown to A
10:BEE9:F0 05 BEQ $BEF0 ; If equal to #$00, branch to Skip PLB at 10:BEF0
10:BEEB:EA EA NOP
10:BEED:20 88 F6 JSR $F688 ; Jump to SubRoutine Page Line Break at 0F:F688
10:BEF0 Skip PLB
10:BEF0:AC 16 02 LDY $0216 = #$02 ; LoaD Letter Position to Y
10:BEF3:98 TYA ; Transfer Y to A
10:BEF4:4C C7 BF JMP $BFC7 ; JuMP to Increase Line Position at 10:BFC7
10:BEF7:20 88 F6 JSR $F688 ; Jump to SubRoutine Page Line Break at 0F:F688
10:BEFA:20 6E F5 JSR $F56E ; Jump to SubRoutine Print Character at 0F:F56E
10:BEFD:4C 45 BF JMP $BF45 ; JuMP to Begin CC Check
10:BF00 PLB Checks
10:BF00:B1 EC LDA ($EC),Y @ $8633 = #$11 ; Load Current Letter to A at $EC+$0214 or $0216
10:BF02:C9 FA CMP #$FA ; Is Current Letter #$FA?
10:BF04:90 05 BCC $BF0B ; If less than #$FA, branch to Begin RC Check at 10:BF0B
10:BF06:E6 EC INC $00EC = #$80 ; INCrease $00EC by #$01
10:BF08:EE 14 02 INC $0214 = #$B4 ; INCrease $0214 by #$01
10:BF0B Begin RC Check
10:BF0B:A2 00 LDX #$00 ; LoaD #$00 to X
10:BF0D Remaining Characters Check
10:BF0D:E8 INX ; INcrease X by #$01
10:BF0E:C8 INY ; INcrease Y by #$01
10:BF0F:B1 EC LDA ($EC),Y @ $8633 = #$11 ; Load Current Letter to A at $EC+$0214 or $0216
10:BF11:C9 FF CMP #$FF ; Is Current Letter #$FF?
10:BF13:D0 F8 BNE $BF0D ; If not, branch to Remaining Characters Check at 10:BF0D
10:BF15:E0 10 CPX #$10 ; Is X #$10?
10:BF17:B0 01 BCS $BF1A ; If greater than or equal to #$10, branch to 10:BF1A
10:BF19:60 RTS -----------------------------------------
10:BF1A:CE 17 02 DEC $0217 = #$00 ; DECrease Line Position by #$01
10:BF1D:CE 17 02 DEC $0217 = #$00 ; DECrease Line Position by #$01
10:BF20:AC 16 02 LDY $0216 = #$02 ; LoaD Letter Position to Y
10:BF23:C0 02 CPY #$02 ; Is Letter Position #$02?
10:BF25:90 09 BCC $BF30 ; If less than #$02, branch to Letter Position Reset at 10:BF30
10:BF27 DELP
10:BF27:88 DEY ; DEcrease Letter Position by #$01
10:BF28:88 DEY ; DEcrease Letter Position by #$01
10:BF29:C0 02 CPY #$02 ; Is Letter Position #$02?
10:BF2B:B0 FA BCS $BF27 ; If greater than or equal to #$02, branch to DELP at 10:BF27
10:BF2D:8C 16 02 STY $0216 = #$02 ; STore Y to Letter Position
10:BF30 Letter Position Reset
10:BF30:A9 04 LDA #$04 ; LoaD #$04 to A
10:BF32:8D 15 02 STA $0215 = #$04 ; STore A to Page End Countdown
10:BF35:8D 1B 02 STA $021B = #$04 ; STore A to
10:BF38:B1 EC LDA ($EC),Y @ $8633 = #$11 ; Load Current Letter to A at $EC+$0214 or $0216
10:BF3A:20 6E F5 JSR $F56E ; Jump to SubRoutine Print Character at 0F:F56E
10:BF3D:20 88 F6 JSR $F688 ; Jump to SubRoutine Page Line Break at 0F:F688
10:BF40:70 89 BVS $BECB ; Branch on oVerflow flag Set to JMP Dialogue Routine at 10:BECB
10:BF42:4C 93 BF JMP $BF93 ; JuMP to Check PEC at 10:BF93
10:BF45 Begin CC (Character Code) Check
10:BF45:B1 EC LDA ($EC),Y @ $8633 = #$11 ; LoaD Current Letter to A at $EC+$0214 or $0216
10:BF47:C9 FA CMP #$FA ; Is Current Letter #$FA?
10:BF49:D0 14 BNE $BF5F ; If not, branch to Continue CC Check
10:BF4B:A9 00 LDA #$00 ; LoaD #$00 to A
10:BF4D:8D 15 02 STA $0215 = #$04 ; STore A to Page End Countdown
10:BF50:8D 16 02 STA $0216 = #$02 ; STore A to Letter Position
10:BF53:8D 17 02 STA $0217 = #$00 ; STore A to Line Position
10:BF56:8D 1C 02 STA $021C = #$00 ; STore A to
10:BF59:60 RTS -----------------------------------------
10:BF5A:EA EA EA NOP
10:BF5D:EA EA NOP
10:BF5F Continue CC Check
10:BF5F:C9 FF CMP #$FF ; Is Current Letter #$FF?
10:BF61:F0 7C BEQ $BFDF ; If so, branch to End Message
10:BF63:C9 FE CMP #$FE ; Is Current Letter #$FE?
10:BF65:F0 4D BEQ $BFB4 ; If so, branch to Line Break
10:BF67:C9 FD CMP #$FD ; Is Current Letter #$FD?
10:BF69:F0 3F BEQ $BFAA ; If so, branch to (Print) Space Branch
10:BF6B:C9 FC CMP #$FC ; Is Current Letter #$FC?
10:BF6D:F0 76 BEQ $BFE5 ; If so, branch to Name
10:BF6F:C9 FB CMP #$FB ; Is Current Letter #$FB?
10:BF71:F0 7B BEQ $BFEE ; If so, branch to Title
10:BF73:AE 12 02 LDX $0212 = #$01 ; LoaD $0212 to X
10:BF76:F0 07 BEQ $BF7F ; Is $0212 #$00? If so, branch to $0212=#$00
10:BF78:48 PHA ; PusH A
10:BF79:A9 01 LDA #$01 ; Load #$01 to A
10:BF7B:20 E4 D0 JSR $D0E4 ; Jump to SubRoutine $D0E4
10:BF7E:68 PLA ; PulL A
10:BF7F $0212=#$00
10:BF7F:20 32 F7 JSR $F732 ; Jump to SubRoutine $F732
10:BF82:AD 16 02 LDA $0216 = #$02 ; Load Letter Position to A
10:BF85:D0 05 BNE $BF8C ; Is Letter Position #$00? If not, branch to Resume Routine
10:BF87:AD 17 02 LDA $0217 = #$00 ; Load Line Position to A
10:BF8A:F0 01 BEQ $BF8D ; Is Line Position #$00? If so, branch to Dialogue Routine
10:BF8C Resume Routine
10:BF8C:60 RTS -----------------------------------------
10:BF8D Dialogue Routine
10:BF8D:EE 16 02 INC $0216 = #$02 ; Increase Letter Position by #$01
10:BF90:EE 16 02 INC $0216 = #$02 ; Increase Letter Position by #$01
10:BF93 Check PEC
10:BF93:AD 15 02 LDA $0215 = #$04 ; Load Page End Countdown to A
10:BF96:F0 F4 BEQ $BF8C ; Is Page End Countdown #$00? If so, branch to Resume Routine at 10:BF8C
10:BF98:AD 13 02 LDA $0213 = #$9F ; Load Message ID to A
10:BF9B:F0 EF BEQ $BF8C ; Is Message ID #$00? If so, branch to Resume Routine at 10:BF8C
10:BF9D:A9 01 LDA #$01 ; Load #$01 to A
10:BF9F:8D 12 02 STA $0212 = #$01 ; STore A to $0212
10:BFA2:20 E4 D0 JSR $D0E4 ; Jump to Dialogue SFX at 0F:D0E4
10:BFA5:A9 00 LDA #$00 ; Load #$00 to A
10:BFA7:20 25 CA JSR $CA25 ; Jump to Pause at 0F:CA25
10:BFAA (Print) Space Branch
10:BFAA:20 6E F5 JSR $F56E ; Jump to SubRoutine Print Character at 0F:F56E
10:BFAD:AD 16 02 LDA $0216 = #$02 ; LoaD Letter Position to A
10:BFB0:C9 1E CMP #$1E ; Is Letter Position #$1E?
10:BFB2:90 D9 BCC $BF8D ; If less than #$1E, branch to Dialogue Routine at 10:BF8D
10:BFB4 Line Break
10:BFB4:AC 16 02 LDY $0216 = #$02 ; Load Letter Position to Y
10:BFB7:C0 1F CPY #$1F ; Is Letter Position #$1F?
10:BFB9:B0 06 BCS $BFC1 ; If greater than or equal to #$1F, branch to Page Countdown at 10:BFC1
10:BFBB Letter Increase
10:BFBB:C8 INY ; INcrease (Y) Letter Position by #$01
10:BFBC:C8 INY ; INcrease (Y) Letter Position by #$01
10:BFBD:C0 1F CPY #$1F ; Is Letter Position #$1F?
10:BFBF:90 FA BCC $BFBB ; If less than #$1F, branch to Letter Increase at 10:BFBB
10:BFC1 Page Countdown
10:BFC1:CE 15 02 DEC $0215 = #$04 ; Decrease Page End Countdown by #$01
10:BFC4:4C D7 BE JMP $BED7 ; JuMP to Page Post at 10:BED7
10:BFC7 Increase Line Position
10:BFC7:EA EA EA NOP
10:BFCA:AD 16 02 LDA $0216 = #$02 ; LoaD Letter Position to A
10:BFCD:D0 C4 BNE $BF93 ; Is Letter Position #$00? If not, branch to Check PEC
10:BFCF:EE 17 02 INC $0217 = #$00 ; INCrease Line Position by #$01
10:BFD2:EE 17 02 INC $0217 = #$00 ; INCrease Line Position by #$01
10:BFD5:AD 17 02 LDA $0217 = #$00 ; LoaD Line Position to A
10:BFD8:C9 04 CMP #$04 ; Is Line Position #$04
10:BFDA:90 B7 BCC $BF93 ; If less than #$04, branch to Check PEC
10:BFDC:4C 85 F6 JMP $F685 ; JuMP to Bank Switch PLB at 0F:F685
10:BFDF End Message
10:BFDF:A9 00 LDA #$00 ; LoaD #$00 to A
10:BFE1:8D 13 02 STA $0213 = #$9F ; STore A to Message ID
10:BFE4:60 RTS -----------------------------------------
10:BFE5 Name
10:BFE5:AD C2 04 LDA $04C2 = #$46
10:BFE8:EE 1C 02 INC $021C = #$00
10:BFEB:4C F2 F5 JMP $F5F2
10:BFEE Title
10:BFEE:A9 81 LDA #$81
10:BFF0:8D 1C 02 STA $021C = #$00
10:BFF3:AD 37 04 LDA $0437 = #$0D
10:BFF6:0A ASL
10:BFF7:0A ASL
10:BFF8:0A ASL
10:BFF9:AA TAX
10:BFFA:BD 91 F7 LDA $F791,X @ $F7A1 = #$1B
10:BFFD:4C F2 F5 JMP $F5F2

0F:F541 Clear Message Box, Begin Dialogue Routine
0F:F541:A9 00 LDA #$00
0F:F543:8D 1A 02 STA $021A = #$00
0F:F546:8D 16 02 STA $0216 = #$00
0F:F549:8D 17 02 STA $0217 = #$00
0F:F54C:8D 1C 02 STA $021C = #$00
0F:F54F:A9 04 LDA #$04
0F:F551:8D 15 02 STA $0215 = #$00
0F:F554:8D 1B 02 STA $021B = #$00
0F:F557:4C 0A F7 JMP $F70A
0F:F55A:AD 00 01 LDA $0100 = #$0E
0F:F55D:48 PHA
0F:F55E:A2 10 LDX #$10
0F:F560:20 1A CC JSR $CC1A
0F:F563:E6 E1 INC $00E1 = #$00
0F:F565:8D 12 02 STA $0212 = #$00
0F:F568:20 83 F5 JSR $F583
0F:F56B:4C 4D F4 JMP $F44D
0F:F56E:AD 00 01 LDA $0100 = #$0E
0F:F571:48 PHA
0F:F572:A2 10 LDX #$10
0F:F574:20 1A CC JSR $CC1A
0F:F577:A9 00 LDA #$00
0F:F579:8D 12 02 STA $0212 = #$00
0F:F57C:20 93 F5 JSR $F593
0F:F57F:4C 4D F4 JMP $F44D
0F:F582:60 RTS -----------------------------------------

0F:F583:AD 13 02 LDA $0213 = #$00
0F:F586:F0 FA BEQ $F582
0F:F588:AD 15 02 LDA $0215 = #$00
0F:F58B:F0 F5 BEQ $F582
0F:F58D:A5 E1 LDA $00E1 = #$00
0F:F58F:29 04 AND #$04
0F:F591:D0 EF BNE $F582
0F:F593:AD 1C 02 LDA $021C = #$00
0F:F596:F0 2F BEQ $F5C7
0F:F598:30 16 BMI $F5B0
0F:F59A:C9 04 CMP #$04
0F:F59C:F0 0B BEQ $F5A9
0F:F59E:AA TAX
0F:F59F:BD C2 04 LDA $04C2,X @ $04D0 = #$00
0F:F5A2:EE 1C 02 INC $021C = #$00
0F:F5A5:C9 FF CMP #$FF
0F:F5A7:D0 49 BNE $F5F2
0F:F5A9:A9 00 LDA #$00
0F:F5AB:8D 1C 02 STA $021C = #$00
0F:F5AE:F0 17 BEQ $F5C7
0F:F5B0:C9 88 CMP #$88
0F:F5B2:F0 F5 BEQ $F5A9
0F:F5B4:29 07 AND #$07
0F:F5B6:85 EC STA $00EC = #$3E
0F:F5B8:AD 37 04 LDA $0437 = #$00
0F:F5BB:0A ASL
0F:F5BC:0A ASL
0F:F5BD:0A ASL
0F:F5BE:05 EC ORA $00EC = #$3E
0F:F5C0:AA TAX
0F:F5C1:BD 91 F7 LDA $F791,X @ $F79F = #$0D
0F:F5C4:4C A2 F5 JMP $F5A2

0F:F5C7:AD 18 02 LDA $0218 = #$00
0F:F5CA:85 EC STA $00EC = #$3E
0F:F5CC:AD 19 02 LDA $0219 = #$00
0F:F5CF:85 ED STA $00ED = #$FD
0F:F5D1:AC 14 02 LDY $0214 = #$B4
0F:F5D4:EE 14 02 INC $0214 = #$B4
0F:F5D7:D0 03 BNE $F5DC
0F:F5D9:EE 19 02 INC $0219 = #$A9
0F:F5DC:4C 45 BF JMP $BF45

0F:F5EF:4C 4D F4 JMP $F44D
0F:F5F2:F0 5D BEQ $F651
0F:F5F4:4C 73 BF JMP $BF73

0F:F44D:68 PLA
0F:F44E:AA TAX
0F:F44F:20 1A CC JSR $CC1A
0F:F452:60 RTS -----------------------------------------

0F:F651:A9 81 LDA #$81
0F:F653:8D 1C 02 STA $021C = #$00
0F:F656:AD 37 04 LDA $0437 = #$00
0F:F659:0A ASL
0F:F65A:0A ASL
0F:F65B:0A ASL
0F:F65C:AA TAX
0F:F65D:BD 91 F7 LDA $F791,X @ $F79F = #$0D
0F:F660:4C F2 F5 JMP $F5F2
0F:F663:85 EC STA $00EC = #$3E
0F:F665:A9 00 LDA #$00
0F:F667:06 EC ASL $00EC = #$3E
0F:F669:2A ROL
0F:F66A:06 EC ASL $00EC = #$3E
0F:F66C:2A ROL
0F:F66D:06 EC ASL $00EC = #$3E
0F:F66F:2A ROL
0F:F670:06 EC ASL $00EC = #$3E
0F:F672:2A ROL
0F:F673:06 EC ASL $00EC = #$3E
0F:F675:2A ROL
0F:F676:85 ED STA $00ED = #$FD
0F:F678:A5 EC LDA $00EC = #$3E
0F:F67A:69 00 ADC #$00
0F:F67C:85 EC STA $00EC = #$3E
0F:F67E:A5 ED LDA $00ED = #$FD
0F:F680:69 80 ADC #$80
0F:F682:85 ED STA $00ED = #$FD
0F:F684:60 RTS -----------------------------------------

0F:CA25 Pause
0F:CA25:A9 00 LDA #$00
0F:CA27:85 10 STA $0010 = #$00
>0F:CA29:A5 10 LDA $0010 = #$00
0F:CA2B:F0 FC BEQ $CA29
0F:CA2D:60 RTS -----------------------------------------


0F:D0E4 Dialogue SFX
0F:D0E4:8D 36 04 STA $0436 = #$00
0F:D0E7:8A TXA
0F:D0E8:48 PHA
0F:D0E9:98 TYA
0F:D0EA:48 PHA
0F:D0EB:AD 36 04 LDA $0436 = #$00
0F:D0EE:20 6F F3 JSR $F36F
0F:D0F1:68 PLA
0F:D0F2:A8 TAY
0F:D0F3:68 PLA
0F:D0F4:AA TAX
0F:D0F5:60 RTS -----------------------------------------

0F:F685 Bank Switch PLB
0F:F685:4C DF F5 JMP $F5DF ; JuMP to 0F:F5DF
0F:F5DF:AD 00 01 LDA $0100 = #$0E ; LoaD Bank to A
0F:F5E2:C9 10 CMP #$10 ; Is Bank #$10?
0F:F5E4:F0 06 BEQ $F5EC : If so, branch to End Bank Switch at 0F:F5EC
0F:F5E6:48 PHA ; PusH A
0F:F5E7:A2 10 LDX #$10 ; LoaD #$10 to X
0F:F5E9:20 1A CC JSR $CC1A ; Jump to SubRoutine Bank Switch at 0F:CC1A
0F:F5EC End Bank Switch
0F:F5EC:20 00 BF JSR $BF00 ; JuMP to PLB Checks at 10:BF00
0F:F688 Page Line Break
0F:F688:AD 08 02 LDA $0208 = #$00
0F:F68B:18 CLC
0F:F68C:69 02 ADC #$02
0F:F68E:85 EA STA $00EA = #$00
0F:F690:AD 09 02 LDA $0209 = #$00
0F:F693:18 CLC
0F:F694:69 02 ADC #$02
0F:F696:85 EB STA $00EB = #$00
0F:F698:20 CC F8 JSR $F8CC
0F:F69B:AE 1A 02 LDX $021A = #$00
0F:F69E:20 E8 F6 JSR $F6E8
0F:F6A1:20 E8 F6 JSR $F6E8
0F:F6A4:20 E8 F6 JSR $F6E8
0F:F6A7:A9 00 LDA #$00
0F:F6A9:A0 10 LDY #$10
0F:F6AB:20 12 F9 JSR $F912
0F:F6AE:AE 1A 02 LDX $021A = #$00
0F:F6B1:BD 2A F7 LDA $F72A,X @ $F738 = #$E9
0F:F6B4:85 E8 STA $00E8 = #$C0
0F:F6B6:BD 2E F7 LDA $F72E,X @ $F73C = #$0A
0F:F6B9:85 E9 STA $00E9 = #$23
0F:F6BB:A2 10 LDX #$10
0F:F6BD:8A TXA
0F:F6BE:48 PHA
0F:F6BF:A9 00 LDA #$00
0F:F6C1:A0 10 LDY #$10
0F:F6C3:20 12 F9 JSR $F912
0F:F6C6:20 EE F8 JSR $F8EE
0F:F6C9:68 PLA
0F:F6CA:AA TAX

0C:9D8D:AD 15 02 LDA $0215 = #$04
0C:9D90:D0 F4 BNE $9D86
0C:9D92:20 D9 9D JSR $9DD9
0C:9D95:A5 19 LDA $0019 = #$80
0C:9D97:10 ED BPL $9D86
0C:9D99:A9 04 LDA #$04
0C:9D9B:8D 15 02 STA $0215 = #$04
0C:9D9E:A9 04 LDA #$04
>0C:9DA0:8D 1B 02 STA $021B = #$04
0C:9DA3:20 41 F5 JSR $F541
0C:9DA6:18 CLC
0C:9DA7:A9 01 LDA #$01
0C:9DA9:60 RTS -----------------------------------------

Obviously a lot of this stuff can be consolidated, rewritten in smaller code. I do have this saved on my phone, so I'll take a look. I imagine there is some redundant code, as well. (Due to partial original dialogue code from the JP version)
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 07, 2015, 06:23:05 pm
I've sent this video link to umaggot in a PM, which shows some graphics corruption after SRAM save: https://youtu.be/qqJHjAVROKQ



But I've fixed some of it here  ;D: https://youtu.be/LJBJFZWQyiI
It was a JSR that I had missed redirecting according to US ROM code.
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 07, 2015, 06:52:50 pm
Nice! Maybe... the extra save icon might be misplaced garbage. I know I did a layering effect to cover up garbage (I.E. the save icon is overlapping garbage) If you could figure out how to scoot that junk to the left, you'll be good to go. :thumbsup:
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 07, 2015, 07:09:20 pm
I think that this is the layering effect you're after:
(http://v2.pxl.se/i/3a91bc3b29fbe309.png)

The original Japanese Faxanadu rom is the above and your beta hack is in the bottom.
The bytes in RED are the ones that has been modified with your hack.

But that is one thing that I can't find in the US ROM :-(
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 08, 2015, 08:03:16 am
It looks like a graphics table; particularly, this should tell the game how to display and mirror each 8x8 square. It would be strange if the US version did not have the same table, but I can see that happening.

// So it looks like my code messes up the stack somewhere. I'm looking for a PLA without a PHA, I believe. There are no obvious instances of this, which means it will eventually JMP $F44D without a PHA. 0F:F44D begins with a PLA and ends with the RTS that pulls a faulty stack pointer. I will continue to seek this out today.

// I did test out the following:

Spoiler:
> PHA (inserted)

0F:F5EF:4C 4D F4  JMP $F44D
 0F:F5F2:F0 5D     BEQ $F651
 0F:F5F4:4C 73 BF  JMP $BF73

Which eliminates the crash in that specific instance. It does, however, present a problem everywhere else. I've also narrowed it down to one of two instances; line 4 is full (16 characters) and/or line 5 begins with Control Code: [End Dialogue]
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 08, 2015, 05:35:08 pm
Hmm, I can't really find that code in my ROM with your patch :-/
Title: Re: Faxanadu - Assembly
Post by: umaggot on April 08, 2015, 08:10:34 pm
Ah; no, sorry. I was talking about my Retranslation hack. Everything after the edit has nothing to do with the SRAM hack.

Still looking into the crashes. So far I'm thinking of creating a new code in a blank area (before neatly reorganizing all code), and running a check for last letter/line, INY, LDA ($EC),Y [current letter], CMP control codes #$FF [End Dialogue], #$FE [Line Break], #$FA [New Page], and immediately execute their respective routines -- otherwise, continue to run [Page End Routine].
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on April 10, 2015, 07:04:16 pm
Darn, this ½ doubled Floppy icon is bugging the hell out of me!!
Title: Re: Faxanadu - Assembly
Post by: Bisqwit on May 12, 2015, 02:25:47 am
Uh, what icon where?
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on May 12, 2015, 03:39:14 am
Bisqwit: see the video here https://youtu.be/LJBJFZWQyiI, 0:12 in
Title: Re: Faxanadu - Assembly
Post by: umaggot on May 23, 2015, 09:01:40 am
You won't have to worry about fixing the floppy icon. The "Faxanadu Restoration (T-HudsonUSA) 05-31-15" patch (with just about every conceivable bugfix) is almost complete. We just need testers! :laugh:
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on June 01, 2015, 05:13:31 pm
Awesome umaggot!

Sign me up for testing :-)
Title: Re: Faxanadu - Assembly
Post by: umaggot on June 01, 2015, 07:05:22 pm
Congrats, you are now signed up for testing! Check your PM inbox for the patch. :)

// Groovy. I broke the game save feature. Again. :banghead:

8:07 PM:// Luckily, it's something simple, and you can still save if needed. (Otherwise, just press B!) :laugh: I just need to make sure to switch to bank #10 before $F600.

9:06 PM:// Sent you the fixed patch.
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on June 02, 2015, 03:50:58 pm
Patched the rom and ran a quick test. Is it possible to increase the text speed?
Title: Re: Faxanadu - Assembly
Post by: umaggot on June 02, 2015, 05:14:56 pm
We're finally ready to release the Faxanadu (J) Restoration Vanilla (T-HudsonUSA) patch. This covers several bug fixes, retains uncensored work, adds SRAM and text speed-up options. There is just one problem. This patch only works on FCEU based emulators, due to doubling the size of the 256k MMC1 to 512k MMC1. We can't get anything else (other emulators and hardware) to read Bank 10. Since this patch is the basis for future patches (Retranslation, Remix, and Literal Faxanadu) we'd like to fix this bug and learn more about accessing Bank 10 on other emulators and hardware, before moving forward.

We doubled the size via King Mike's ROM Expansion utility, and changed the SRAM byte. Other than that, I just used regular bank switching (TXA, PHA, LDX #$10, JSR CC1A). I have no idea which bank is being read in other emulators, but further testing by implementing my dialogue code within bank 0F has shown that only garbage will be loaded when reading bank 10 in other emulators and flash carts, where FCEU will read bank 10 without any problems.

// ...Maybe "bank 10" is just not a good bank to use for this purpose?

// Looks like I need to adjust byte 4, and do more research. Found some pretty neat documentation. :)

// Nope. Either King Mike's utility or I myself have already adjusted byte 4 from 10 to 20. Byte 6 went from 10 to 12, which only affects battery backed SRAM.
Title: Re: Faxanadu - Assembly
Post by: umaggot on July 04, 2015, 08:37:18 am
Faxanadu Restoration has been released! (http://heroesoflegend.org/affiliate-projects/faxanadu/)
Don't forget to update your bookmarks!

Oops! Also, it looks like I made a bad link on the main page. Go to the download page to access the patch. :)
Title: Re: Faxanadu - Assembly
Post by: frsj8112 on July 04, 2015, 09:12:27 am
Awesome umaggot!

Sorry for the lame response from my side, but real life has been busy  :-\
Title: Re: Faxanadu - Assembly
Post by: umaggot on July 04, 2015, 11:44:20 am
Thanks! :thumbsup:

No worries, my life has been busy too. I'm just glad I found the time to finish this almost 5-year project.

July 04, 2015, 10:16:32 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
So, since FCEUX will not crash on me, I have to test on something else. NesterJ, Nestopia and flash carts all crash at the same place: the dialogue. This happens when Bank #$10 is loaded. Bank #$10 is loaded just like any other bank, with no real modification.

Code: [Select]
TXA
PHA
LDX #$10
JSR $CC1A

This is all handled in Bank #$0F. So when dialogue is loaded in Nestopia, I get a message in the log.

Quote
Emulator: loading "C:\Users\Heath\Desktop\6502\Faxanadu Restoration (T-HudsonUSA) v1.00.nes"
Ines: 512k PRG-ROM set
Ines: battery set
Ines: horizontal mirroring set
Ines: NTSC set
Ines: mapper 1 set
Board: SUROM
Board: 512k PRG-ROM
Board: 8k W-RAM
Board: 8k V-RAM
Board: MMC rev. B2
Emulator: battery data file "C:\Users\Heath\Desktop\6502\save\Faxanadu Restoration (T-HudsonUSA) v1.00.sav" not found
Cpu: warning, TOP opcode executed
Cpu: warning, DCP opcode executed
Cpu: warning, SRE opcode executed
Cpu: warning, DOP opcode executed
Cpu: jammed!

I'm not sure what this is saying, but I made a test ROM. It was made to print dialogue endlessly, and without running code in Bank #$10. Instead, Bank #$10 was only to be loaded for the purpose of the dialogue itself. On FCEUX, the dialogue would print correctly. On NesterJ, it would print random characters from my font. This tells me that only FCEUX is reading Bank #$10, but the bank switch is unsuccessful on NesterJ, Nestopia, and a flash cart.

Okay, so I looked it up. It's saying that I've executed Double and Triple NOPs. Yep, that's true, and easily fixed. Then there's DCP... "Subtract 1 from memory (without borrow)". Wait, I *need* to have carry set when I DEC or SBC? ...Or does it mean simply that it ran an illegal opcode? As far as I know, other than my DOPs and TOPs, I don't really use extended instructions. Then there's SRE... "Shift right one bit in memory, then EOR accumulator with memory." :crazy: FCEUX doesn't worry about this stuff, so I didn't really pay attention to it. I know I can fix most of this, but... I'm not quite sure what to do about the SRE, if it's necessary.
Title: Re: Faxanadu - Assembly
Post by: Disch on July 05, 2015, 03:04:04 pm
I'm jumping into this thread late, so sorry if you know this already:

This happens when Bank #$10 is loaded. Bank #$10 is loaded just like any other bank, with no real modification.

[snip]
Ines: mapper 1 set

The normal MMC1 maximum is $10 banks.  You can expand this to $20 but you have to use SUROM or SXROM, which swaps $1x and $0x blocks differently.  So... you can't treat bank $10 like "any other bank"

http://wiki.nesdev.com/w/index.php/MMC1#SOROM.2C_SUROM_and_SXROM

You basically have 2 "blocks", each block is $10 banks.  Only 1 block can be swapped in at a time.  This means the fixed bank $0F needs to be duplicated at $0F and $1F, since it will be swapped out when you switch blocks.

So to swap, you'll have to select a block (by writing to $A000-BFFF), AND select a bank within that block (by writing to $E000-FFFF)

If you only do the latter, you'll only be selecting banks 00-0F and will be toggling WRAM disable instead of selecting a block.


EDIT:

Can you post your swap code?  (the routine at $CC1A).  I'll be able to spot if you're doing it correctly or not.
Title: Re: Faxanadu - Assembly
Post by: umaggot on July 05, 2015, 04:03:38 pm
That makes sense, so that's how FF1+2 handles swapping! This is exactly why I've given you credit! :) Anyway, here's the unaltered swap code:

Code: [Select]
Skip; 0F:CC15:AD 00 01  LDA $0100 = #$0E
Skip; 0F:CC18:85 11     STA $0011 = #$0E
>0F:CC1A:8E 00 01  STX $0100 = #$0E
 0F:CC1D:A9 01     LDA #$01
 0F:CC1F:85 12     STA $0012 = #$00
 0F:CC21:8A        TXA
 0F:CC22:8D FF FF  STA $FFFF = #$C9
 0F:CC25:4A        LSR
 0F:CC26:8D FF FF  STA $FFFF = #$C9
 0F:CC29:4A        LSR
 0F:CC2A:8D FF FF  STA $FFFF = #$C9
 0F:CC2D:4A        LSR
 0F:CC2E:8D FF FF  STA $FFFF = #$C9
 0F:CC31:4A        LSR
 0F:CC32:8D FF FF  STA $FFFF = #$C9
 0F:CC35:A5 12     LDA $0012 = #$00
 0F:CC37:C9 01     CMP #$01
 0F:CC39:F0 47     BEQ $CC82

>0F:CC82:C6 12     DEC $0012 = #$00
 0F:CC84:60        RTS -----------------------------------------

The only difference I made was this:

Code: [Select]
>0F:F56E:AD 00 01  LDA $0100 = #$0E
 0F:F571:48        PHA
 0F:F572:A2 10     LDX #$10
 0F:F574:20 1A CC  JSR $CC1A

Which was originally this:

Code: [Select]
>0F:F56E:AD 00 01  LDA $0100 = #$00
 0F:F571:48        PHA
 0F:F572:A2 0D     LDX #$0D
 0F:F574:20 1A CC  JSR $CC1A

So basically I just need to add a block switch, and possibly just switch to the first bank on the second block. I've duplicated $0F to $1F, so the second block should be good and ready. :thumbsup: Now to find the nearest block switch FAQ.
Title: Re: Faxanadu - Assembly
Post by: Disch on July 05, 2015, 04:21:35 pm
Yeah see you're only swapping the bank, not the block.

Quote
Now to find the nearest block switch FAQ.

I doubt you'll find one.... it's kind of a specific thing.  Though you shouldn't need one... you just have to set a bit in the $A000-BFFF reg.


Looks like X has the bank number... and the block is just bit 4 of the bank number so....

Code: [Select]
STX $0100
LDA #$01
STA $12

TXA
AND #$10    ; isolate the block number
STA $BFFF   ; write the 5-bits in stupid MMC1 fashion
LSR A
STA $BFFF
LSR A
STA $BFFF
LSR A
STA $BFFF
LSR A
STA $BFFF

TXA         ; get the bank number again
AND #$0F    ; strip the block number and have only the bank number
STA $FFFF   ; write the 5-bits in stupid MMC1 fashion
LSR A
STA $FFFF
LSR A
STA $FFFF
LSR A
STA $FFFF
LSR A
STA $FFFF

;; do whatever else the routine was doing
Title: Re: Faxanadu - Assembly
Post by: umaggot on July 05, 2015, 05:40:10 pm
That's awesome! I've seen your work before and I thought to myself "it would be awesome if Disch showed up right about now". Leave it to you to fix it in 5. :) Thanks for the help!
Title: Re: Faxanadu - Assembly
Post by: Pennywise on July 05, 2015, 10:11:43 pm
I'll chip in my thoughts too. I've expanded a few MMC1 games to 512kbs before and I find it is more convenient to keep the bank numbers the same between blocks if I'm moving text. So if the text is located at bank 5, I make sure to put the moved text in bank 5 of the other block. That way, I don't have to worry about swapping banks and creating unnecessary code.
Title: Re: Faxanadu - Assembly
Post by: umaggot on July 06, 2015, 10:36:06 am
v1.01 has been released! (http://heroesoflegend.org/affiliate-projects/faxanadu/index.html) :woot!: