Connecting my homebrew GPU to Ben's 6502 computer

 Last time I had 'completed' my design for a supremely powerful GPU featuring a resolution of 400x300 with 256 beautiful colours - as I said at the end of that post, the next step would be to ditch the raspberry pi which was currently driving it, and attach it directly to Ben's 6502 computer.

The plan

Since last time I left off with the latest GPU board bodged together with my old counter board, I needed to recreate it with the best of both worlds, as well as attach it to the computer.
Rather than making a gigantic PCB like last time (or even bigger in order to fit all the counter logic on it!), I decided to make a "stack" of PCBs which would be connected by pin headers in order to pass the necessary shared connections between boards.

A 3 board sandwich was what I landed on: bottom board handles the counting, scrolling, vsync & hsync, middle board handles the vram and gpu interface, and the top board is the 6502 computer.

The 6502 computer

First thing's first, I needed to actually build Ben's computer. I bought a 65c02 and 65c22, then threw it together on a breadboard using Ben's exact schematic (no changes this time)


As you can see I was not going for any prizes in neatness; just wanted to make sure I understood how it works, and all my chips were working.

Nothing exciting to report here, it worked fine, so I remade Ben's schematic in EasyEDA complete with the necessary pin headers so it could be stacked on top of my GPU boards.


Creating the PCBs

In theory this should have been relatively low risk. I already had the schematics for the GPU as a whole, I only needed to split it into 2 boards. So that's what I did.

Count, hsync/vsync, and scroll adding:


VRAM (tile and map), color decoding, and VGA output


Ben's 6502 computer with added pins to connect to the board below, and a 5v usb power header. Note the LED was added later, so the actual board doesn't have that



PCB errors

The PCBs arrived; I put little standoffs between them to get an idea of how the final stack would look.




As always, when I populated them, I found a few errors...

The first was the most obvious; I placed the VGA header backwards by mistake!


So I needed to jump some wires off of it and solder those directly to the VAG header; then hot glued it to make sure nothing shorted when wobbled 






I also made another board layout error by putting a 5 pin header for the USB header, but I only have little 4 pin breakout boards, but since I'm not using the data lines for anything I just bridged the ground pin over

Testing the 6502 computer


Next I tested the 6502 computer section of it on it's own, since it's entirely optional to talk to the GPU. I tried running Ben's simple hello world example and got some strange results


Pretty close, but obviously something was wrong. After a little debugging I found the culprit. Below you'll find the datasheet for my RAM chip, as well as my schematic



Notice the CE# and CE2 pins in the datasheet versus the CE and CE2 on the schematic. The schematic doesn't indicate that one is active high and the other active low, and you'll see I'm tying them together, therefore the RAM chip is never enabled, so no subroutine jumps etc will work.

To remedy this, I simply bent the leg of CE2 up, and tied it high via a croc clip (and later soldered a jumper wire to the underside of the board for neatness.


The computer was now verified as working; and I've only had to make 3 fixes so far, which is not bad considering the complexity.

Now to test the GPU and try to interface to it from the computer.

More PCB errors

In the last post I mentioned that I got the enables the wrong way around for the interface demultiplexer; well, seems I forgot to update it in the schematic before copying it across to the new form factor, so I had to fix that again in the same way as before.

Next I found I forgot to pass two signals across boards - namely the enable draw signal between the 2 gpu boards, and the disable draw signal between the GPU and computer. So I added a couple of jumpers to fix those.

After all those fixes, something was still going wrong; after a lot of probing and testing, I eventually found a couple of random traces were shorting.

I took the whole board apart and looked at it (literally under a microscope at one point) and just couldn't figure out why it was shorting. I gave it a quick clean with some alcohol and a toothbrush and lo and behold, the short disappeared. Some of the leftover residue from soldering must have been bridging something.

It's working

Here are the populated PCBs, and finally them arranged in a stack

GPU Part 1:


GPU part 2:


6502 Computer:


Full stack:


Software

I'm very new to 6502 assembly, but I managed to bumble through it to make a couple of demos.

First one is just 2 tiles (one all red, one all green), repeated across the entire 'map', and the scroll registers both being incremented every vblank:


The second demo is 256 tiles filled with each color the GPU is capable of producing, repeated across the screen. It then moves them all left 1 each vblank


The multi coloured square is because my code must be buggy and I didn't write to all the tiles, so it's just showing random garbage in memory which hasn't yet been set.

Emulation

As I mentioned before, I'm very new to assembly, especially on the 6502. In order to smooth out the workflow of writing programs for the computer to control the GPU, I decided to build a 6502 emulator, and a "Matt GPU" emulator, so I could quickly write and test programs on my PC, then transfer them to EEPROM when they're done.

I won't go into the details of how I built the emulator, since it's probably worth an entire write up on it's own, but in summary, I have implemented almost every 6502 instruction, the main missing part (for now) is interrupt handling.

Here is how the exact program above without any changes looks on the emulator; notice how it even includes the random garbage memory tile!



I will be open sourcing it when complete, in case anyone wants to use it for their projects

What's next

There's a couple more things I want to do before I can finally draw a line under this project.

First of all, I'm not happy how the GPU is hard coupled to the 65c22; meaning if you have the GPU hooked up the the computer, there isn't really any room for anything else (input devices, memory expansion, etc) - so I've come up with a new design which will allow multiple I/O devices to be addressed by the computer.

Adding the ability to have multiple I/O devices would mean I could create any "expansion" cards I can think of. Keyboard input, controller input, extra ROM, and sound are some of the ideas I have already, but since it will be just a common interface to the computer, it really could be anything.

I'm in the process of working on that now; hopefully the next post is the last, at which point I'll open source all of this in case anyone wants to use it or expand on it.







Comments

Popular posts from this blog

Upgrading my BenEater inspired video card

BenEater inspired video card

BenEater Inspired GPU - Final Design