Keyboard and Storage Device?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
noyen1973
Posts: 32
Joined: Sat Oct 06, 2018 10:15 am

Keyboard and Storage Device?

Post by noyen1973 »

Has anyone been able to interface a PC keyboard to the game port or some kind of storage device to the Super NES?
The scan codes from the Xband keyboard look identical to a PC keyboard and the pin outs are pretty much the same as PS/2 and USB with vcc, gnd, clk and data. FAT16/32 has been implemented in 6502 using SPI mode with SD cards. Can the same be done for the Super NES using one or both of the game ports for IO?
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Keyboard and Storage Device?

Post by tepples »

You'd need a microcontroller (MCU) to link the two, as both the Control Deck and the keyboard want to be generating the clock signal. Years ago, tpw_rules was working on a PS/2 to NES/Super NES controller bridge, with a mouse mode and a keyboard mode, but college interfered.
nocash
Posts: 1405
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: Keyboard and Storage Device?

Post by nocash »

To play by the rules, an SD card adaptor should have voltage conversion (for 3.3V supply/signals).
Without extra logic, the SNES could read about 1 byte per 150 cpu cycles via SPI.
That would be maybe 20Kbytes/second at 3.5MHz for opcodes in FastROM (and less MHz for controller access and main ram).
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Keyboard and Storage Device?

Post by tepples »

That sounds about right. Assuming the SD card uses SPI over controller 2 bit 1, with a passthrough receptacle to connect actual controller 2 to bit 0, I count 92 master clocks per bit, or 32 + (108 * 8) - 6 = 890 clocks to read a byte, less than one 1324-clock scanline. (Correct me if I'm wrong.)

Code: Select all

  ; Assume sep $20 and fast ROM
  lda #$01   ; 12
  sta tmp    ; 20   ; loop counter: once this 1 reaches carry, we're done
loop:
  lda $4017  ; 30   ; 401x access takes 12 clocks or two fast cycles
  lsr a      ; 12
  lsr a      ; 12   ; select adapter (bit 1), not player 1 (bit 0)
  rol tmp    ; 36
  bcc loop   ; 18
             ; -6   ; last untaken
Equivalent NES code runs in 60 + 192 * 8 - 12 = 1584 clocks, just over one 1364-clock scanline.

Code: Select all

  lda #$01   ; 24
  sta tmp    ; 36   ; loop counter: once this 1 reaches carry, we're done
loop:
  lda $4017  ; 48
  and #$08   ; 24
  cmp #$01   ; 24   ; select adapter (bit 3), not player 1 (bit 0)
  rol tmp    ; 60
  bcc loop   ; 36
             ; -12	   ; last untaken
This is why a few SPI-on-NES proposals give the SPI serialization job to cart hardware.
noyen1973
Posts: 32
Joined: Sat Oct 06, 2018 10:15 am

Re: Keyboard and Storage Device?

Post by noyen1973 »

Loading 20Kbytes/s is not that bad if you were going to implement some kind of interpreted language like Basic. A banks worth of Basic code can go pretty far even if it's full of data statements. Audio is pretty limited since the SPC700 only has 64k, ~3 seconds to load. Only graphics data takes up a lot of space and the intent is not making a commercially saleable piece of software. As a learning tool it would be quite appealing for a kid to write something on a console that was intended just for video games. Some built-in tools like a tile/sprite editor, music tracker, assembler and disassembler/monitor to complement Basic would not require much room in ROM (a bank each). Everything could be done right on the Super NES without touching a PC.
Post Reply