CNROM to TxRom conversion - CC65 compiler

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 8:05 am

I'm trying to convert my current project from CNROM to TxROM using MMC3 mapping. I'm using C scripts for software development, so I know there are things I need to change in my CC65 config file and init code (crt0.s) in order to accomplish the conversion, but I'm not totally sure what to change.

If anyone can help, or provide some example files that use MMC3 mapping, I would greatly appreciate it!
Last edited by the_doctor on Mon May 30, 2016 1:45 pm, edited 2 times in total.

User avatar
tokumaru
Posts: 11466
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: CNROM to TxRom conversion - CC65 compiler

Post by tokumaru » Tue May 24, 2016 8:38 am

You shouldn't need to change the config file if all you need is to get a CNROM program working with the MMC3, because the ROM structure can remain the same. You only need to make sure that the init code is in the fixed bank ($E000-$FFFF), and that this code will map the remaining banks in the correct order before running the test of the program. In addition to that, CHR bankswitch operations will now need to change 6 mapper registers, instead of just one.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CNROM to TxRom conversion - CC65 compiler

Post by tepples » Tue May 24, 2016 9:50 am

This code must run in $E000-$FFFF before any code outside $E000-$FFFF runs:

Code: Select all

  ldx #$06
  ldy #$00
  stx $8000  ; Command 6: Into PRG $8000-$9FFF...
  sty $8001  ; switch PRG ROM $0000-$1FFF
  sty $E000  ; Disable interval timer IRQ
  sty $A001  ; Select vertical mirroring
  inx
  iny
  stx $8000  ; Command 7: Into PRG $A000-$BFFF...
  sty $8001  ; switch PRG ROM $2000-$3FFF
  sty $A001  ; Select horizontal mirroring
Use only one of the mirroring select lines; comment out the other.

Old bank switch code:

Code: Select all

.proc cnrom_switch_tile_bank
  tay
  sta identity_table,y
  rts
.endproc
New bank switch code:

Code: Select all

;;
; Writes bank*8 + [1, 3, 4, 5, 6, 7] to the MMC3 CHR bank registers
.proc mmc3_switch_tile_bank
  asl a
  asl a
  sec
  rol a  ; A = bank number * 8 + 1
  sec    ; first ADC #1 will go to 3, not 2
  ldy #0
  @loop:
    sty $8000
    sta $8001
    iny
    adc #1
    cpy #6
    bcc loop
  rts
.endproc

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 10:11 am

Thanks for the replies!

Don't I need to change the .cfg file though so that my PRG is divided into 8kb chunks?

User avatar
tokumaru
Posts: 11466
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: CNROM to TxRom conversion - CC65 compiler

Post by tokumaru » Tue May 24, 2016 10:48 am

No, because as long as the init code is guaranteed to be in the fixed bank, it will take care of mapping all 4 banks linearly so they look like a single 32KB. Unless you plan on extending the ROM past 32KB and actually make use of MMC3 bankswitching.

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 11:03 am

Interesting, okay I added the posted init code and everything still compiles and runs as it did before. Is there any way I can verify that the ROM type has been successfully converted from CN to Tk? (using FCEUX emulator, version 2.1.5)

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 11:07 am

Ah actually I did find something in the message log labeled "Mapper name". And it does say MMC3!

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 11:08 am

Oh but now most of the in-game graphics are messed up. Probably not bank-switching correctly....

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 11:41 am

Looks like I fixed it, thanks for the help guys!

Summary of the solution:
1) Had to go into the .cfg file and change the mapper number to 4
2) Had to add the following to my init code:
ldx #$06
ldy #$00
stx $8000 ; Command 6: Into PRG $8000-$9FFF...
sty $8001 ; switch PRG ROM $0000-$1FFF
sty $E000 ; Disable interval timer IRQ
;sty $A001 ; Select vertical mirroring
inx
iny
stx $8000 ; Command 7: Into PRG $A000-$BFFF...
sty $8001 ; switch PRG ROM $2000-$3FFF
sty $A001 ; Select horizontal mirroring

3) had to use the following to switch between CHR banks:
asl a
asl a
sec
rol a ; A = bank number * 8 + 1
sec ; first ADC #1 will go to 3, not 2
ldy #0
loop:
sty $8000
sta $8001
iny
adc #1
cpy #6
bcc loop
rts

Note: credit for the above code goes to tepples (I just copied and pasted it from his post) Thanks! :)
Last edited by the_doctor on Tue May 24, 2016 12:47 pm, edited 4 times in total.

User avatar
dougeff
Posts: 2616
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: CNROM to TxRom conversion - CC65 compiler

Post by dougeff » Tue May 24, 2016 12:11 pm

How many PRG banks of 8k are you going to use?

You should test on a flash cartridge/real hardware, and especially in an emulator that isn't FCEUX.

Also, I believe MMC3 banks need to be initialized near start-up, or you can't guarantee which bank is mapped to which addresses...especially if the user hits 'reset'.
nesdoug.com -- blog/tutorial on programming for the NES

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 12:46 pm

Currently using 4 8kb PRG banks.

And thanks for the advice, I'll try to test it on some other emulators now, and will probably have someone with more knowledge and skill than me to test it on some hardware. Any emulators in particular I should test on?

the_doctor
Posts: 31
Joined: Tue May 24, 2016 7:54 am

Re: CNROM to TxRom conversion - CC65 compiler

Post by the_doctor » Tue May 24, 2016 12:59 pm

Looks like it works fine on VirtuaNES v0.97, but not on Nestopia v1.40 (for some reason the video quickly cuts out, but it seems to do this even with the nes file I have from before I started the CN to MMC3 conversion so I don't think it's related to that).

User avatar
dougeff
Posts: 2616
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: CNROM to TxRom conversion - CC65 compiler

Post by dougeff » Tue May 24, 2016 1:02 pm

Currently, I prefer Nestopia with Options/Video/Filter=NTSC

I'm not sure which emulator does MMC3 most accurately.
nesdoug.com -- blog/tutorial on programming for the NES

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CNROM to TxRom conversion - CC65 compiler

Post by tepples » Tue May 24, 2016 1:11 pm

Can you afford a PowerPak CF to NES adapter (135 USD) or an EverDrive-N8 SD to NES adapter (127 USD*) to use with your NES?


* This price includes a black shell, basic labels, and standard Phillips screws.

lidnariq
Posts: 8786
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: CNROM to TxRom conversion - CC65 compiler

Post by lidnariq » Tue May 24, 2016 1:15 pm

No emulators currently randomize the MMC3's registers on boot, so it's easy to accidentally rely on undefined state. ( thefox has said that he wants to add this to NintendulatorDX, but it's not present yet. )

If you're not using IRQs, there's very little else to be accurate about. If you are, Nintendulator(/DX) is the only debugging emulator that I'd trust to be remotely accurate. Without a debugger, I'd probably trust puNES to be the most accurate.

Post Reply