Homebrew CPU with discrete 74HC update: Video,Sound,Joystick,Keyboard <-- BIOS - Page 1
Forum section: electronics / projects

author: PauloConstantino
author_rank: Regular Contributor
timestamp: June 27, 2017, 12:44:58 am
content: ---->> Howdy my electronics nerdy, geeky and junkie fellows.. After trying 10 times to post this thread, with error after error saying I had already posted it, how frustrating....!Anyways.Since I have no friends and I am a lone electronics obsessed person, I thought I would share my work online with like minded people.This is an update on the 8 bit homebrew breadboard CPU made using only discrete 74HC logic IC's. Before you think about saying it's a birdnest, which it is, bear in mind this is the very point: to make a complete cpu from scratch using breadboards and jumpers very quickly, almost like a piece of art. I WILL however, replace the jumpers with short wires later on. Bear in mind that the circuit works perfectly as it is, with little crosstalk due to the very few edge type signals involved.There are a couple of things, first I'll show an unupdated schematic, which I will update some time in the future, but the current design is 95% what the schematics show, except for how memory is handled and lack of I/O devices on the schematics.Secondly, I am now in the BIOS stage, that is, the CPU is finished, with its instruction set exhausted, except that it could be fine tuned for sure, and so now I am looking to write a BIOS from scratch, in order to provide basic I/O support. For example, video handling routines: character writing, line, circle, triangle drawing, cursor moving, screen clearing, etc. IDE Disk handling routines, Floppy handling routines, Serial and parallel port handling routines, sound card handling routines and so forth.And yes the CPU/Computer has support for all these devices, all I need is drivers at the moment and thats where the bios comes in.The CPU is 8bits, with an 8bit data bus, an 8bit address bus (my only regret), 2 registers A and B, a stack pointer SP and a base pointer BP. There is currently 32KB of RAM accessible by the CPU, which is handled as 128 banks of 128 bytes each. The CPU is microcoded, with 4 parallel ROMS flowing control bits into the system. The PROMS are programmed with a u-code compiler written by myself which takes strings of 1's and 0's corresponding to control bits and assembled everything in binary files to be programmed into the ROMS with a rom programmer.There is a video card installed. Also made with breadboards and discrete IC's. It generates monochrome composite video which goes into a TV or monitor. The resolution is 320x280 pixels at 8MHz pixel write frequency. Video memory isn't part of the main memory, but is stored in an external VRAM, which is accessed and written to via IO ports. So if you want to write a byte to VRAM, just send a 2 byte address to port 70h/71h, the data to port 75h, and pulse WE on port 76h. This is of course slower than if it were part of main RAM, but I preferred this as then I don't use 11kB from main memory.There are 16 I/O ports at the moment, which can be used for anything. 9 of them are currently used for video, bank switching, the sound card, and 2 input ports.Yes there is a sound circuit, which generates square waves in several octaves, with 12 notes per octave. This circuit will be expanded soon to include sawtooth, triangle and sine, as well as filters to control the desired waveform etc.So this being said, this is a photo of the current setup, with a green monitor displaying raw random VRAM.I appreciate comments and questions!This is a top view photo of the whole set up, with a joystick installed, and a picture being displayed at the TV, having been loaded by the CPU.This is a picture of the current, latest instruction set. There is only one space left blank at the moment. I am still fine tuning it however.This is a picture of the CPU displaying raw VRAM to the monitor, just after reset. It shows a nice pattern that some old NEC srams have at reset:This is a sample assembly code, which I wrote early on before the instruction set was expanded. The memory map showing here however is correct:Code:; Genesis BIOS Version 1.0****************************************************** Memory map ******************************************************________________________________||0xFFFF|ROM Banks|.||.||0x8090|ROM Banks|________|_______________________|||0x808F |Lower 16|. |bytes of| -->> These addresses conflict with the lower 16 bytes of common ROM, which are used to boot up the system.. |ROM|0x8080 ||________|_______________________|||0x7FFF|127 Banks of|.| 128 Bytes|.|(RAM)|0x0180 | |________|_______________________|| |0x00FF | Free RAM |. | Free RAM |. | Free RAM |0x00F0 | Free RAM | -->> These addresses do not conflict with the common area I/O ports because the I/O ports decoder requires A7 to be 0, and here it is 1.________|_______________________|| |0x00EF | Common RAM |. | Common RAM |. |Common RAM| -->> Duplicate addresses for common RAM0x0080|Common RAM|________|_______________________|||0xXX7F| I/O:|0xXX7E| I/O:|0xXX7D| I/O:|0xXX7C| I/O:|0xXX7B| I/O:|0xXX7A| I/O:|0xXX79| I/O:|0xXX78| I/O:|0xXX77| I/O:|0xXX76| I/O: VRAM Control|0xXX75| I/O: VRAM DataOut|0xXX74| I/O: Bank Reg|0xXX73| I/O: Input1|0xXX72| I/O: Input0|0xXX71| I/O: VRAM Addr1|0xXX70| I/O: VRAM Addr0|________|_______________________|||0xXX6F| SP |0xXX6E| BP|.| Stack Begin|. ||0xXX10| Common RAM|________|_______________________|||0xXX0F| Lower ROM|.||.||.||.| 04: Begin BIOS|. | 03: 6E |.| 02: 6F|0xXX00| 00: JMP 04|________|_______________________|Low << =========== >> HighVRAM write sequence:write address0 to 70hwrite address1 tp 71hwrite data to 75hwrite 1 to VRAMEn (bit 0 on control byte) while keeping WR bit high (bit1)write 0 to bit1 on VRAM control byte. (WR) to write datawrite 1 to bit1 on VRAM control byte. (WR) to remove WRthen either continue writing: changing addr and data and pulsing WRor stop writing: send 0 to VRAMEn (bit0)00:_boot:71 04jmp 046F6f6E6e03 00mova, 00; reset VRAM controls and tristates it (VRAM WR here is active high, even though its active low in the actual chip)05 76mov , a; write 00000000 to VRAM Control to turn off buffers and keep WR high.03 80mova, 8005 74mov, a; send 80 to BANK register71 90jmp90; jmp to 8090, which is the beginning of the BIOS, after the 16 lower bytes.8090:_BIOS:03 6Dmova, 6d05 6Fmov, a05 6Emov, a; initialize SP and BP03 00mova, 086pusha; make space for 1 local variable for keeping VRAM address, starting at BP71 9Bjmp_VRAM_test_VRAM_test:03 ffmova, ff_count:23deca75 A2jz_end1:71 9Djmp_count; just a flagging loop so I know where the program is_end1:11 FFmovb, ff03 00mova, 005 71mov, a; send address to VRAM, upper byte is 003 0Fmova, 0F05 75mov, a; send data to VRAMdata register (stripped pattern)03 01mova, 0105 76mov, a; open VRAM buffers while keeping WR low_loop:13 70mov, b; send lower address to VRAM, which consists of just counter b.03 03mova, 0305 76mov, a; pulse WR high and write data03 01mova, 0105 76mov, a; pulse WR back low24decb75 BFjz_end271 B0jmp_loop_end2:03 00mova, 0005 76mov, a; close VRAM buffers so VRAM controller takes control again and displays data_halt:71 C3jmp_haltI have also attached the complete microcode that the CPU executes. Note that it is the textfile version, which is compiled into binaries.------------------------------- end -------------------------------------------------------------------

author: albert22
author_rank: Regular Contributor
timestamp: June 27, 2017, 03:51:16 pm
content: Man. I wish I could have your determination and patience to complete projects as you do.Congrats.

author: PauloConstantino
author_rank: Regular Contributor
timestamp: June 27, 2017, 10:13:35 pm
content: Thanks Albert! You really need to think about how pleasurable the end result will be. Hooking up wires is not fun, although it feels good when the jumper is going into the breadboardsBut the end result is imagining this mess of wires running a game like prince of persia and asking yourself how on earth, even though you know how

author: moffy
author_rank: Super Contributor
timestamp: June 28, 2017, 12:15:06 am
content: Unbelievable! Remarkable!

author: PauloConstantino
author_rank: Regular Contributor
timestamp: June 28, 2017, 12:31:57 am
content: Thanks Moffy. I hope someone could let me know of a small, tiny operating system I could install on the machine.

author: dr.diesel
author_rank: Super Contributor
timestamp: June 28, 2017, 12:42:43 am
content: Very good Sir,

author: GK
author_rank: Super Contributor
timestamp: June 28, 2017, 02:41:09 am
content: Bitmap graphics are nice, but you really ought to add hardware character generation to your video circuitry. Printing strings of text to the screen is a tedious and processor-intensive process if you have to write each individual pixel.

author: PauloConstantino
author_rank: Regular Contributor
timestamp: June 28, 2017, 03:01:34 am
content: Very true. I might do this in the future. I wanted to keep everything as simple as possible. It runs at 5MHz, so it should be fast anyhow.... Thanks for the suggestion!

author: jiro
author_rank: Contributor
timestamp: July 01, 2017, 12:21:41 am
content: Boy! Congrats! thie really requires a lot of dedication

author: Omega Glory
author_rank: Regular Contributor
timestamp: July 01, 2017, 01:52:01 am
content: Veryverynice! That is really something else. Keep up the good work!

author: xrunner
author_rank: Super Contributor
timestamp: July 01, 2017, 01:55:57 am
content: Wow! Great work. Now I see the possibilities of having a lot less friends.

author: Fungus
author_rank: Super Contributor
timestamp: July 01, 2017, 11:08:00 am
content: You own alotof breadboard cables.It's not often I'm left without words but you got me.I'm not sure whether to offer practical advice or tell you to keep going.If I was being practical I'd say:"OK, you've proved you can build a CPU!". The next stage is writing a BIOS and interfacing screens, disk drives, etc., but what do you gain by using all those wires? One bad connection could ruin a whole week. Can you move it to an FPGA or an emulator to do the next part? The advantage is that other people can have a copy of the 'hardware' to work on.If you're asking for collaboration with the BIOS it's going to be difficult because nobody else has the computer to work with (there's only one!) You might have to create an emulator anyway.

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 01, 2017, 11:37:28 am
content: Quote from: Fungus on July 01, 2017, 11:08:00 amHehehe thanks for your kind comments.I gain nothing in the long term by using the jumpers. I only gained a lot of time. I built the bulk of it in one week, and then started improving it and tuning it during the subsequent weeks. I didn't want to use an FPGA because I think it's not as "romantic" as building it like this. I wanted it to be as primitive as possible and still work.As for the BIOS, I think I'm trying to get others inspired to build their own.Thanks a lot

author: GK
author_rank: Super Contributor
timestamp: July 01, 2017, 05:33:55 pm
content: Oh, looks like the reply I just opened this thread again to reply to had disappeared....... I presume that you have figured it outIncidentally this evening I noticed that IC4D is drawn as a NAND gate when in fact it is an AND gate. Just being pedantic.

author: GK
author_rank: Super Contributor
timestamp: July 02, 2017, 03:48:34 am
content: Yes, you just have to program to update the video ram only during either the vertical or horizontal blanking intervals or both. If your processor can monitor digital I/O, just feed it the sync/blanking signals. A more sophisticated system/arrangement would be interrupt driven.Having the video RAM separate from the main RAM is the best performing and most logical way to implement a simple system like this, IMO. If the processor and video circuitry shared a common address and data bus then you wouldn't be able to do any processing at all out side of the video blanking intervals.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 02, 2017, 05:51:53 am
content: Nice work,I think you should expand the address bus to at least 24 bits, and I think it would be nice if you could do it on the PCB, I have lot's of students, so maybe it would be a great practice for them to design separate PCB's for each part of the computer as an assignment! if you are willing to I can set the assignment for them

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 02, 2017, 06:00:43 am
content: Quote from: ali_asadzadeh on July 02, 2017, 05:51:53 amYes definitely if you want to set it I can send you the eagle schematics.......

author: GK
author_rank: Super Contributor
timestamp: July 03, 2017, 04:24:46 am
content: Quote from: PauloConstantino on July 03, 2017, 03:47:52 amThat is one of two possible ways I mentioned for doing it. I cloned a Commodore PET. The PET video RAM update was interrupt driven.

author: GK
author_rank: Super Contributor
timestamp: July 03, 2017, 06:04:15 am
content: Quote from: PauloConstantinoWhat you described is called double buffering, of which there are variations. You also insisted on keeping the video logic as simple as practical, which double-buffered video RAM isn't. Make up your mind.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 03, 2017, 06:12:09 am
content: QuoteSure...please send them in

author: timb
author_rank: Super Contributor
timestamp: July 03, 2017, 06:47:17 am
content: Quote from: PauloConstantino on July 03, 2017, 05:28:23 am*Facepalm*

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: July 03, 2017, 08:48:43 am
content: Awesome stuff

author: GK
author_rank: Super Contributor
timestamp: July 03, 2017, 10:02:17 am
content: Quote from: PauloConstantino on July 03, 2017, 08:28:06 amUnreal!No, double buffering need not involve a duplicate of the entire RAM area, though that is how it was typically implemented. A shift register acting as a temporary memory storage for serial pixel shifting while the processor writes to the main video memory is the same operational principle.All I did was suggest that hardware character generation in addition to your bitmap graphics (really, I missed the fact that you already have video generation?) would be worthwhile addition to your project. Let me remind you of how you replied:"Very true. I might do this in the future. I wanted to keep everything as simple as possible. It runs at 5MHz, so it should be fast anyhow.... Thanks for the suggestion!"Quote from: PauloConstantino on July 03, 2017, 08:28:06 amI wrote that "there isn't a lot to it" simply because there isn't, as could be seen from the schematics I posted subsequent to your reply. In addition to the pixel/line counters required in any case for addressing the RAM and deriving the line/frame sync and blanking signals there is just a character ROM, a shift register and a small amount of additional logic.I wasn't suggesting that you were asking for advice and you can implement your video generator however you see fit. I bothered to scan and then post/share my video generator circuit design because I stupidly thought the technical details might be something of mutual interest, being from a project in a similar vein, irrespective of however you choose to build your own unit.I've deleted my unwelcome post with the schematics from this thread; I didn't post them here to wave my dick.Bye.

author: timb
author_rank: Super Contributor
timestamp: July 04, 2017, 01:57:51 am
content: Quote from: PauloConstantino on July 03, 2017, 12:42:03 pmYeah, uh, you're the one who started that argument, just to let you know. GK did nothing but help.GK, can you send me those schematics? I didn't have a chance to grab them before you took them down. (I've been collecting stuff on video generation for awhile, for a future project.)

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 04, 2017, 04:23:05 am
content: Quote from: alexanderbrevig on July 03, 2017, 08:48:43 amThanks buddy. Glad you found it interesting!

author: BrianHG
author_rank: Super Contributor
timestamp: July 04, 2017, 04:55:06 am
content: Another option for you display driver, you can cheat with this IC:https://www.digikey.com/product-detail/en/idt-integrated-device-technology-inc/7130LA35PDG/800-2448-5-ND/2011121Wire one side as ram, the other side is wired to read only and goes to your row and column counters, feeding the address of a eprom, which has your character set, with 8 bit color output. use upper addresses on the eprom for bit-mapped graphics mode which you can write and latch at the beginning of each line, stored in the same DP ram chip above. You'll get something like an Atari 800 graphics processor with an optional different graphics mode every few lines of video, though not palette unless you replace the eprom with a second DP ram chip. This will give you programmable fonts, with palette color per character and some easy snazzy effects making video games easy to program.Pros: 0 wait states! No system slow downs!Cons: 10$ a chip at digikey. Note that 2k and 4k exist in stock elsewhere, be careful to choose the DIP48 package for your breadboards.

author: ale500
author_rank: Frequent Contributor
timestamp: July 05, 2017, 05:47:22 am
content: Very impressive ! I find video output almost essential, serial is mehDo you have a schematic ? I wonder if it can be realized in HDL...

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 05, 2017, 10:06:01 am
content: Quote from: ale500 on July 05, 2017, 05:47:22 amYou completely get it! Some people want to just use a serial terminal and I find that a sort of unfinished business with this kind of project. I wanted to do everything from scratch, using the least bring up tools available, and I think I have cheated badly by having used a rom programmer and a text editor to write the microcode.Yes I have attached the schematics as a high res image, but eagle is also available. This schematic isn't 100% complete as it doesn't show the clock signals or even their polarities, but I can help with that. It also doesn't show the schematics for the video part as I don't have schematics for that! It can definitely be realized in a HDL. It's a simple microcode state machine.

author: BrianHG
author_rank: Super Contributor
timestamp: July 05, 2017, 11:27:11 pm
content: Quote from: PauloConstantino on July 05, 2017, 10:06:01 amIf you feel that bad, get rid of the text editor and rom. Get graph paper and cheap optical reflective IR reflective sensors, 1 per dip-switch on your bread board for programming. Draw out your program with a black marker, with one of the IR sensors shifted down 50% to catch the graph lines as you load clock. Just slide the paper under the string of 12-15 sensors to load your program or OS.No more rom... No more text editor... (I see it's probably too late anyways...)Though, I do not have a good method of saving programs to paper unless you add a parallel port & printer, on spool paper, and you create a simple printer save routine, + at least a way of expanding everything to a simple OS with peripherals.

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 06, 2017, 06:54:50 am
content: Quote from: BrianHG on July 05, 2017, 11:27:11 pmLOL! I have to say that is one of the most creative ways I've heard of to load a program! And that would be really exciting too. It's like a modern punched tape. I could even build a small machine to roll the paper for me while sending signals to WE and an address counter.I have to say the problem isn't a ROM, it's the ROM programmer which requires a computer. But then again, making an IC requires a computer so.........

author: dorin
author_rank: Contributor
timestamp: July 06, 2017, 08:36:26 am
content: My question is not how you made it, but how you debugged the damn thingOr is it really possible to connect everything right from the first time, and have no poor breadboard contact?

author: Fungus
author_rank: Super Contributor
timestamp: July 06, 2017, 08:38:51 am
content: Quote from: PauloConstantino on July 05, 2017, 10:06:01 amI was very disappointed when I heard that. I think I might have to unsubscribe now.You can always go back and do it again all by connecting wires to the chip and flipping switches.

author: BrianHG
author_rank: Super Contributor
timestamp: July 06, 2017, 08:45:23 am
content: @PauloConstantino, if you software has an opcode followed by data, or, opcode and control data in a fixed word length, I have an assembler language you can use which allows you to create your own commands and opcodes up to 36 bits wide. The layout is similar to microchip assembly with the addition of inserting tables of data. It gives you full listing output and a .bin file.Windows based...

author: ale500
author_rank: Frequent Contributor
timestamp: July 06, 2017, 01:31:16 pm
content: I don't know how much microcode you have but you could just use one ROM and several latches, and load the latches in sequence, saving on ROMs.

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 06, 2017, 04:34:24 pm
content: Quote from: dorin on July 06, 2017, 08:36:26 amI had various bad breadboard contacts, but I was lucky to debug them away. I had loose jumper problems.Finally though I had a few very strange problems which led me to "destroying" the CPU.It was executing most of the 255 instructions but not all, for no reason. I think maybe a bad IC was causing problems, or bad breadboard pins. Too much work to debug so I destroyed the CPU. I will rebuild it on a pcb.

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 06, 2017, 04:35:26 pm
content: Quote from: Fungus on July 06, 2017, 08:38:51 amYea that was bad by me. I dont know what I was thinking. You are good at catching my slips

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 06, 2017, 04:37:30 pm
content: Quote from: BrianHG on July 06, 2017, 08:45:23 amI would have accepted a few days ago but unfortunately this project has ended

author: JPortici
author_rank: Super Contributor
timestamp: July 06, 2017, 05:18:29 pm
content: Yep, this is time for PERFBOARD!

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 06, 2017, 05:24:34 pm
content: Quote from: JPortici on July 06, 2017, 05:18:29 pmI'll design a PCB I guess. Or maybe wirewrap. No perfboard........... I much prefer wirewrap!

author: Fungus
author_rank: Super Contributor
timestamp: July 06, 2017, 08:23:32 pm
content: Quote from: PauloConstantino on July 06, 2017, 05:24:34 pmHotsnot dead bug wirewrap!

author: PauloConstantino
author_rank: Regular Contributor
timestamp: July 06, 2017, 08:55:01 pm
content: Quote from: Fungus on July 06, 2017, 08:23:32 pmYes wirewrap 4eva.

author: GK
author_rank: Super Contributor
timestamp: July 17, 2017, 01:24:27 am
content: Quote from: timbTimb, the schematic is now here:https://www.eevblog.com/forum/projects/otp-eprom-programmer/msg1257749/#msg1257749Did you get my PM days ago? I can send PMs but nothing appears in my "sent" items folder. Dunno if the forum software is buggy or what.

author: timb
author_rank: Super Contributor
timestamp: July 20, 2017, 11:13:00 pm
content: Quote from: GK on July 17, 2017, 01:24:27 amI've tried to reply a couple of times, but can't. It says you've either got me blocked or have chosen not to receive PMs from other users. You might want to poke around your control panel and see if there's a setting you have turned off.