Getting it alive

Some time ago I posted on Facebook and Twitter that I was working on a second book, this time about building 8-bit computers, and I asked them what processor they would be most interested in. I gave them a choice of tried-and-true pieces: the Zilog Z80, the MOS 6502, the Motorola 6809, and the Intel 8085.

Truthfully, I didn't want to get into the Z80 or 6809 right off the bat; those are very powerful processors. I had a vision of starting with a complete classic, either the 6502 or the 8080 – and since the 8080 processor and its supporting circuitry is a chore on so many levels, from being hard to find to making the design unnecessarily complex, I offered the 8085 instead.

That almost nobody wanted the 6809 is not surprising, almost nobody knows this processor. But I was surprised that the Z80 wasn't such a clear winner (on FB it was, but there were only two choices) and that the 8085 held the top spot for a long time. Until I wondered if the voters were mistaken and thought it was the 8086… Well, the 6502 paid the price for the irrational dislike that the Czech computer community, addicted to Sinclairs and Intel processors in general, probably feels towards it.

So I finally reached for the 8085. This processor is a significantly improved 8080 and except for the multiplex of addresses with data it is easy to use. Plus, unlike the 6502, it separates memory and peripherals into separate compartments, which simplifies the design a bit.

So one fine day, I sat down and started to build.

A processor here, memories there, an address latch in between, an exciter and data bus separator, an ACIA MC6850 circuit, an LED for the SOD output to flash when it's supposed to, and finally an 8255. A thing of immense beauty on the face of it, so I routed it manually in Eagle for a while, but then I figured screw it, the Chinese would do it anyway for four crowns apiece, so I put the Autorouter on, let it run, eyeballed it, was horrified at the furious pulling of lines, and – come on, the beagle bears!

After a while, the processors and other parts arrived, and even the board package. So last weekend I started soldering.

Awakening, day one

I started nice and slow: CPU socket (two hollow strips to be exact, I have good experience with them), memory socket (I had two „precision sockets“ DIL 28), jewelry around RESET (button, capacitors, diode), crystal and two resonant capacitors.

Stumbling block number 1: I took the capacitor values from the 8085 datasheet, but for the CMOS version. And then, when I took a good look at what the Chinese had sent, I was almost fooled: M5L8085AP! The NMOS version. Fortunately up to 6 MHz, which is gut, but still! The problem is that the NMOS version wants 6.8 pF capacitors.

I measured the sockets to see if the supply voltage is where it should be. It was. I plugged in the processor. Thanks to the circuit board, I didn't have to worry about interrupt signals, they were neutralized. I just wondered if the oscillator would oscillate and if there would be anything interesting at the CLK output. There was, folks, there was! I tried RESET again. It worked, too.

So, I kept plugging away. I tried the minimal version, i.e. with an address latch, data bus separator and EEPROM memory, which had a simple flashing program that was supposed to flash an LED at 1 Hz, but without using any subroutines (I didn't set the RAM).

And nothing happened. Of course, how else… I mean, respectively on the buses something was happening, but completely strange, and the output of the SOD was still 0. Well, after a while, even that strange thing changed…

What the hell, I'll look for the cause. I'm looking at the EEPROM wiring diagram. The /ROMCS leads are there correctly, the pins are connected correctly, the /RD signal is connected correctly, the /WR signal is connected correctly – wait, what? What's the /WR signal doing there? There should be a logic 1!

Stumbling block number 2: Stupid!!! I look at it three times, RAM on the left, ROM on the right, and then plug /WR to another chip anyway. So RAM was write disabled and ROM was happily writing. I stuck the EEPROM in the programmer, read it pro forma – and there was a ton of nonsense! I rewrote it. But at least you could see that the processor was working somehow.

I scratched one connection and plugged in two wires. Still nothing.

I keep looking at the data, and I keep thinking there's something wrong with it. Out on the data bus was all ones, in… eh… wait a minute!

Stumbling block number 3: Stupid squared! The 245 bidirectional exciters have an enable input, I connected that to ALE, and then an input that gives direction. When it's 0 it lets left to right, when it's 1 it lets right to left. I remember keeping one eye on the datasheet and the other on the Eagle and thinking: If it's 1, the data goes from here to here, that means I'm going to put the /RD signal here, when it's at 0, the data has to go like this… I'm going to eat, I'll come back, what am I going to do… Oh yeah, the /WR signal, I'm going to plug in here, wait, really? Well, when it's 0, it's 0.

I scratched the connection, soldered the wire, started – SOD set to 1!

Oh, it's alive! Yay. It's alive, but it's not sucking. But something did happen!

I pulled out the logic analyzer and started measuring and detecting. I kept getting the feeling that there was too much FF on the bus.

I pulled the bus exciter and replaced it with wires. Let me minimize possible trouble spots. Then I also shortened the program, just to the absolutely necessary loop, without waiting. And it ran! I added more RAM so I could test more complex programs…

It was already ten o'clock at night, so I postponed further experiments until a public holiday.

Awakening, day two

I found that damn 6850 circuit. I knew I had it, I knew I had it in a non-soldering field, but I had no idea where the field was. I finally found it and I see it's a version MC6850. I mean, embarrassing, because this version is guaranteed to run up to 1 MHz, and I have a 1.8432 MHz cpu in there. I need the MC68B50 version, which is rated to run up to 2 MHz. But Grant Searle claims, and I have no reason to disbelieve him, that nonB versions work at that frequency. So we'll see, I'll give it a try, and if not, I'll just wait for the „B&#8220chips&#8220that are on the way.

„Additionally, all of the standard 6850 chips that I have worked perfectly at the speeds required for this circuit even though the circuit requirement is faster than their specification. Therefore, you are unlikely to have any issues. However, I would recommend you buy the „B“ speed grade ACIA ie. 68B50 if possible.“ – Grant Searle

Připájel jsem tedy dutinkovou lištu coby patici pro 6850, do EEPROM nahrál „Hello world“ pro sériový port a jedeme testovat.

And nothing happened, of course.

Logic analyzer in one hand, oscilloscope in the other, reconnect, and off we go!

Finally, I watched the addresses as they went down the address bus and the data that went there. And indeed: address 0, data $F3 – that's DI. Then address 1, 2, 3 – LXI SP, $FFFF. Address 4, 5 – MVI A, $15. So it's live…

At addresses 6 and 7 is OUT $DE – ACIA setting. Here the data bus wobbled for a while…

Oh, actually: ACIA is already sending data, but it hasn't finished ALE. Oh yeah, the bus separator isn't there, there are wires instead. Wires out, separator in, in we go!

Everything's running. 0, 1, 2, 3, 4, 5, 6, 7, $DE, 8, 9, A, B, C, D, E, D, D, C, B, 8, A, 9, 8, … And that's weird… Why is it counting up and down?

At addresses 8, 9, A is LXI H, HELLO, at addresses B, C, D is CALL $1C. Clearly, E and D are stack addresses in RAM, where CALL stores the return address (because I initialized SP to $FFFF and the processor decrements first, then stores). Then C – since I'm only tracking four bits of the address bus, that's 1D – and that's where the MOV A,M instruction is.

But there isn't. According to the data, there's something that has all ones in the lower bits, here $xF.

The hunch has become obvious! It reads FF from memory, which is instruction RST 7. It stores the return address on the stack (C, B) and jumps to $0038. That's the eight. And there it reads $FF, so it stores again on stack (A, 9)…

Memory! Aren't the pins swapped somewhere? It looks like the address pins have been swapped. According to the schematic everything is OK, I'm still consulting the datasheet. Everything fits;

Stumbling block number 4: Inattention! I look at the PCB, I look at the EEPROM pin by pin, and – damn, why is A4 and A5 connected? And there is no signal going to the A5 input! Oh, so instead of the $1C address, which was correct, the memory was reading the $3C address, which was already all $FF!

Scratching, soldering wire… I'll measure it again. Everything fits. I plug in the EEPROM, check it again for good measure and – wait a minute, one input seems strange! It's like it's beeping halfway!

Stumbling block number 5: The pin in the socket was connected, but there was no signal on the memory pin. On the pin, yes, but not in the pin. Damn! Stupid „precision socket“! I don't think I can unsolder it anymore. But for next time and for you: don't use them! I'm not the only one who warns about them, and it's my stupidity for not heeding the warning!

I connected the memory pin at the damaged cavity to the correct signal and started the machine. Everything ran as it should, at least judging by the addresses.

Which also explained, by the way, why the flashing with the timing loop did not run, but the full speed flashing did: because the „full speed“ code was short and fit into 16 bytes!

I connected one measuring probe to the TxD – and there was really something going on!

So I plugged in the USB-to-UART converter, full of anticipation, ran the terminal – and nothing…

Yet according to the measurements it… echm… but somehow slow… So the clock speeds matched, only the times the analyzer showed indicated that the transfer rate was 700 Bd. How is that possible?

Well, see Stumbling Block 1 below. The oscillator oscillated slower. All I had to do was turn it off and on, and it ran beautifully at 28800. But I'll have to reduce the capacity, or wait for the CMOS version of the processor.

And if it works for me, it'll work for you! Next week, as a sort of taster from the new book, I'll post a couple of chapters on the design of this computer.

0000                          .ENGINE   alpha   
0000                          .ORG   0   
0000                          ; init()
0000   F3           COLD:     DI   
0001   31 FF FF               LXI   SP,0FFFFh   
0004                          ; serial port
0004                ACIA:     EQU   0DEh   
0004                ACIAC:    EQU   ACIA   
0004                ACIAS:    EQU   ACIA   
0004                ACIAD:    EQU   ACIA+1   
0004                ACIA_TDRE:   EQU   02h   
0004                          ; ACIA init
0004   3E 15                  MVI   A,15h   ; 115200 Bd, 8 bit, no parity, 1 stop bit, no IRQ
0006   D3 DE                  OUT   ACIAC   
0008                WARM:     
0008   21 2B 00               LXI   H,HELLO   
000B   CD 1D 00               CALL   STROUT   
000E   C3 08 00               JMP   WARM   
0011                SEROUT:   
0011   F5                     PUSH   PSW   
0012                SO_WAIT:   
0012   DB DE                  IN   ACIAS   
0014   E6 02                  ANI   ACIA_TDRE   ;bit TDRE - if it is =1, we can transmit
0016   CA 12 00               JZ   SO_WAIT   
0019   F1                     POP   PSW   
001A   D3 DF                  OUT   ACIAD   
001C   C9                     RET   
001D                STROUT:   
001D   7E                     MOV   A,M   
001E   E6 7F                  ANI   7Fh   
0020   CD 11 00               CALL   SEROUT   
0023   7E                     MOV   A,M   
0024   E6 80                  ANI   80h   
0026   C0                     RNZ   
0027   23                     INX   H   
0028   C3 1D 00               JMP   STROUT   
002B                HELLO:    
002B   48 45 4C 4C 4F 20 57 4F 52 4C 44 0D 8A .ISTR   "HELLO WORLD",0Dh,0Ah   

Comments powered by Talkyard.

Martin Maly

Martin Maly

Programmer, journalist, writer and electronic hobbyist. Vintage CPU lover. Creating new computers with the spirit of 80's.