News: 11 March 2016 - Forum Rules

Author Topic: Faxanadu - Assembly  (Read 17601 times)

frsj8112

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Faxanadu - Assembly
« Reply #40 on: July 04, 2015, 09:12:27 am »
Awesome umaggot!

Sorry for the lame response from my side, but real life has been busy  :-\

umaggot

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Faxanadu - Assembly
« Reply #41 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.
« Last Edit: July 04, 2015, 10:18:56 pm by umaggot »

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Faxanadu - Assembly
« Reply #42 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.

umaggot

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Faxanadu - Assembly
« Reply #43 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.

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Faxanadu - Assembly
« Reply #44 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

umaggot

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Faxanadu - Assembly
« Reply #45 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!

Pennywise

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 2394
  • Prepare thyself for holy judgment
    • View Profile
    • Yojimbo's Translations
Re: Faxanadu - Assembly
« Reply #46 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.

umaggot

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Faxanadu - Assembly
« Reply #47 on: July 06, 2015, 10:36:06 am »
« Last Edit: July 20, 2015, 05:14:49 pm by umaggot »