How Super Nintendo (SNES) controller interfaces with my 8-bit homebrew computer

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ต.ค. 2022
  • NEW: Zeal 8-bit Computer is now available on Tindie, check tindie.com/products/zeal8bit/...
    Or get it on Aliexpress now: www.aliexpress.com/item/10050...
    Hello world!
    In this video I will show you how the Super Nintendo (also known as SNES or Super Famicom) controller protocol works. Thanks to this, we will be able to explain how to connect one to a homebrew 8-bit computer: Zeal 8-bit Computer.
    After a brief explanation, I will also show how to write an example in Z80 assembly to reproduce the protocol and communicate with the controller.
    The final outcome is a PCB that acts as an SNES Controller Adapter for Zeal 8-bit Computer, and that can be connected directly to the User I/O port.
    You will find the source code of this example on my Github, and also the schematics for the adapter board:
    github.com/Zeal8bit/Zeal-SNES...
    Feel free to contribute, ask questions or simply comment your thoughts!
    find me on:
    * Discord: / discord
    * Twitter: / zeal8bit
    * Reddit: / zeal8bit
    * Website: zeal8bit.com
    ---
    Source for the controllers table and the controllers pictures:
    en.wikipedia.org/wiki/List_of...
    en.wikipedia.org/wiki/File:Pl...
    en.wikipedia.org/wiki/File:Ni...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 60

  • @Curt_Sampson
    @Curt_Sampson ปีที่แล้ว +10

    Why do you bother reading the last four bits from the shift register? If you read just twelve bits, that should be fine, too, since the next time you make latch active all the bits in the register will be replaced with the parallel input (the current button values) regardless of any shifting that's been done before that, right?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +9

      Good point! In theory yes, that's how a shift register works, here I really wanted to mimic the SNES, which performs all the clock cycles.
      That's definitely something I am going to try though!

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +10

      I confirm that it works, only 11 clock cycles (as after the latch, we have already the first bit on the DATA line) are necessary to get all the buttons!
      Thanks for the remark, I am going to pin your comment so that everyone can see it!
      Reagarding the SNES itself and why it perform 16 clock cycles, my guess is that it's not only due to the controller 16-bit shift register but also due to the console itself which has a 16-bit I/O register used to store the joypad status (CNTRL1L, CNTRL2L, ...). Moreover, in the hardware, it's much simpler to detect when a counter is equal to 16 than dectecting when it's equal to 12, as it's not a power of two.

    • @Curt_Sampson
      @Curt_Sampson ปีที่แล้ว +4

      @@Zeal8bit Good to know that not reading all the bits actually works! It's always nice to have one's theories tested.
      As for why Nintendo reads 17 bits, I read in a forum that it's used for controller detection: the SI (shift input) pin from the shift register at the end of the chain is what you'll read after the 16th shift, and this pin is held low in the controller, causing you to read a zero if the controller is connected. I'll link to this post in another reply since TH-cam tends to swallow any post of mine that has a URL in it.

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +3

      @@Curt_Sampson The 17th is a very ingenious trick, I didn't know about it!
      So the games could detect when a controller has been disconnected or reconnected

    • @jkobain
      @jkobain ปีที่แล้ว +1

      04:04 note brought me to the comments section with the very same argument.

  • @bridiro
    @bridiro ปีที่แล้ว +3

    AMAZING!!!! That's exactly why I am here! I just hope your channel could reach more people in future!

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Thank you very much, I hope so!

  • @sanhua8337
    @sanhua8337 ปีที่แล้ว +5

    I like that you left a user port on Zeal 8-bit computer, leaving lots of space for extensions like adding joysticks, or even Wi-Fi module etc. BTW when can I get some kit, really wanna try it😄

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Haha exactly, that was the purpose, let anyone extend the capabilities! The limit is the imagination (and the cost?)

  • @rfgrooteman
    @rfgrooteman ปีที่แล้ว +4

    Great stuff!

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Thank you very much 😄

  • @paulspark7287
    @paulspark7287 ปีที่แล้ว +4

    Awesome video! I love the sound effect you use when presenting the pins too! Very entertaining.. and I might just have to use one of these types of controller myself since I have one. I would have been lazy and stuck with the Atari/C64 joystick scheme myself.. but I like the idea of something a bit more complex.
    Of course I still have to integrate a CPU to my FPGA yet as you know..

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      Thanks for the feedback!
      I would totally advise you to try if you have one already. It's easy and the controller is really good. If you want to interface it with an FPGA, be careful about the DATA line (and other pins too maybe) the controller needs 5V, all recent FPGA I/Os are 3.3V
      The controller won't have any problem recognizing 3.3V signals, but don't plug the DATA line directly to your FPGA without a level-shifter or you'll fry your FPGA I/O. In practice I would even advise you to shift all DATA, LATCH and CLOCK pins with level-shifters.

  • @foxwwweb
    @foxwwweb ปีที่แล้ว +3

    Great work! I feel the Sinclair vibe :)

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Thank you for the compliment! 😄

  • @ezrakornfeld8436
    @ezrakornfeld8436 ปีที่แล้ว +1

    You inspired me to make my own 8 bit computer. I went with the 8080 because I didn’t want to completely copy yours. It’s called the 808E because it sounds the same when you say it.

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      I like the name of your project!
      You can "copy", it's not a problem, the Z80 is very popular, I didn't innovate on that😄
      Keep in mind that powering on an 8080 is more tricky because it requires more voltages than the Z80, which only requires 5V

  • @zetaconvex1987
    @zetaconvex1987 ปีที่แล้ว +3

    I love how professional-looking your board is. You could probably build your own little button controller using some buttons and an off-the-shelf IC. Hardware back in the day was so SIMPLE. I have been mucking around with USB as an experiment. Jeez, could anything get more complicated? For your system, how to you read the controller? Do you bit-bang, use interrupts, or mapped memory?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Thank you very much, I did put a lot of effort in the board 😄
      Making a controller is totally possible! Few buttons, one parallel to serial shift register and that's it. In fact, I was thinking about making this as part of the video at first, but I didn't want it to be too long.
      The hardware was indeed simple and effective. What bothers me in USB is not the protocol itself but more the software stack on top of it that is really complex.
      I do use bit-bang for the controller because we are not tied to timing and because I have a PIO that makes this easy. In comparison, for the PS/2 keyboard I prefered to add hardware shift registers and generate an interrupt everytime a key is received.

  • @GregCoonrod
    @GregCoonrod ปีที่แล้ว +3

    This is such a cool project! I hope to be able to do something like it in the future. Keep up the great work :)

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Thank you very much!
      With time and patience, it's always possible

  • @bulldog8080
    @bulldog8080 ปีที่แล้ว +3

    finally a new video! 🤟😎👍

  • @nuthenry2
    @nuthenry2 ปีที่แล้ว +3

    I wonder if it would be possible to put the rom on the controller interface card and have it auto run the needed drivers, allowing you to use it with any software/games without having to edit the games to have the drivers. you may have to add a config options to the driver so it can work with games that uses different key bindings and maybe a key shift option (press start and the A button is now Z)

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      Putting a ROM on the controller interface is completely possible, mainly since the "User port" has an I2C bus. So adding an I2C EEPROM is simple (and cheap).
      I wanted to show in the video how this controller could be interpreted as a keyboard thanks a proper driver and also thanks to the "open device" interface/layer Zeal 8-bit OS offers, but I didn't want to make the video too long.
      I may also need to add support for dynamic driver loading in that case though. That's doable, but needs a bit of work.

  • @philtoa334
    @philtoa334 ปีที่แล้ว +3

    Nice.

  • @retrogamestudios6688
    @retrogamestudios6688 ปีที่แล้ว +3

    New viewer here, do u upload often

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +2

      Welcome to you! I try to upload once a month

    • @retrogamestudios6688
      @retrogamestudios6688 ปีที่แล้ว +3

      Hey hey, I'll be there can't wait to see what's next. You on Patreon

  • @ratatus5645
    @ratatus5645 ปีที่แล้ว +2

    It will be posible to use the user port for 9-pin style connectors like the sega mega drive or some joysticks?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      Yes! Almost any joystick can be interfaced. However you will need to use the appropriate driver too (or write one) as the protocol is different from the SNES'

  • @Defianthuman
    @Defianthuman 5 หลายเดือนก่อน

    One question is the intro music able to be played on the system?

  • @ratatus5645
    @ratatus5645 ปีที่แล้ว +1

    Are you gonna use fpga for the sound? 'cause there's an fpga emulator for the Yamaha ymf262(opl3)

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      Indeed, I am using the FPGA as a sound card too. It's still in development as there are higher priority tasks to do but the goal is to have an easy interface to generate sound (PSG). What I've done so far is a module that receives a duration, a frequency, a waveform and generates the sound out of this. Usually, sound chips are more complex to set up.

  • @octacore4F
    @octacore4F 10 หลายเดือนก่อน +1

    Does the Controller even work in games? Or do you have to write drivers or something for that?

    • @Zeal8bit
      @Zeal8bit  10 หลายเดือนก่อน

      If the games use the standard input and the joystick is somehow simulating the standard input, it is possible, without modifying the games!

  • @analebanane508
    @analebanane508 ปีที่แล้ว +1

    Hello - I have the following question:
    for what are the 2 "not used" Pins good for?
    I mean are they debugging pins f.e.?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      On the controller side, these pins are not connected to the shift register. On the console side, they are connected are can be controlled by the processor. I guess Nintendo intended to have special peripherals, just like the NES had the Zapper. I don't know if there was such device using these pins on the SNES.

    • @catgirlQueer
      @catgirlQueer ปีที่แล้ว

      @@Zeal8bit there is, the super scope!
      I'd recommend checking out Retro Game Mechanics Explained's video about SNES controllers for more info on what those lines are used for on other controllers

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      @@catgirlQueer Thanks for the pointer! I am going to check this

  • @vidi0816
    @vidi0816 ปีที่แล้ว

    Awesome.... but my old game is nitendo. May convert to wireless joystick ?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      I am not sure to understand. You want to convert your SNES controller to a wireless controller?

  • @DiggOlive
    @DiggOlive ปีที่แล้ว +2

    Is vertical scrolling implemented?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว

      I implemented vertical scrolling for text mode in the FPGA. So it's hardware scrolling.

  • @SuicideJones
    @SuicideJones 11 หลายเดือนก่อน +1

    so we can create visually driven text-based interfaces.. selecting from multiple onscreen options.. being able to navigate intuitively back and forth up and down through menus and sub-menus and such.. can we use start/select to stop/pause a process and open up options?? if i hold down the start button for 3 seconds will the machine reboot?? some would suggest an onscreen keyboard but there is so much more potential here.. can this system support a PS controller?? are there specific controllers it could not support?? will it run DOOM??

    • @SuicideJones
      @SuicideJones 11 หลายเดือนก่อน

      have you seen C64OS?? text-based windowing GUI..

    • @SuicideJones
      @SuicideJones 11 หลายเดือนก่อน

      i want to see C64OS installed over FreeDOS installed over ZEAL..

    • @Zeal8bit
      @Zeal8bit  11 หลายเดือนก่อน

      Zeal 8-bit OS offers an abstraction layer for drivers and standard input and output, so definitely, it's possible to implement a "virtual" keyboard that can be used with the SNES controller. That is one demo I was considering doing to show how drivers work on the OS.
      PS controller can also work, it may be more tricky because they have more sophisticated protocols but if a microcontroller does the decoding job and offers a simpler interface to the Z80, yes, it is possible.
      As long as you allow yourself to have microcontrollers, you can support any controller that has a known protocol, even bluetooth ones (thanks to ESP32-type MCUs)
      The problem of running Doom is that it would need to be recompiled or ported to the Z80, I am not aware of any real port (not clone) of it for the Z80. I is possible, but needs a lot of work

    • @Zeal8bit
      @Zeal8bit  11 หลายเดือนก่อน

      @@SuicideJones C64OS is for the 6502, so it is not compatible with Zeal's Z80. FreeDOS is for x86, MS-DOS isn't compatible either with the Z80 unfortunately

  • @catgirlQueer
    @catgirlQueer ปีที่แล้ว +1

    where did you get the SNES ports from?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      I bought it on Taobao but I am convinced you can also find it on AliExpress

    • @catgirlQueer
      @catgirlQueer ปีที่แล้ว

      @@Zeal8bit I see, thanks!

  • @kirill_bykov
    @kirill_bykov ปีที่แล้ว +1

    4:04 why do you think you need 16 clocks? Did you try 12?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Check the pinned comment 😉

  • @bulldog8080
    @bulldog8080 ปีที่แล้ว +1

    I forgot to ask but do you recognize me from the discord?

    • @Zeal8bit
      @Zeal8bit  ปีที่แล้ว +1

      Haha, yes I recognize you

    • @bulldog8080
      @bulldog8080 ปีที่แล้ว

      @@Zeal8bit oh ok maybe do a shoutout?
      ...... Nah just kiding XD

  • @SuicideJones
    @SuicideJones 11 หลายเดือนก่อน +1

    a part of me thinks it should be an 8-bit NES controller..

    • @SuicideJones
      @SuicideJones 11 หลายเดือนก่อน

      the Game Glove..

    • @Zeal8bit
      @Zeal8bit  11 หลายเดือนก่อน

      Actually the protocol is exactly the same, but with less buttons of course, so only 8 clock pulses are required to read the controller state.
      About the Game Glove, did the NES have any access to the analog values from the glove's sensors? Or where the sensors interpreted in the glove itself and sent to the NES as regular buttons? This can be interesting project too