This is a tale about embedding a 6502 microprocessor into an FPGA. A 6502 is a old 8-bit microprocessor. It was in its prime in the late 70's and early 80's. It powered some very famous computers like the Apple II, the Commodore PET and C64, the Atari 800 and Atari video computer system.
Modern Field Programmable Gate Arrays (FPGA) chips can easily hold all of the circuitry that went into making not only the 6502 microprocessor, but all of the peripherals needed to build a computer from that time frame. I wanted to build up an old computer, using the 6502, that would contain some RAM, some ROM, and a UART. I wanted the design to fit entirely in the FPGA. I wanted the design to be easily movable between FPGA families (ie: Xilinx, Altera, or Microsemi).
Step one, I did not want to write much code for this project. I just wanted to get a computer up and running in an FPGA with as little effort as possible. So I went looking for code. I needed a 6502, a RAM, a ROM, and a UART. I found several 6502 processors at Opencores in addition they also had the UART. The RAM came from a quick google search. The ROM came from a program that one of the 6502 processor coders wrote in the form of a C program that would convert the binary output of an assembler into a VHDL file that instantiated a ROM.
Step two, An FPGA development board. I had a NEXYS3 board from Digilent (I also see that its already out of production). This board contains a Xilinx Spartan 6 FPGA. I started this project using this board. Later I migrated the design to a Microsemi board that contained a ProASIC FPGA.
Ok, so I started with a single 6502 processor core. I built up the system by connecting together the various cores. I wrote a very small looping program in assembly and placed it into the NEXYS3 development board. It worked!, well not at first. I had to change the RAM model so that it did not register the read address. The 6502 needed the read data sooner in time, so the registering of the read data caused it not to work. So great, now what. Well searching the web, I found a version of Microsoft Basic, written for the Ohio Scientific computer, which used a 6502. I figured I would embed this basic language and have a small embedded computer that runs the basic language. I figured the only thing I would have to change would be a small amount of code for the input/output routines. I would have to write code to make the computer use the particular UART that I had embedded into the system. I did this, rebuilt the system and its worked, well not really.
So the system worked, somewhat. It was working a little, but you could see that it was "messed" up. When I had compiled the Microsoft Basic, it had a couple of instructions that did not exist in the 6502 instruction set. I had looked into these areas of the code and thought that I had fixed them to be correct. Now that the system was messed up, I figured that either I did not have a good copy of Microsoft Basic, and/or that I had fixed it incorrectly. So how to fix it? Well searching the web led me to a site that has a way to build several different versions of Microsoft Basic. (To be continued)