Showing posts with label 6502. Show all posts
Showing posts with label 6502. Show all posts

6502 SBC and the Chip Select Epiphany

What did you do during Covid? Me, not much.....but I have been trying to understand computers at a deep level--to augment my digital and hybrid design skills, e.g., ones based on SBCs like a Raspberry Pi, I figure it's a good time to learn how computers really work. 

How phones really work. Analog ones anyway.

Single Bored Computer: where to start? I figure learning retro computer technology, circa say 1980, would help. Modern hardware, with its improved performance, multiple CPU cores, complex GPU's, and so on, follows the same design principles as retro systems but are a lot more complex. Let's start with the old designs. 

OK, what retro rig? After experimenting with an RCA1802 I settled on the Western Devices 65C02 CPU for this learning process, since it's still in production (!), can be clocked at a snails' pace, and is well documented. 

65C02 research led me to a tremendous series of vids from YouTube legend + content creator Ben Eater; he built a 65C02 SBC on breadboards.  Wow! If you are interested in understanding how computers really work, watch his vids; then watch some of them twice. This guy is the real deal.

The mighty Mr. Eater must have put a ton of work into his vids; least I can do is buy his kit (here). "Hands on helps". But you know how I hate breadboarding, so I bought a PCB for the Eater design from PBCWay as well, here.  Here it is partially assembled:

The Eater 6502 parts kit: got that here.....partially assembled PCB, and an SBC external timer. A useful logic probe, based on an Arduino Mega, is also part of the BE 6502 project, vid for that is here.


So far so good, but after finish all the fab, it took me about 3 evenings to get the SBC working, mostly because I rushed and made mistakes. Never rush.  

Stupid mistakes let me count thy ways. First, I got an older version of the PCB, i.e., I clicked "add to cart" to save myself about 2 minutes--but instead, I should have read the project's webpage, downloaded the REV-B gerbers and gotten the REV-B PCB fabbed from that. The PCB's designer clearly states REV-B solves some design issues with REV-A, but I missed it. The author also clearly states: to get REVA to work I needed to add a 3K resistor to the bottom of the board, or the BE pin on the 6502 won't be held high, but, well, I missed that too. Until I used Sigrock Pulseview to determine the 6502 BE pin was kaput, and added the aforementioned kludge, I got zilch from the CPU. Time wasted: maybe 2 hours. Very nice! 

I also put all the LEDs in backwards and also flipped the SBC's reset switch 90 degrees. I see these little 4mm switches all the time but did I really know how their contacts were laid out?  No. 4mm switches are laid as per my drawing below: flip the switch 90 degrees and it won't work.  


During fab I also had a scary moment; I decided to replace the RAM socket with a low profile 28 pin ZIF I had in my junk box, but lifted up a critical trace in the process.  


Fortunately when I soldered in the ZIF and fixed every other mistake everything worked, which means the RAM socket trace must have still made contact--I got lucky. It was a frustrating few evenings, but, troubleshooting the REV-A board, using my PIVISA enabled bench tools, adding the missing BE kludge resistor and correcting other stupid mistakes proved educational; fixing something new almost always is.

Working SBC.  



My current setup for 6502 SBC action. Clockwise from left: ROM burner, LCD, timer, breadboard, and Arduino Mega clone used as a logic probe. In the center is the 6502 SBC.


OK, so, beyond practicing patience during fab, what else did I learn? The crux of the biscuit is understanding basic Von Neumann architecture. That's the internal design most (if not all?) PC's nowadays use, including the Eater SBC.  

(Von Who? No not this guy:)

Not me--"yes I worry".


(Not this guy either:)

Wasn't involved in computer design as far as I know but, hacked strat clones, and is extremely important.


This guy!!

John Von Neumann, who led the team that came up with the basic architecture of a modern PC. All hail-- outrageously brilliant dude--"The Van Halen of Computer Hardware". Fun video re: JvN is here.

In this case: The Eater SBC's CPU, RAM, ROM, and peripherals share common elements: for instance, data, address, and read/write lines. What this SBC project drove home and what I felt I didn't understand is how each device (a RAM chip, a ROM chip, a graphics device, etc.) on the bus is enabled or disabled.  

It's pretty simple: we use logic to trap a range of memory addresses then upon a match select a chip or device so it can read from or write to the shared bus, allowing the chip to do useful things. Otherwise: deselect the chip or peripheral so it leaves the data and bus alone. Once the chip is selected the CPU can communicate other things to it, such as whether to read data from it (eg: OE or "output enable" = low), or write data to it (e.g.: WE or "Write enable = low"). The Eater SBC uses a single 74HC00 chip to trap addresses and uses the 7400s' outputs for selecting the computer's various memory ICs as well as the LCD display for Read/Write madness. 

These logic values, chosen when the PC or MCU was laid out, determines the device's memory map, a computer science term I never really understood. Now I think I get it.

So yes: this week's great chip select epiphany can be summed up in an abbreviated, back of the napkin drawing:


From here we can dig into how each chip, CPU, peripheral etc. works, giving us a way to understand things at a deep level. 

Timing has to be considered--see the vid here--just because a chip or device is selected doesn't mean it will act quickly or slowly enough to make everything else on the bus happy. And of course, you need to understand how the guts of the CPU and attached devices work--study those data sheets--to be able to write useful assembly code. 

Going forward: the PCBWAY-PCB for the REV A Eater 6502 SBC PCB has an expansion bus if you will--it brings useful signals out to a 40 pin header, and better still, there is room in Mr. Eater's SBC design to trap unused memory addresses (say 4000-4FFF?) to add more peripherals, perhaps something audio focused? But that's for a later post. 

OK enough for now. It's Covid so i can't get on the local bus, but now, I can most-def get on the PC's bus. Which means yes, there are fumes, but at least they aren't diesel. See ya.



Retro Computer Audio--6502, Timers, Emulators, and Assembler Madness

Hello again! From a few posts ago, I had an idea to build an Arduino knockoff using an RCA1802. But another tech was already doing it (here), and his work is 1000x's better than mine will ever be, even if I worked on it for years. He even picked a better name for the project. Damn! 

However, my desire to learn more about computers at a deep level continues on many fronts: Von Neuman architecture, assembler, homebrew PC construction, blinkenlights, and yaddah.  

So where to start?  How about a timer? Why/why not? No matter what hardware I'll use for this adventure, I figure I'll need a timer that can step through CPU machine cycles and see if my code is working. Marvey let's build that.


To this end I found a great series of vids on youtube from Ben Eater where he fabs a simple 6502 PC (that's CPU used in old Apples and other early PCs) using breadboards--his "getting started" webpage is here. This is a complex subject, but the author explains things so clearly and patiently that even a tinitous distressed, OCD burdened, over the hill rock and roll guy like me can follow along. 

In addition to 6502 madness, the vid series has a very good series of explanations about how the venerable 555 timer works--part I is here. Mr. Eater uses 3x 555's in a monostable/bistable/astable timing board for his own 6502 machine language "Hello World" project. 

Let's motorize this pursuit! I laid the Eater timer out in Eagle--as I've said many times, I can't breadboard to save my life and slapping together a gerber/getting it fabbed/getting it built is affordable and in the long run, seems more expedient. 

For this timer board--didn't work the first time, I made a few dumb mistakes, but 2nd go at it, the PCB works 100% as far as I can tell; he's the schematic:


And the board....


A couple of useless build photos:



It works. I have a gerber for this....if you want it, ready to send off to your favorite fab shop,  comment below, we will figure something out. Important! if you build this board make sure to tie HALT to ground to allow the circuit to work reliably, or wire in a switch between 5V (off) and Ground (run) to HALT. For my build I ran a 22 gauge jumper from GND to halt which is not shown in the photos above.

OK now what?  I bought a kit for the basic Eater 6502 hardware kit (here, scroll down the page) and this PCB for it (here, there are others) but while I'm waiting I figure I can get my feet wet with a 6502 emulator. There are lots online but I really liked the one here; it's simple--download the js and html stuff, stick the files on your PC, open with Chrome, and you're off.

Using that, with help from some vids, I created my first assembly language program--for me, the first one ever. Who needs hardware?   

OK the code below paints the background of the emulator's screen in whatever (limited) color you choose. 

Assembly language in general is unlike anything I've coded with before, but with assembler we're baking things down a very simple form, and as a reductionist, that's A-OK by me. Once I got the hang of this what you see below wasn't that hard tp figure out, and I figure assembly for relatively simple processors like this, for certain things, might be easier than C?  No mallocs, crazy pointers, C++ objects etc. anyway. Just goofy 3 letter codes, right?

So here is the code:

;LDY #$00 ; load offset Y 1 NOT NEEDED already 00?
LDX #$02 ; load h02 into X
STX $11  ; put X into special RAM MSB
LDY #$00 ; load offset Y 0
LDX #$02 ; load h02 into X
STX $11  ; put X into special RAM MSB
LDX #$00 ; load h00 into X
STX $10  ; put X into special RAM LSB
LDA #02  ; color of pixel to draw
STA ($10),Y  ; indirect memory addressing 0x0200 to get to 16 bits…..
JSR draw1

LDX #$03 ; load h03 into X
STX $11  ; put X into special RAM MSB
LDX #$00
JSR draw1

LDX #$04 ; load h04 into X
STX $11  ; put X into special RAM MSB
LDX #$00
JSR draw1

LDX #$05 ; load h05 into X
STX $11  ; put X into special RAM MSB
LDX #$00
JSR draw1

draw1:
INX     ; increase X register by one
STX $10 ; put that into RAM LSB
STA ($10),Y  ; store A register (color) to screen
CPX #$00     ; compare, is X at h00?
BNE draw1
RTS

I am not sure the code above is as optimal as it could be but it works.

Going forward: Next up is build the Eater homebrew 6502. To further flesh this out I have some ancient Analog devices parallel A to D's, it would be interesting to see if I can get those going with the home brew 6502 circuit.  

OK which begs the question: Why can't I just use an Arduino to learn how computers work at their deepest level?  Anything I can do on a 6502 can be done on a modern CPU, right? But the 6502 makes me feel as I am starting out simple. And best of all: For me, it's like, well, you know: all new, no matter what.

OK that's it, until next time don't breathe the fumes.