nano80 - An Arduino nano based 8080 Simulator

Overview

I wrote my first 8080 simulator about 15 years ago in c for my x86 based PC. It worked. I posted the code and several others used the source for their projects.

I hadn't thought about it for a while, but on whim I started thinking about how small a footprint I could make an 8080 type single board computer, something like the microprocessor trainers we used in college. The nano80 is the result.

I honestly didn't think I could fit an 8080 simulator on an Arduino nano. I didn't think there was enough ram to be useful (there wasn't) nor did I think it would be fast enough (it really isn't). But as an 8080 test bed it works better than I hoped. I have LED's for a display port, toggle switches for an input port, a 1x8 LCD display for the address and data output for programming, and 6 momentary push button switches all combined to give me a programmable front panel.

At first I used the internal ram of the nano as my main memory. That gave me about 700 bytes of system memory. Enough for some small programs (our first 8080 had 256 bytes of ram), but not enough to do what I wanted.

I saw a breakout board for an I2C FRAM that gives me 32K x 8 which is enough for what I want. However, it's really slow. Think of this as an 8080 processor with 500uS wait states for memory.

It takes appx. 14 seconds to write to all 32K bytes. 0.5 msec per byte.

Programming

There are two ways to load data to main memory: via the front panel toggle/momentary switches with the LCD as the address/data display and via a boot loader on the serial port. The front panel switches are a classic way to load a file but is slow and error prone.

The boot loader reads Intel .hex files and loads the data into main memory. This is accomplished via a c routine in the Arduino. Its quick and error free and the preferred way of doing it.

 In the source code I include:

asm80.c    an 8080 source code assembler
ihex.c        a converter program to take the .com output of asm80 and create Intel .hex records
upload.c    a serial port uploader to send the .hex files to the nano80 computer

I tried using minicom and ascii-xfr to upload the object code files but because of the slow
write times of the FRAM chip, I got too many errors. The program upload.c puts a 20 msec
delay after each appx. 43 byte line, giving enough time to decode and store the object code.

Testing

 I wrote a brute-force op code tester that checks each (mostly) 8080 emulated opcode for com pliancy. The test cycles thru 40 times testing all the opcodes except those that manipulate 8080 hardware itself.

After a few days of testing and optimizing, all the 8080 op codes pass the test. I may have missed something. I expect I did. I loaded much of my old 8080 code and some new stuff and it all works as expected. The program that does this is called diag.asm and is also in the github repository.

Source files and schematics

I posted all the code, schematics and notes along with a few test files on my github account at:

https://github.com/WA6YDQ/nano80

All code (unless otherwise noted) is MIT licensed. In other words do what you want with it. I couldn't have made this without the open source tools others created, nor could I post the results without blogger and github. Who am I to make and hide my code?

Use

When first powered up the (simulated) 8080 processor does a reset. This sets the PC to address 0x00.
The RUN/STOP switch is tested. If it's at 0 (logic low) the command loop reads from the main memory and processes the opcode found there. The PC is incremented and the next instruction is loaded/executed. This continues until the RESET button is pushed or the STOP switch is active.

When the RUN/STOP line is 1 (logic high) an internal Arduino routine takes over and:

  • displays the address of the PC on the LCD
  • displays the opcode found at the address of the PC
  • test the LDH and LDL switches (momentary)
  • test the STEP+ switch (momentary)
  • test the STEP- switch (momentary)
  • test the RESET switch (momentary)
  • test the LOAD switch (momentary)
  • test the RUN/STOP switch (toggle)
The LDH switch takes the byte generated by the toggle switches and stores the byte in the upper byte of the 16 bit PC. The LCD display is updated.

The LDL switch takes the byte generated by the toggle switches and stores the byte in the lower byte of the 16 bit PC. The LCD display is updated.

The STEP+ and STEP- switches increment/decrement the PC by 1. The LCD display is updated.

The LOAD switch takes the byte generated by the toggle switches and stores it in the address of the PC. The PC is incremented by 1 and the LCD display is updated.

The RESET switch sets the PC to 0 and preps the nano80 computer to run the loaded program from the beginning.

The RUN/STOP switch when placed in the RUN position takes control away from the front panel and executes the simulated 8080 processor.

Final Comments

The source code is heavily commented and describes in detail how this works. I use this to test code before it goes into my Z80 based computer and generally play with. It's a fun toy.







Comments

  1. Hello, I like this. I'm trying to build this item. At first I want to test the sketch on a Arduino Uno, but I get an error "termios.h: not such file or directory" What can I do?
    regards Michael

    ReplyDelete
  2. For reference, the .ino file is the only arduino program needed to run the simulator. Place it in your arduino ide and built it, then load the object code on your arduino.

    The other .c files are used (on linux without mods, on windows with minor changes) as utilities and are not necessary for proper function of this project.

    ReplyDelete
    Replies
    1. Sorry, this was my mistake. I didn't read all your instructions. Seems to work now. I must wait for ordered items.
      Michael

      Delete
  3. Now I made my mini i8080 with an Arduino UNO and a shield.
    It was fun to build it.
    https://photos.app.goo.gl/ALcPW8XWjm2JbNz69
    Only changed the Arduino pins in the sketch for better wiring.
    Do you have more little progs for this computer? I'm a maker, no programmer.
    Michael

    ReplyDelete
    Replies
    1. Beautiful work! Unfortunately, aside from a few test programs, I never wrote any large 8080-based applications. I tested it with some of the projects we did in school some time ago (simple timers, counters, etc). I have a couple things I'll try to post in the near future, but they're pretty simple stuff.

      Delete

Post a Comment

Popular posts from this blog

Our Universe is a Simulation

Lightwave Communications