controller emulation

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
uglyoldbob
Posts: 6
Joined: Tue Feb 21, 2023 7:22 pm

controller emulation

Post by uglyoldbob »

Hello all,

I recently started a NES emulator in rust (https://github.com/uglyoldbob/old_systems). I have run into a problem where my emulated controller just does not behave properly. This is based on the test_rom/read_joy3/test_buttons.nes rom.

My controller code is in nes/rust/src/controller.rs and the integration to the system in nes/rust/src/motherboard.rs.

I'm probably drastically misunderstanding how the controller is supposed to work. Can anybody provide some guidance on the controller emulation?
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: controller emulation

Post by jeffythedragonslayer »

Are you getting no controller input whatsoever?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: controller emulation

Post by lidnariq »

It would help if you explained what does happen. For example, what do you see if you try running my viewtopic.php?p=106954#p106954 ?
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: controller emulation

Post by Fiskbit »

Looking at your code, it looks to me in motherboard.rs like you're inverting the data from the controllers (d ^ 0x1f). This is correct in that data from the controller ports is indeed inverted before reaching the CPU, but standard controller buttons are active low while your controller seems to be tracking pressed buttons with 1, so I think the CPU will see the data inverted. This inversion also means that you're setting unused controller bits to 1, but those bits read either as 0 or open bus, depending on the bit and console type.

Otherwise, the code seems correct to me. Your controller looks like it models the real one very well and should even handle reads properly while out0 is high.
uglyoldbob
Posts: 6
Joined: Tue Feb 21, 2023 7:22 pm

Re: controller emulation

Post by uglyoldbob »

I tried the test rom, and found my controller logic was inverted, so I corrected my controller implementation.
Additionally, I had to run controller 2 because some of the top of the screen doesn't get displayed for some reason. I'll try to post a picture of it later.
Post Reply