Software SPI

Note: The following is a repost from Mike Kohn on one of his projects with the W65C265SXB.  He also made Java Grinder, which works with the 6502/65816.

There are at least two famous robots that run on 6502: Futurama’s Bender and The Terminator. I thought it might be fun to write some 6502 code for part of one of these robots, so I downloaded a sound sample of The Terminator and loaded it on this chip along with some code to communicate with an MCP4921 DAC chip.

I wrote two programs here, one with a very generic software SPI and one optimized for playing sound. I’m not sure if anyone would care if I used a sound sample from The Terminator, so I left it out of the git repository. To assemble this project, download a .wav file and run the following commands:

sox ill_be_back.wav -b 16 -r 4000 out.wav
./convert_sound out.wav

The convert_sound program is included in the EasySXB git repository. It converts 16 bit sound samples from a .wav file to 12 bit DAC format (a big endian 16 bit number where the upper 4 bits are always 0x3 and lower 12 bits are the sound sample). In the play_sound.asm source file, uncomment the .binfile line and comment out the .db line. Type make.

To hook up the MCP4951 SPI DAC chip, connect:

  • 1) Vdd to +5v (P4x Pin 1)
  • 2) /CS to P40 (P4x Pin 3)
  • 3) SCK to P41 (P4x Pin 4)
  • 4) SDI to P42 (P4x Pin 5)
  • 5) /LDAC to GND (P4x Pin 2)
  • 6) VrefA to +5v (P4x Pin 1)
  • 7) AVss to GND (P4x Pin 2)
  • 8) VoutA to 10uF cap to amplifier

Source:
software_spi.asm
play_sound.asm


Here’s a 6502 programmed to be a part of The Terminator. Note that when I’m running this program I press JSL instead of JML. JML jumps to the location while JSL jumps to the location as a subroutine. The rts instruction should bring control back to the ROM when speech stops. https://youtu.be/di7iV8C51F4.