Famicom Expansion Port Controller Support for 'Celeste Mario's Zap & Dash!'

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

Post Reply
FWo
Posts: 3
Joined: Wed Jan 08, 2025 8:16 pm

Famicom Expansion Port Controller Support for 'Celeste Mario's Zap & Dash!'

Post by FWo »

1-2 years ago, I came across the fantastic 'Celeste Mario's Zap & Dash!' hack of 'Super Mario Bros.' (https://www.romhacking.net/hacks/7915/).

I have never been able to make it run on my Famicom. Today, I randomly came across this Twitter conversation (https://xcancel.com/krikzz/status/1876701368448172432#m), and it finally works!

Granted, in all the excitement I saw the nes2edit screenshot way too late, so I (1) wasted 20 minutes on Google to find viewtopic.php?t=16587, and (2) played the guessing game and ended up setting all 4 dropdowns to 32K. Would have been a lot easier to just follow provided instructions by Krikzz--either way, the game runs.

There is just one problem: A/B buttons are not working when using my BlueRetro controller via the Famicom expansion port.

I have found a whole bunch of patches for this issue on https://github.com/darthcloud/famicom-e ... /tree/main, but sadly there is none available for this particular romhack.


Does anybody here happen to have the knowledge of how to create a patch for this?
Bavi_H
Posts: 219
Joined: Sun Mar 03, 2013 1:52 am
Location: Texas, USA
Contact:

Re: Famicom Expansion Port Controller Support for 'Celeste Mario's Zap & Dash!'

Post by Bavi_H »

I took a look at the code. From what I see, the game already combines the inputs from controller 1 and the expansion controller except for the A button which it only uses from controller 1. (It looks like using the B button to dash only works a little bit into the game after you have collected the lightning bolt and the status bar says you are now DASH MARIO.)

I've attached a patch that will update the game to use the A button from the expansion controller. After you have applied the original patch to get the Celeste Mario game, apply the attached patch to update the controller reading code.
Advanced note: I saw the original code uses unrolled code during the controller read, possibly for speed reasons. In my fix, I used partially unrolled code but it takes 20 more CPU cycles than the original code. I only tested a little bit and see no problems, but it might be possible that at some later point in the game, this code takes too long and causes a crash or a problem. Does anyone else have any ideas how to help confirm if the code using 20 more cycles is okay or will cause a problem?

Code: Select all

==========

original code

00:9879  LDX #$01   ; \
00:987B  STX $4016  ; / Mem[$4016] = 1
00:987E  DEX        ; \
00:987F  STX $4016  ; / Mem[$4016] = 0
00:9882  LDA $4016  ; \
00:9885  STA $0100  ; / ; A
00:9888  LDA $4016  ; \
00:988B  AND #$03   ; |
00:988D  CMP #$01   ; | 
00:988F  ROL $0100  ; / ; B
00:9892  LDA $4016  ; \
00:9895  AND #$03   ; |
00:9897  CMP #$01   ; |
00:9899  ROL $0100  ; / ; SELECT
00:989C  LDA $4016  ; \
00:989F  AND #$03   ; |
00:98A1  CMP #$01   ; |
00:98A3  ROL $0100  ; / ; START
00:98A6  LDA $4016  ; \
00:98A9  AND #$03   ; |
00:98AB  CMP #$01   ; |
00:98AD  ROL $0100  ; / ; up
00:98B0  LDA $4016  ; \
00:98B3  AND #$03   ; |
00:98B5  CMP #$01   ; |
00:98B7  ROL $0100  ; / ; down
00:98BA  LDA $4016  ; \
00:98BD  AND #$03   ; |
00:98BF  CMP #$01   ; |
00:98C1  ROL $0100  ; / ; left 
00:98C4  LDA $4016  ; \
00:98C7  AND #$03   ; |
00:98C9  CMP #$01   ; |
00:98CB  ROL $0100  ; / ; right
00:98CE  [...]      ;   [...next instruction]

==========

patch replaces instructions from 00:9882 to 00:98CB with the following

00:9882:
  LDX #1

rpt:
  LDA $4016
  AND #$03
  CMP #$01
  ROL $0100

  LDA $4016
  AND #$03
  CMP #$01
  ROL $0100

  LDA $4016
  AND #$03
  CMP #$01
  ROL $0100

  LDA $4016
  AND #$03
  CMP #$01
  ROL $0100

  DEX
  BPL rpt
  BMI $98CE

==========
FWo
Posts: 3
Joined: Wed Jan 08, 2025 8:16 pm

Re: Famicom Expansion Port Controller Support for 'Celeste Mario's Zap & Dash!'

Post by FWo »

Thank you so much! It works perfectly.

I progressed reasonably far into the game (not on the Famicom), and as far as I can recall the level design never gets tooo busy. I'm hoping those 20 cycles will be fine, but I'll definitely let you know should I run into any issues.


Re the patch, is that something that can easily be adopted to another game, for example Aladdin? Assuming that's a hard 'no', as the instructions would look completely different?
Bavi_H
Posts: 219
Joined: Sun Mar 03, 2013 1:52 am
Location: Texas, USA
Contact:

Re: Famicom Expansion Port Controller Support for 'Celeste Mario's Zap & Dash!'

Post by Bavi_H »

I found a speedrun emulator movie of the game for the emulator BizHawk: The movie ran to completion with both the original game and my fix, so that helps suggest there's no problems with my fix...

FWo wrote: Thu Jan 09, 2025 12:44 amRe the patch, is that something that can easily be adopted to another game, for example Aladdin? Assuming that's a hard 'no', as the instructions would look completely different?
Each game can read the controllers a little differently, but I think the process is mostly similar from game to game. I suspect the only likely problem when developing a patch to make a game use expansion controlers would be if there is too little free space to add the extra instructions needed.

For example, on the page of patches you linked to, I see there's a section in the readme text that lists three game patches that had to omit reading the normal controllers to read the expansion controllers, instead of reading them both and combining their inputs: Games that loose internal controllers support. It says in these games "The original poll function is quite optimized already and the bank in which the poll function is located do not have obvious empty space to allow relocation/split of the poll function."
FWo
Posts: 3
Joined: Wed Jan 08, 2025 8:16 pm

Re: Famicom Expansion Port Controller Support for 'Celeste Mario's Zap & Dash!'

Post by FWo »

Again, thanks a ton. I know what I'll be doing this weekend!

(I need a lot more time than 6 minutes for this game :mrgreen: )
Post Reply