Close
0%
0%

SPAM-1 - 8 Bit CPU

8 Bit CPU in 7400 with full Verilog simulator and toolchain

Public Chat
Similar projects worth following
SPAM-1 : Simple Programmable And Massive - v1/v2
"Massive" in the sense that it's going to be built on breadboard.

8 Bit CPU using mostly HCT chips and fully simulated in verilog with realistic chip timings.

The current design is a heck of a lot more complex than the original POC but also a lot more capable. Unlike the POC it won't be relying on google sheets as the development effort of programming in that environment is too high, and also because I want to be able to use Icarus verilog and other such tools.

---

The prototype learning exercise was simulated in Logisim Evolution with an assembler written in Google Sheets - I've not seen this done before - is it a first? My intention was to make the tooling as accessible as possible and more visual.

However, once that initial effort and sim was completed I decided that this was too trivial to actually build as hardware. So I decided to bite off a lot more.

V2 objective

I got v1 working in the sim but then decided I wasn't going to build it in hardware as these very simple CPU's aren't that capable or complex and I wanted more of a challenge; something that would force me to learn more.

So this has changed out of all recognition.

Along the way I got distrated by a hardware build of a testing device for all the chip's Ive bought for this CPU project. The testing device project can be found in my project list. That was interesting and a throw back to my Uni days in the 80's.

Now, I'm firmly back on the CPU task and nearing the end of the design and sim phase....

UPDATE: After a few more months I've finally settled on the capabilities and design and have arrived at an approach that appeals to my  sense of symmetry. I've adopted some features of ARM; specifically conditional instructions and status flag control.

Check out the project logs !



V1 objective 

⭐️ I wanted to do things a little differently to some of the other efforts on the internet! 

I wanted the assembler and any other code I write to to be more readily accessible and instantly usable to others (like you) without installing python or perl or whatever first, so I've written the assembler in google sheets!I want to be able to run at least the typical demo programs like Fibonacci

  • I would like to extend it to play some kind of basic game (tbd)
  • It will have an assembly language and assembler for it
  • I might port C to it
  • I want to simulate it first
  • I want to build it physically, or a more likely a derivative

  • 32KB Dual Port Video RAM

    John Lonergan10/01/2022 at 19:42 2 comments

    Started a new module to support the VGA component of SPAM-1.

    I wanted 32KB of dual port ram for video but wasn't willing to shell out for it. I found a couple of 16KB PLCC modules so I need a board to support them as part of SPAM-1 and the new sub-project is a PCB to create a 32KB module that's R/W from the CPU side and Read-only from the GPU side and fast enough for 160x120 approx video.

    It's a work in progress.

    https://oshwlab.com/john.lonergan.sharing/32kb-dual-port-video-memory

    I want it to fit amongst my breadboards so it's size constrained.

  • Why? Why? How?

    John Lonergan08/27/2022 at 17:53 0 comments

    Several people asked those questions so I made a video to explain....

  • Benchmarking SPAM-1 using Mandelbrot

    John Lonergan07/14/2022 at 16:46 3 comments

    I've been wondering about how one homebrew CPU arch compares to another. How the memory addressing modes contribute, or which ALU ops are worth implementing or Harvards vs VN.

    Anyway I came across Matt Heffernan's 8 Bit Battle Royale channel where he discusses multiple popular commercial machines and I decided it would be interesting to see how SPAM-1 stacks up.

    The first step is to figure out how to do 16 bit fractional arithmetic on an 8 bit CPU like SPAM-1 that has no concept of floating point or even 16 bits. In the video Matt mentions using fixed point integer arithmetic and then presents an assembly language impl of mMandelbrot, but that's too far too fast for me to learn from.

    So I wrote my own "C" fixed point integer impl of mandelbrot using "8.8" encoding in 16 bits which I should be able to translate to my existing SpamCC compiler and which I should also be able to code in SPAM-1 assembly for speed comparison purposes. I wrote it in 'C' because I want to quickly understand the "8.8" arithmetic and because I expect GCC to be bug free, unlike SpamCC.

    The Fixed point Integer implementation I came up with is at  https://github.com/Johnlon/mandelbrot   and there is also a line by line equivalent floating point impl for comparison and learning purposes.

    I'll see if I can get SpamCC to implement the same thing. I pretty much expect this to show up a bug in the SpamCC compiler - but then that's a good thing.

    .........,,,,,,,,,,,,,,,,,,,,,,,
    ........,,,,,,,,,,,,,,,,,,,,,,,,
    .......,,,,''''''''''',,,,,,,,,,
    ......,,,'''''''~~=<=~'',,,,,,,,
    .....,,'''''''~~~=+[<+~~'',,,,,,
    ....,,'''''''~~~=+/  ;==~'',,,,,
    ....,''''''~~~=x/o&  /;:/~'',,,,
    ...,''''''~===+[        /=''',,,
    ...''''~= ++::/         /+~''',,
    ...'~~~=+[ X /           +~''',,
    ...~~~+:/o               =~''',,
    ...                     :=~''',,
    ...~~~++/?               =~''',,
    ...'~~~=+;   <           +~''',,
    ...''''~=&::::/         <+~''',,
    ...,''''''~===+/        /=''',,,
    ....,''''''~~~= / &  ?[:&~'',,,,
    ....,,'''''''~~~=+/  [==~'',,,,,
    .....,,'''''''~~~=+[<+~~'',,,,,,
    ......,,,'''''''~~=&=~~',,,,,,,,
    .......,,,,''''''''''',,,,,,,,,,
    ........,,,,,,,,,,,,,,,,,,,,,,,,

  • VBCC C Compiler now working !!

    John Lonergan07/14/2022 at 16:32 0 comments

    I've Made really good progress on porting a the C compiler to SPAM-1.  The capability of the product of my labours is best seen from the integration tests which can be seen in the SPAM-1 assembler test suite...  

    https://github.com/Johnlon/spam-1/blob/master/jvmtools/compiler/src/test/scala/asm/VbccAndAssemblerTest.scala

    This test suite is pretty reliable in that it uses VBCC to compile various C of increasing complexity each down to SPAM-1 assembler, it then converts the assembly to ROM images and then runs the ROM images on the Verilog simulation.

    See actual the SPAM-1 VBCC code is https://github.com/Johnlon/spam-1-vbcc/tree/main/demo - needs doco and also needs a way to keep is up to date with changes in the core VBCC code base.

    I will do a vidoe at some point to cover getting started with porting it as there's nothing out there that I found really useful.

    There are loads of undone stuff like I support 32 bit integer arithmetic only, I only support add and nothing else yet -  there's probabl;y a ton of language features I've not covered. However, supporting 32 bit is cool on an 8 bit CPU and adding other arith ops isn't hard.  Also I want to add at least 8 bit ops since they are native to the hardware and would be super fast. 

    I really think this is something others building such machines would benefit from.

    GCC and LLVM were basically impenetrable.

  • C Compiler

    John Lonergan05/09/2022 at 17:13 0 comments

    Currently struggling with undertstanding the VBCC C compiler with the idea of creating a back end for SPAM-1.

    I read up on LLVM and decided that was probably impossible for me.

    VBCC looks a lot simpler, certainly lines of code needed, but it's the style of C code with lots of single letter variables and little commenting in the code and some massive functions. It would be nice if the code were documented with the text that's in the PDF that's been written. I don't like having to switch to a PDF to figure things out.

    Still others have done it. 

    There is an existing 6502 back end and another 8 bit port called 832 but I really wanted to start by seeing a really minimal impl with no optimisations at all as otherwise it's pretty incomprehensible understanding what's needed. I wrote C for yearas and never regretted moving on and this stuff is hard work.

    If (when) I figure it out then I may do a write up or video on what I did if it seems useful to others.

  • Procrastination

    John Lonergan12/02/2021 at 17:41 0 comments

    So it's nearly Christmas again and everyone at work is doing Advent Of Code. I did that for a couple of years and eventually I get hacked off with it and bail.

    So this year rather than finishing off the hardware for SPAM-1 I'm going to learn something new seeing if I have the energy to write an emulator for SPAM-1 to speed up software development.

     Currently I road test my software on a timing accurate emulation built using my 7400 verilog model. Whilst Verilog been a really useful tool for checking hardware ideas I found that the Icarus Verilog engine is quite slow and so my Sims take too long. For instance running the Chip-8 tertis have via the Verilog model/SIM is super slow motion.

    So I have the Verilog for hardware verification but what is want is something faster for simulation for software dev purposes.

    So if I have the patience then I will write an emulator in multiple languages and that can be my advent of code.

    I'm most of the way there with a typescript impl and have already come to the conclusion that although the language ecosystem has a few niggles the lack of good doco on building a basic typescript app and what certain errors mean is a pain in the arse. Still I'll push ahead. Disclosure I am historically a C/C++/Java/Scala programmer with a bit of assembler and python. 

    Once that's done maybe I'll have a look at go and maybe even rust again. My last look at rush left me feeling that it would be unproductive to take a team and adopt it because it's so hard to get a program to even compile successfully, but on the other hand I had the feeling that if you can get a rust program to compile then it probably had relatively few coding bugs in it. Strange tradeoff, getting fired Vs accepting a high bug rate.

    I did say to myself I'd try Nim or Elixir but I'd also like to do something more substantial like my emulator in kotlin. I have most experience in the last 10 years with Scala and I'd like to have a better go at kotlin because right now I'm using Java and remembering why I was glad to start functional programming in Scala.

    Anyway seasons greetings (if it's tolerable to say that on 2 Dec)

  • Procrastination

    John Lonergan12/02/2021 at 17:41 0 comments

    So it's nearly Christmas again and everyone at work is doing Advent Of Code. I did that for a couple of years and eventually I get hacked off with it and bail.

    So this year rather than finishing off the hardware for SPAM-1 I'm going to learn something new seeing if I have the energy to write an emulator for SPAM-1 to speed up software development.

     Currently I road test my software on a timing accurate emulation built using my 7400 verilog model. Whilst Verilog been a really useful tool for checking hardware ideas I found that the Icarus Verilog engine is quite slow and so my Sims take too long. For instance running the Chip-8 tertis have via the Verilog model/SIM is super slow motion.

    So I have the Verilog for hardware verification but what is want is something faster for simulation for software dev purposes.

    So if I have the patience then I will write an emulator in multiple languages and that can be my advent of code.

    I'm most of the way there with a typescript impl and have already come to the conclusion that although the language ecosystem has a few niggles the lack of good doco on building a basic typescript app and what certain errors mean is a pain in the arse. Still I'll push ahead. Disclosure I am historically a C/C++/Java/Scala programmer with a bit of assembler and python. 

    Once that's done maybe I'll have a look at go and maybe even rust again. My last look at rush left me feeling that it would be unproductive to take a team and adopt it because it's so hard to get a program to even compile successfully, but on the other hand I had the feeling that if you can get a rust program to compile then it probably had relatively few coding bugs in it. Strange tradeoff, getting fired Vs accepting a high bug rate.

    I did say to myself I'd try Nim or Elixir but I'd also like to do something more substantial like my emulator in kotlin. I have most experience in the last 10 years with Scala and I'd like to have a better go at kotlin because right now I'm using Java and remembering why I was glad to start functional programming in Scala.

    Anyway seasons greetings (if it's tolerable to say that on 2 Dec)

  • NES Game controller complete

    John Lonergan10/29/2021 at 00:09 0 comments

    I've added an NES gamepad adapter to the project. This gives me a way to provide interactve input to games and get on with more of the build.

    The implementation is based around a PIC micro which handles the I2C comms with the two gamepads.

    I also needed a random number generator for the games so with a bit of space on the breadboard and a small addition to the design I added that too.

    For more info ...

    Hackaday project for the adapter ...

    https://hackaday.io/project/181036-nes-controller-interface-using-pic16f18446

    As usual I have a verilog simulation of the adapter....

    https://github.com/Johnlon/spam-1/blob/master/verilog/gamepadAdapter/gamepadAdapter.v

    The hardware schematic is ...

    https://easyeda.com/editor#id=c41219d653c64b329350f3ddb47a70a8

    The main routine of the microcontroller code is ... 

    https://github.com/Johnlon/NESInterfaceAndPeripherals/blob/main/main.c

  • Fully wired and working ! New subproject spawned.

    John Lonergan08/01/2021 at 21:30 0 comments

    I wired in the register file, the RAM, the ALU and the memory address registers 

    Did it work?

    No, an error showed up when I tried running the CHIP-8 Tetris program.  

    I spent hours trying to figure our my mistake and in the end it was my wiring of the signals from a 74245 transceiver being off by one pin. Gah !

    Anyway, I happily watched SPAM-1 playing Tetris but without any means to interact with the game and having no random number generator (yet) for CHIP-8 it was a major milestone but limited.

    It has been great though that I have had literally zero timing issues with this CPU that didn't also show up in the Verilog simulation - this has been a great vindication.

    I have two options for integrating a controller into SPAM-1. The first is to provide the hex keypad input via the over the UART as I've done previously and the other is to wire up some games controllers to the hardware; specifically a pair of Nintendo NES controllers. This latter approach helps wean the CPU off the UART interface and eventually I'll add a VGA interface so the UART inteface can be detached entirely.  

    Anyway, to fill in a few of the hardware gaps including the lack of games controllers I've come up with a side project to build a parallel interface adapter to NES controllers.

    This new device will also provide a whole load of other peripheral functions and it's rather akin to how the 6522 complements the 6502.

    Take a look and subscribe for updates.  

  • Almost there!

    John Lonergan07/06/2021 at 01:49 0 comments

    So I've also wired in the Register file now which means I have a total memory of 4 bytes.

    Not a lot but plenty to adapt my trivial UART program to echo back whatever is typed at the console.

    This all seems to work fine at around 2MHz which is where my 555 timer clock maxes out. I'm quite interested to see how fast this thing can be made to run on a breadboard. I'm pretty sure that the critical timing data path is about 200ns half cycle, so I'll see if I can get 5MHz at least from it. The single biggest component in the latency is the 80ns-100ns EEPROM used for the ALU, add to that say another 100ns for other components in th data path and 4-5MHz seems reasonable. It will be interesting to see if the IC's outperform the advertised timings.

    I've also wired up all the ALU status register flags to the control logic so all that's left to hook up is the Memory Address Registers and the 64KB RAM.

    As soon as I have the RAM in place I'll try running some of my MUST more complicated CHIP-8 programs on SPAM-1 CHIP-8 emulator.

    This is a massive achievement for me given I've spent ages building this thing in fits and starts.

    I'll need to add a few more things like a random number generator and an IO port to which  can add something like a games controller. And, the thing I'm really interested in is adding some video RAM and VGA output.

    Anyway lots to come - but I want to get that CHIP-8 stuff working this week if possible.  

View all 61 project logs

Enjoy this project?

Share

Discussions

John Lonergan wrote 06/30/2022 at 16:53 point

Thanks.

Want to get back to the hardware but I've been having some success porting the vbcc compiler to spam-1

  Are you sure? yes | no

kaimac wrote 06/30/2022 at 13:40 point

Great project!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates