This is Hacker Public Radio Episode 387 for Tuesday 7 March 2023. Today's show is entitled, People Builds a Computer. It is the 20th show of Brian in Ohio and is about 34 minutes long. It carries a clean flag. The summary is. Brian starts the process of building an 8-bit retro computer. Hello Hacker Public Radio Brian in Ohio here. I'm out from under my rock and I'm doing another group of shows on a project that I've become interested in. So, you might notice the title of the show is, Peepaw Builds a Computer and you might answer ask yourself who's Peepaw, well, that's me and at least that's who my grandson who's two years old has started calling me. He calls me Peepaw and I've thought, you know, I've meant a little bit into computers and electronics and hobby stuff and I'm thinking maybe some time in the future when he's a little older, be fun to show him a computer that he, if he wants to, wants to could build and we could build it together. So to get a little bit of a lead turn on this, I thought maybe I should go through this. Myself and document it on HPR and as a template, as some notes to myself in the future when me and my grandson might run through this project together in real life. So why a retro computer, there's a couple of reasons, first is I think that an 8-bit computer is a computer that anybody could put together and kind of really delve into the inner workings of a computer. What you do with a microcontroller too and but it's being more, a microcontroller having all of its components inside of itself, it's a little bit more interesting to have all the peripherals and everything on the outside and having to put that stuff together. It gives you some real understanding of what's going on at a real foundational level. So then I, you might ask why the Z80, I grew up using Commodore 64s, which are 65 or 2-based, but when you look at the cost of a 65 or 2-chip now, they're about $15, whereas the Z80 is less than 5 and so cheap is a important part. I think having something that's inexpensive, they can do the take care of the goals that you want to meet, that's the way to go there. A 65 or 2-zanzi 80s are both still available, they might even, I think the Z80s, I know they're still making them, I don't know if they still make them in the, in the dip packages that they're going to use for this project, but certainly they're out there and easy to get and and did I say their cheap, yeah, their cheap, so that's the way to go. So a plan is to, I want to build this from scratch, there's certainly lots of kits out there, there's lots of very well done boards and tutorials online and I've looked at a lot of those things and I'm garnering knowledge from them, that's great, but I want to build this from scratch, I want to be able to point to this thing and say, yeah, I put that here, I did this here, I made this mistake there, things like that. And so the real template that I'm using is a computer called the Tech One, the Tech One was introduced in the 80s at Talking Electronics magazine, so Talking Electronics was an Australian magazine that didn't last that long, 15 or so issues and in three or four of them, they described this computer, this is the 80 computer that you can build. It looks a little bit like a Kim one, Kim one was a single board computer that was built by Moss Technologies, basically as a marketing device for their 65 or two chip, so the Tech One uses a Z80 and there's all those issues are available on the website, basically everything that the founder of Talking Electronics's name is Colin Mitchell, he's basically put everything that he ever has done out in the public domain and he encourages people to use his ideas and use his stuff to build projects and learn about electronics, kind of a cool idea. I think it had about free culture long before, well long for it was really a popular to say open source like it is now. Another book that's out there is called Build Your Own Z80 Computer, it's 1981 book written by Steve CRSEA, CRSEA, it's available at archive.org, there's links for all this stuff in the show notes and that book's kind of a good foundation of a good roadmap on how to build something a system starting from nothing. There's things in it that aren't going to be applicable, some of the RAM, he uses dynamic RAM and I probably won't use that although I might and the feet might maybe I don't know, but there's other things and there's parts that he uses that have been and you can find that are hard to get and you'd have to substitute, so those are just some of the little things you have to, as you go along with figure out how you're going to do it and how other people maybe got around some of the problems. To get started, I'm going to do the most basic thing is I'm going to build a no-op tester which I'll explain here in a few minutes, but there's a link at the Z80 dot info site and it shows a picture of a no-op tester and we're going to, I'm going to do that, but I'm going to do it not with hardware, I'm going to use software and like I said, I'll explain in a second. So I also want the system to be expandable, I want it to be able to grow and try to see a push limit, see how far I can get with a building a system like this, I want to keep the cost down, so that's always going to be in the fourth front of the idea and even if it's more difficult but a little bit less expensive maybe I'll go with the more difficult route and eventually what my goal would be to work up to a system like the Jupiter Ace, so Jupiter Ace was a computer that was built in the, again, around the same time in the 80s, see if I can pull up the page here, yeah, it's built in the, oh, 82, a computer that looks a little bit like the Sinclair ZX, ZX Spectrum or ZX-81, both computers that really don't have any knowledge of, I never, you've got to use those things here being here in the United States of America, but the Jupiter Ace, it's big difference, well there's lots of differences, but one of the main difference from a user perspective then compared to the ZX-80s or 81s is the, that it boots into fourth and if you haven't noticed, I do like fourth as a computer language and so whereas other systems were booting into basic, the designers of the Jupiter Ace had booted into a fourth environment and used fourth for its main interaction with the computer, so that's the plan, so how to get started, to get started I'm gonna build a no-op tester and do a no-op test on a Z-80 chip that I have right now and to do that I'm gonna use an Arduino Mega board and some forth to spin up the most basic Z-80 system. Now again this is not a new idea, there's a project at 8 bit force that's called a retro shield and they have a shield for an Arduino Mega that you can do basically what I'm gonna do right now, but I don't want to use the Arduino IDE, I'm happy with fourth and I understand fourth and I think fourth is a better way to go with a microcontroller anyway, so that's what I'm gonna do, but it turns out no-op test is pretty, pretty easy actually, if you give a Z-80 chip a five volts a clock and the right data on the data bus it will just happily start running through its address space doing nothing, it's basically it does no operation a no-op test and so that's that's what this this episodes about actually is to get a no-op tester functioning, but there's actually another step back from there, most of the no-op testers that you'll see out there use LEDs and resistors and probably some kind of external like a five five five timeer for the clock and put those things together to do the no-op test and what I want what I propose doing is to use all of the capabilities of the Arduino Mega board in order to not have to use any not have to use any LEDs or I think this is just actually my goal here is to use an Arduino Mega that is a subtlest breadboard, the Z-80 chip and just a few wires to get the to get the job done to see if this chip actually still works and in order to do that I'm going to make a logic probe and specifically a logic probe a software logic probe in fourth basically what I'm going to make is a frequency counter using the facilities of the Arduino Mega to do that. If you don't know what a logic probe is there is a link in the show notes for that and for but for this episode I've actually went to an app note that's available at the micro chip, micro chip website which micro chip bought acquired at mill which was the makers of the at mega chips and but they acquired all of their app notes and everything so there's an app note DOC 8365 and it talks about using a AVR micro controller as a frequency counter and in that in that app note there's a section about using a gated method to to do frequency counting and so to what that means is we're going to you're going to get whatever you're going to use it what they call an external interrupt to count how many times something how many times something cycles from high to low and in for a certain period of time and then if so they use a hundred milliseconds as a as a as an idea and then if you if you take that how many times you counted it a hundred milliseconds you multiply by 10 you get a frequency pretty simple system and so they're in the flash forth at the flash forth website there's a tutorial on counting button presses and that's pretty helpful in designing this frequency counterless logic logic pro and there's a link in the show notes for that too just tells you how to how to set up some registers on a different kind of chip a picture but you know it's with a little bit of thought you can easily set it up on an AVR chip or old AVR chip and add mega chip so this project's going to need an Arduino mega running flash forth and Arduino mega is the reason to use that versus the regular Arduino Uno is because of the amount of of IO the amount of pins that are available on it the Arduino mega has four 16-bit timers to 8-bit timers it's got 50 pins as in that you can use this input and output so there's plenty of IO space to interact with a Z80 chip some of the other things you'll need to do this project is the data sheet for the at mega 2560 link in the show notes some jumper wires and a Z80 a solderless breadboard which I should add that to the show notes here I'll do that add that there solderless breadboard so I've done this I've written some fourth words to solve this problem fourth is a problem oriented language you start with the base dictionary and then you create words to solve the problem that we have so the problem that we have is I wanted to be able to make a software logic probe and so logic probe but it's very simplest we'll tell you you can probe inside of a digital system and see if a pin is high whatever the high voltage level is in this case it'd be five volts or low which is ground so in the or zero volts and or if the pin is pulsing if it's transitioning through those states it's not going to give you a frequency and that's really not its point the point is hey is there activity on that pin is there or is it just high or low and with that you can do some diagnosis it's a troubleshooting device and that's what we're going to use it for too but we're going to set of buying one which you can still do easily they're not that expensive we're just going to use this Arduino mega to do those things and so in order to do that I think I mentioned this before the best way to look at initially yet if you're just glossing through some fourth code which is here in the show notes it's to start from the bottom the the bottom most word is probably the most is probably the word that will get you the farthest understanding what's what's going on in this in this collection in this vocabulary and so the first the bottom most word in this a little bit of code is sample pin and so sample pin it says the line sample pin has first off it has a little parenthesis and a couple dashes and that's a kind of a that is a fourth standard no not standards not the right word of fourth yeah I guess standard it's it's a call a stack effect comment basically what it's what it says is that this sample pin has nothing coming in on the stack and it leaves nothing on the stack what it's done and so what it does is it calls a word open gate it then waits it then closes the gate and then it calls a word process data so it's this this sample pin is defined by these four words open gate wait close gate process the data so if you if you listen then you know that this is this is what we talked about in the frequency counter you know open a gate wait for a period of time close the gate and then we're gonna look at see how many counts we got to see what frequency this pin is oscillating at or if the barring that if there's no oscillation is it high or low so then if you look up a little bit there the first word they see above sample pin is wait wait it says a hundred milliseconds and it hasn't again no stack effects and in flash fourth although MS is a word stands for milliseconds and basically it's just I think Arduino has this too you give it a number and it pauses for that many milliseconds doesn't do anything just a just a delay function so in this case it's a fixed one hundred milliseconds that's what I'm using as the wait time and then it then it closes the gate so let's take a look at open and closing of the gates those are a little bit higher up opening the gate I guess maybe now would be the best time to just think a little bit about what's this fourth code the the first thing to think about is constants and the constants are declared higher up in the in the in the in the code and the first line of that has word constant is this is this line that says dollar sign 100 constant pin H and so these this is where I'm using a constant merely as a labeling system for these ports that the that are defined in the in the at mega data sheet and so if you're not if you don't really know this you all of the functionality of a of a microcontroller is controlled through the manipulation of these registers and in the at mega 2560 there's there's 100 there's there's now that 100 now it's a hex number hundred hex numbers of these mapped into RAM and so the if you look at the data sheet the what you'll see at the there's a section called registry summary it's the bottom of the data sheet and it has all the registers and some of the registers just take a full eight-bit number and some of them are broken down where each bit in that in that eight-bit byte that is that register has causes sets up a function of some peripheral be it the serial port the the timers which is what we're gonna use here the whether or not there's interrupts or whether or not the pin is can be used to input data or output whether or not you're gonna do pulse-width modulation so in when you're using Arduino and you set up something like digital pin X and it's as an output you're you're manipulating the registers but it's but it's it's obviscated from you it's it's it's you're not directly unless you dig into it you won't really know what's going on but in fourth it's all exposed to you but in that you also need to make sure that you have to make sure that you understand what's going on because you can make things quit function that you need to function but anyway so I've defined some constants here and to and to use those as labels because sure as easier to say hey I want to make a pin on port H high easier than remembering dollar sign one or two and and then there's so there's a quite a number of these that I define as constants and they consist of the the ports that we're gonna need for this project and the ports we're gonna use are port H port H has three registers connected to a pin H DDR H and port H they're at X 100 it's X 101 and X 102 we're gonna use the timer counter register four which is at X A 0 A 1 and A 8 and we're gonna use port E which is has its three registers at X 2 Charlie 2 Delta and 2 Echo and lastly we're gonna use the external interrupt control register for pin where is that pin that's on the e port on port E and then we're gonna use there's a mask to do some pit manipulation I'm sorry that yeah there's a mask to do some controlling of that of whether of how that pin sees inputs and what it's what it should do so those constants are defined there there's a couple variables also a compare is a number that a compare is gonna be a value that we use and count is a value that we're gonna use and in fourth when you when you use a constant if I use it's after I've defined it if I if I type in pin H after I just the fine pin H what it does is it'll put the value that pin H has in it on the stack which is a dollar sign 100 in this case with a variable a variable because you can you can change the the contents of a variable do you when you put a variable's name when you call it it puts it initially just puts where the value is stored what register it is and then you use a couple of other words to decide what you're gonna do with that those words are the at symbol and the exclamation symbol and those stand for fetching store the at the at sign fetch fetches the value from that register and the the exclamation point store stores a value into that variable a couple other fourth words that we're gonna use for this is m set m clear and m test those are unique to flash forth those are to help with bit manipulation in a microcontroller like the like the at mega 2560 we're also going to use a timer the timer we're gonna use this timer four timer four has the ability to toggle the value of pin 6 on the Arduino board higher low in the background at a certain frequency and we're going to use that for initially as a test function just to test to see if this logic probe is going to work and lastly we're going to use that e that external interrupt register to to manipulate pin 2 to I think it is pin 2 on the board on the Arduino mega board we're going to use to to use it as a external interrupt device the meat of the logic probe will begins at the word ext4.IRQ it's an interrupt routine that that when there's an interrupt on that pin it's going to increase the count the value in count by one it fetches count increases by one stores the value back in the count the logic probe itself is initialized with a few words that are in the defining the word logic probe in it and what you're doing is you're setting up timer register four to do what they call CTC mode what it does is it runs a timer it has a compare register it just continuously compares that number to what's in the in the timer and when the number hits the timer count it toggles the value that's on pin six and then resets the timer count it is zero and then continues to do that it does that just in the background so what we're doing is we're setting up a timer we're getting it to toggle this pin high and low and then we're going to do some other stuff and this is this is where the microchips are well or where things like in Arduino you don't necessarily see this but it's stuff that runs in the background it's not really they're not interrupts they're actually peripherals running in the background that the the the the micro processor works and queries what it needs to what when you need it to to acquire it the the rest of the logic probe in it is just to set up the the correct pins is inputs or yeah inputs and outputs and to set some pull up registers and then and it attaches that interrupt routine to the interrupt vector table and to to make to fire off that interrupt what it happens so in the there's some I they to find a few other words start clock and stop clock that's that's just to start and stop timer 4 you can there's a word set frequency that allows you to change the compare value to change the frequency of the what's happening on that pin there's a pin high and a pin low and that basically allows us to set the value at port h to higher to low to test out the the logic probe and then there's those words open gate and close gate open gate sets the count to zero starts the interrupt routine and then you and then close the gate shuts off the shuts off the interrupt routine and then in processing the data it does a little bit of it reduces the count in count by one and that's a that's a thing you need to do just to clean up the numbers and get to get an accurate reading and then if there is a count that means that the pin is oscillating then it's going to return the frequency by multiplying that value by 10 and then printing it out if there's no if the count is zero or less meaning that there was no oscillations it basically you will interrogate pin h and if it and then tell you if the pin is higher low and there's the functionality of that logic probe so just a few words it does the difference between when I built this up the real the really cool thing is basically you can you can interactively test all these things you can manipulate these registers and work at the at the fourth prompt to make sure things work and understand it before you build up your vocabulary and you end up with to to be able to solve this problem if you're interested in that out there's more I did some fourth episodes earlier fourth that are on an Arduino and then there's all kinds of information on the web on on on fourths on microcontrollers so the actual test I'm doing here just to get this there's a picture let's get the Arduino board with the one wire hook from pin two to pin four what you do what's happened what'll happen is you'll it's start the 16 bit timer running at a hundred hertz then we'll do a little bit manipulation set of higher low and then we'll sample the pin to see if it works and so after uploading this vocabulary and starting the starting the Arduino board I put the output from the serial terminal in the show notes and so you start out with that the fourth prompt which is okay and then a couple of brackets and a hashtag sign in RAM that's the that's the fourth prompt and the first word you type in is logic pro minute that just sets up the timer and the pin and then you type in sample pin and then the output from that it says this frequent freak equals 100 which is 100 hertz is what we expect and so it's telling us it's oscillating at a hundred hertz and now if we stop the clock you're gonna sample the pin and it's either gonna come up as low or high in this case it it told us that the pin is low and then we can set the pin high by using the word pin high and sample the pin again and it says that the pin is high and now if I put in so the original compare value was 1,249 so if I take basically take a divide that by 10 and use it just roughly 125 the frequency should go up by by 10 times because we're causing the inner the inner up that triggers 10 times faster so you should see a frequency of about a thousand and so what I did was I the next next thing I did was I put 125 and I call the word set frequency which basically changes the compare value I started the clock again and then I sample the pin and sure enough the frequency that comes out of it is 1,000 so it seems like the logic probe is working and with that I'll bring this show to a close a little bit rambly but it was interesting I think with the show notes and a little thought you can probably all figure out what I was doing here for the next show I will use I'll repurpose that 16 bit clock and actually use it to drive a Z80 I'll hook up the data port to the to the Arduino mega and then we'll set up a no up test so we'll have power a clock and we'll give it some data and we'll use the logic probe to see if there's any activity on the address bus to see if the pin is if the chip is working so we'll do that in the next episode we'll use this logic probe to to move to the next step which will be an actual no up test of this chip so if you have any questions or comments put free to leave them in the show notes if you like forth or if you're doing something with retro computers please do some episodes for us it's always interesting and if you want to get hold of me I think my emails are available there and at HPR feel pretty email me and so this is Brian and Ohio I'm signing off and I want to remind everybody that you are more than your body you have been listening to hacker public radio as hacker public radio does work today's show was contributed by a HPR this night like yourself if you ever thought of a coin podcast click on our contributally to find out how easy it means hosting for HPR has been kindly provided by an onsthost.com the internet archive and our synced.net on the satellite status they show is released on our creative comments attribution for pointo international license