News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: RoboCop MMC3 to MMC5 Almost Finished  (Read 1583 times)

Dracula X

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • My YouTube Page for ROM hacking
RoboCop MMC3 to MMC5 Almost Finished
« on: January 11, 2020, 09:57:50 pm »
I'm almost finished converting this mapper but I'm having a proble on trying to figure out on how to set up the PPU and CHR.

Heres what I have so far:

Power up or Reset:
Code: [Select]
07:FF00: 78        SEI
 07:FF01: D8        CLD
 07:FF02: A9 00     LDA #$00
>07:FF04: 8D 00 E0  STA $E000 = #$72 ;MMC5_equivalents?
 07:FF07: 85 44     STA $44 = #$FF
 07:FF09: A9 00     LDA #$00
 07:FF0B: 8D 10 40  STA DMC_FREQ = #$00
 07:FF0E: A9 40     LDA #$40
 07:FF10: 8D 17 40  STA JOY2_FRAME = #$00
 07:FF13: A9 28     LDA #$28
 07:FF15: 8D 00 20  STA PPU_CTRL = #$00
 07:FF18: A9 00     LDA #$00
 07:FF1A: 8D 01 20  STA PPU_MASK = #$00
 07:FF1D: 8D 03 20  STA PPU_OAM_ADDR = #$00
 07:FF20: AD 02 20  LDA PPU_STATUS = #$00
 07:FF23: 10 FB     BPL $FF20
 07:FF25: AD 02 20  LDA PPU_STATUS = #$00
 07:FF28: 30 FB     BMI $FF25
 07:FF2A: AD 02 20  LDA PPU_STATUS = #$00
 07:FF2D: 10 FB     BPL $FF2A
 07:FF2F: AD 02 20  LDA PPU_STATUS = #$00
 07:FF32: 30 FB     BMI $FF2F
 07:FF34: AD 02 20  LDA PPU_STATUS = #$00
 07:FF37: A9 10     LDA #$10
 07:FF39: AA        TAX
 07:FF3A: 8D 06 20  STA PPU_ADDRESS = #$00
 07:FF3D: 8D 06 20  STA PPU_ADDRESS = #$00
 07:FF40: 49 00     EOR #$00
 07:FF42: CA        DEX
 07:FF43: D0 F5     BNE $FF3A
 07:FF45: A9 00     LDA #$00
 07:FF47: 8D 00 80  STA $8000 = #$07 ;MMC5_equivalents?
 07:FF4A: A9 00     LDA #$00
 07:FF4C: 8D 00 A0  STA $A000 = #$01 ; I know how to work around this one
 07:FF4F: A9 00     LDA #$00
 07:FF51: 85 0C     STA $0C = #$FF
 07:FF53: A2 00     LDX #$00
 07:FF55: 86 0D     STX $0D = #$FF
 07:FF57: 8D 05 20  STA PPU_SCROLL = #$00
 07:FF5A: 8E 05 20  STX PPU_SCROLL = #$00
 07:FF5D: A2 FF     LDX #$FF
 07:FF5F: 9A        TXS
 07:FF60: 20 14 C0  JSR $C014
 07:FF63: 20 B7 CD  JSR $CDB7
 07:FF66: A9 0D     LDA #$0D
 07:FF68: 20 3E C3  JSR $C33E bank
 07:FF6B: 20 00 80  JSR $8000
 07:FF6E: A9 A8     LDA #$A8
 07:FF70: 85 09     STA $09 = #$00
 07:FF72: 8D 00 20  STA PPU_CTRL = #$00
 07:FF75: 20 1D C0  JSR $C01D
 07:FF78: A9 1E     LDA #$1E
 07:FF7A: 85 0A     STA $0A = #$00
 07:FF7C: 4C 00 C0  JMP $C000

Bankswitch code:
Code: [Select]
bank:
 07:C33E: 78        SEI
 07:C33F: 85 19     STA $19 = #$0D
 07:C341: A2 06     LDX #$06
>07:C343: 8E 00 80  STX $8000 = #$07
 07:C346: 8D 01 80  STA $8001 = #$0C
 07:C349: 58        CLI
 07:C34A: 60        RTS -----------------------------------------
bank2:
 07:C34B: 78        SEI
 07:C34C: 85 1A     STA $1A = #$00
 07:C34E: A2 07     LDX #$07
 07:C350: 8E 00 80  STX $8000 = #$07
 07:C353: 8D 01 80  STA $8001 = #$0C
 07:C356: 58        CLI
 07:C357: 60        RTS -----------------------------------------

This is what I have:
Code: [Select]
bank:
 07:C33E: 78        SEI
 07:C33F: 85 19     STA $19 = #$0D
 07:C341: A2 06     ORA #$09
>07:C343: 8E 00 80  STA $5114 = #$07
 07:C346: 8D 01 80  STA $8001 = #$0C ;MMC5_equivalents?
 07:C349: 58        CLI
 07:C34A: 60        RTS -----------------------------------------
bank2:
 07:C34B: 78        SEI
 07:C34C: 85 1A     STA $1A = #$00
 07:C34E: A2 07     ORA #$09
 07:C350: 8E 00 80  STA $5115 = #$07
 07:C353: 8D 01 80  STA $8001 = #$0C ;MMC5_equivalents?
 07:C356: 58        CLI
 07:C357: 60        RTS -----------------------------------------

Now I'm trying to get the PPU and CHR to work:

Code: [Select]
07:DA21: A9 00     LDA #$00
 07:DA23: 8D 06 20  STA PPU_ADDRESS = #$00
 07:DA26: 8D 06 20  STA PPU_ADDRESS = #$00
 07:DA29: AD 02 20  LDA PPU_STATUS = #$00
 07:DA2C: A5 0C     LDA $0C = #$00
 07:DA2E: 8D 05 20  STA PPU_SCROLL = #$00
 07:DA31: A5 0D     LDA $0D = #$00
 07:DA33: 8D 05 20  STA PPU_SCROLL = #$00
 07:DA36: A9 B0     LDA #$B0
>07:DA38: 8D 00 C0  STA $C000 = #$20 ;MMC5_equivalents?
 07:DA3B: A9 00     LDA #$00
 07:DA3D: 8D 01 C0  STA $C001 = #$1D ;MMC5_equivalents?
 07:DA40: A5 44     LDA $44 = #$00
 07:DA42: D0 06     BNE $DA4A
 07:DA44: 8D 00 E0  STA $E000 = #$72 ;MMC5_equivalents?
 07:DA47: 4C 4D DA  JMP $DA4D
 07:DA4A: 8D 01 E0  STA $E001 = #$20 ;MMC5_equivalents?

And here:
Code: [Select]
07:DA7A: E0 08     CPX #$08
 07:DA7C: F0 07     BEQ $DA85
 07:DA7E: E0 10     CPX #$10
 07:DA80: B0 08     BCS $DA8A
 07:DA82: 4C 5B DA  JMP $DA5B
 07:DA85: A5 65     LDA $65 = #$00
 07:DA87: 4C 5B DA  JMP $DA5B
 07:DA8A: A9 00     LDA #$00
 07:DA8C: 85 64     STA $64 = #$00
 07:DA8E: 85 65     STA $65 = #$00
 07:DA90: A2 05     LDX #$05
>07:DA92: 8E 00 80  STX $8000 = #$72 ;MMC5_equivalents?
 07:DA95: B5 13     LDA $13,X @ $0017 = #$00
 07:DA97: 8D 01 80  STA $8001 = #$20 ;MMC5_equivalents?
 07:DA9A: CA        DEX
 07:DA9B: 10 F5     BPL $DA92
 07:DA9D: A5 19     LDA $19 = #$FF
 07:DA9F: 48        PHA
 07:DAA0: A9 0D     LDA #$0D
 07:DAA2: 20 3E C3  JSR $C33E bank
 07:DAA5: 20 06 80  JSR $8006
 07:DAA8: 68        PLA
 07:DAA9: 20 3E C3  JSR $C33E bank
 07:DAAC: 60        RTS -----------------------------------------

So I'm trying to figure out the MMC5_equivalents except for $A000 and $A001.

SomeOldGuy

  • Jr. Member
  • **
  • Posts: 52
  • Game Changer
    • View Profile
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #1 on: March 19, 2020, 08:36:11 pm »
Hey Drac!   

Any updates on this conversion?   ;D

OG

Disch

  • Hero Member
  • *****
  • Posts: 2787
  • NES Junkie
    • View Profile
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #2 on: March 19, 2020, 08:43:15 pm »
I didn't see this post until it got bumped.  Are these still problems you want help with?

Dracula X

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • My YouTube Page for ROM hacking
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #3 on: March 19, 2020, 09:48:22 pm »
Yes! I think I got the bankswitch code working but I need to figure out how to fix the game graphics and PPU stuff.

Disch

  • Hero Member
  • *****
  • Posts: 2787
  • NES Junkie
    • View Profile
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #4 on: March 19, 2020, 11:17:28 pm »
Robocop looks like it uses 8x16 sprites.  MMC5 does 8x16 sprites a little weird -- it has a completely different set of registers for BG tiles and for sprite tiles.  That way it can give 8x16 sprites twice as many tiles to choose from (they don't have to share the pattern tables with the BG like they normally would have to)

So when the game is swapping BG CHR tiles, you'd want to use $5128-512B .. and when swapping Sprite CHR tiles you'd want to use $5124-5127.  Note that $5120-5123 will probably go unused -- those are going to be your extra sprite tiles that the original game won't be using.

So looking at this:

Code: [Select]
07:DA90: A2 05     LDX #$05
>07:DA92: 8E 00 80  STX $8000 = #$72 ;MMC5_equivalents?     ; <---- loop here
 07:DA95: B5 13     LDA $13,X @ $0017 = #$00
 07:DA97: 8D 01 80  STA $8001 = #$20 ;MMC5_equivalents?
 07:DA9A: CA        DEX
 07:DA9B: 10 F5     BPL $DA92                                  ; <---- jump to loop

X is controlling which portion of CHR gets swapped (via the write to $8000).  What makes this tricky is that when X=0 or X=1, the game is selecting a 2K block of BG tiles.... whereas when X=2,3,4 or 5, you are selecting a 1K block of Sprite tiles.  Aside from BG and sprites being different, these are also different SIZES.

From the MMC5 standpoint, you'll probably be in 1K CHR mode, which means you'll have to swap in two different 1K pages instead of the 2K page for BG tiles.

There isn't really a simple way to reconsile the differences here -- so you'll probably have to split this loop into two parts -- one to select BG and one to select sprites:

Code: [Select]
; The 0,1 values are 2K BG pages
;   You MIGHT be able to shave a few bytes by making a very small loop, but I
;   didn't check and it wouldn't be more than a byte or two if even that.
LDX $13      ; load first 2K page number
STX $5128    ; swap first half in
INX
STX $5129    ; swap second half in

LDX $14      ; do same for next 2K page number
STX $512A
INX
STX $512B

; the 2,3,4,5 values are 1K Sprite pages
;   this is easier to loop
LDX #$03   ; we're going to loop 4 times counting down 3->0
LoopHere:
  LDA $15,X   ; read from $15,X instead of $13,X because we're only interested in the spr pages
  STA $5124,X
  DEX
  BPL LoopHere


The other parts are IRQ related.  Fortunately the overlap between MMC3 and MMC5 is enough that this isn't TOO terrible... but it's still kind of barfy.

Code: [Select]
07:DA36: A9 B0     LDA #$B0
>07:DA38: 8D 00 C0  STA $C000 = #$20 ;MMC5_equivalents?
 07:DA3B: A9 00     LDA #$00
 07:DA3D: 8D 01 C0  STA $C001 = #$1D ;MMC5_equivalents?
 07:DA40: A5 44     LDA $44 = #$00
 07:DA42: D0 06     BNE $DA4A
 07:DA44: 8D 00 E0  STA $E000 = #$72 ;MMC5_equivalents?
 07:DA47: 4C 4D DA  JMP $DA4D
 07:DA4A: 8D 01 E0  STA $E001 = #$20 ;MMC5_equivalents?

$C000 controls which scanline the IRQ is to fire on.  The MMC5 equivalent of that is $5203.
Writing any value to $C001 just triggers the IRQ counter to restart.  This doesn't need to be done on MMC5 since it automatically primes itself when rendering starts.

There is a SLIGHT difference in how each mapper counts scanlines, but I don't think it'll make a big difference here.  I would say just use the game's original scanline counter values and tweak them by a scanline or two only if the screen splits look bad.  I suspect they'll be fine.

$E000 and $E001 control whether the IRQ counter is enabled.  Writing any value to $E000 will acknowledge the IRQ and disable it.  Writing any value to $E001 will enable it.  The code here seems to use $44 as the flag to enable/disable IRQs (nonzero = enabled)

On MMC5, IRQs are controlled by the high bit of $5204.  You can also acknowledge IRQs by reading from $5204


So the MMC5 equivalent to the above would be....
Code: [Select]
LDA #$B0     ;  (maybe need to adjust this value if it looks bad, but probably not)
STA $5203    ; set scanline for the IRQ to fire

LDA $5204    ; acknowledge any pending IRQ -- probably need to put this in the IRQ handler, too, the
             ;    game is certainly writing to $E000 at that point in the code to do this.
             
LDA $44      ; Do we want to enable IRQs?
BEQ Skip     ;   If zero (disabled), keep the zero in A
   LDA #$80  ;   Otherwise (nonzero, enabled) put #$80 in A
Skip:
STA $5204    ; write A to enable/disable IRQs as appropriate

I'll stop there for now.  I didn't look at the startup or PRG swapping bits you posted since you said the graphics stuff is what you were having problems with, but if you are still having problems with that lemme know.

Dracula X

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • My YouTube Page for ROM hacking
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #5 on: March 20, 2020, 04:10:48 pm »
Wow! Thanks! The first code fixed up everything, now the music is not playing. Now I need to fix the other part that shows how many bullets and health graphics and that's it.

Disch

  • Hero Member
  • *****
  • Posts: 2787
  • NES Junkie
    • View Profile
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #6 on: March 20, 2020, 04:36:39 pm »
now the music is not playing.

That's gotta be a problem with your PRG swapping.  I don't know what else could possibly cause that.  =x

Quote
Now I need to fix the other part that shows how many bullets and health graphics and that's it.

The HUD?  Could be that the screen is not splitting properly.  Might be a problem with some IRQ code, or maybe code inside the IRQ handler isn't swapping CHR properly.

Dracula X

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • My YouTube Page for ROM hacking
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #7 on: March 20, 2020, 06:25:50 pm »
You might be right or it could be my bankswitch code.

Here is my MMC5 setup code maybe this might be wrong too:
Code: [Select]
mmc5setup:
SEI
CLD
LDA #$00
STA $5010
LDA #$00
STA $5015
LDA #$03
STA $5100
LDA #$02
STA $5101
LDA #$02
STA $5102
LDA #$01
STA $5103
LDA #$02
STA $5104
LDA #$44
STA $5105
LDA #$00
STA $5106
LDA #$00
STA $5107
LDA #$0F
STA $5120
LDA #$0F
STA $5121
LDA #$0F
STA $5122
LDA #$0F
STA $5123
LDA #$0F
STA $5124
LDA #$0F
STA $5125
LDA #$7F
STA $5126
LDA #$0F
STA $5127 ;#$7F
LDA #$00
STA $5128
LDA #$00
STA $5129
LDA #$02
STA $512A
LDA #$01
STA $512B ;#$01 $13
LDA #$0F
STA $5130
LDA #$00
STA $5200
LDA #$00
STA $5203
LDA #$00
STA $5204
LDA #$00
STA $5209
LDA #$00
STA $5800
LDA #$03
STA $5113
LDA #$80
STA $5114
LDA #$81
STA $5115
LDA #$8E
STA $5116
LDA #$8F
STA $5117

I think I found the HDD code:
Code: [Select]
  01E231: 8D 00 E0  STA $E000 = #$72
  01E234: A9 00     LDA #$00
  01E236: 8D 00 80  STA $8000 = #$07
  01E239: A9 04     LDA #$04
  01E23B: 8D 01 80  STA $8001 = #$0C
  01E23E: A9 01     LDA #$01
  01E240: 8D 00 80  STA $8000 = #$07
  01E243: A9 02     LDA #$02
  01E245: 8D 01 80  STA $8001 = #$0C
  01E248: 68        PLA
  01E249: 60        RTS -----------------------------------------
« Last Edit: March 20, 2020, 09:19:28 pm by Dracula X »

Disch

  • Hero Member
  • *****
  • Posts: 2787
  • NES Junkie
    • View Profile
Re: RoboCop MMC3 to MMC5 Almost Finished
« Reply #8 on: March 20, 2020, 10:17:46 pm »
Regarding your setup:

- You want 1K CHR mode (should be writing 3 to $5101, you're currently writing 2, putting you in 2K mode)

- Writing $0F to $5130 is.... strange, but it won't hurt anything I suppose.  You probably don't need to touch that reg at all unless you've got over 256K CHR (the original game doesn't).  But if you want to be super-safe I'd write 0, and I'd do it before writing to any of the other CHR regs.  But again -- probably not necessary.

- I probably would not write anything to $5209 at all -- but I would READ it.  According to the wiki writing to $5209 starts an IRQ timer which you probably don't want -- whereas reading it will acknowledge it.  Maybe the safest and most bulletproof bet here would be write 0->$520A, then 0->$5209, then READ $5209.  That will zero the IRQ counter and then acknowledge it, bringing it to a full stop regardless of any weird startup state.

- I definitely would not touch $5800.  It's an unknown reg and it looks like Just Breed is the only game that touches it, meaning you probably don't have to mess with it.

- I'd probably write 0 to $5113 rather than 3, but I doubt it really matters.  3 is just kinda weird.

- I would read from $5204 at some point.


Everything else looks great.   :beer:



As for the HUD code, that looks like typical CHR swapping stuff (and an IRQ acknowledge).  Rather than hand you that one, I think it's best if you try it out yourself and post your attempt here if it doesn't work.   :thumbsup:

I've already sort of covered everything you need to know to mimic that in my last post.