8085 Assembly: Interesting Instructions

So, I’ve been hitting the books and I’ve found a few cool resources on the 8085 CPU.  Since I understand how most assembly languages work, I want to focus on the unique qualities of this CPU and expose its strengths and weaknesses.  The MOS 6502 is well known for its efficiency and instruction pipe lining.  Yet, handling simple programming chores like structuring blocks is a pain.  For instance, if you wanted to write a conditional statement with several clauses, you would have to use branch instructions or unconditional jumps in the right places.

This isn’t anything new and is a problem typically found in most machine code.  However, the 8085 comes with quite a few conditional jump instructions just like the 6502, yet also packs in some niceties that allow some more conditionals to reduce boilerplate code:

conditonal-calls-8085-assembly-retrojohnny conditonal-returns-8085-assembly-retrojohnnyWith the ability to call subroutines vs. local labels, you can really keep your source clean and flexible.  Also, when you call your subroutine, you can handle local logic as normal, yet you also have the ability to return on flag conditions.  If a subroutine is well thought out, you can get away with saving some bytes and cycles.

It is true, calling subroutines vs. jumps involves the use of the stack, and can add some overhead to your application.  Ideally, though, your system will have a reasonable amount of ROM  / Stack Space to work with.  I mean, were not talking about writing code for the Atari 2600.

But still, if we wanted to focus 100% on clarity and ease of use, we would be writing in Ruby or Python.  Since we reside in the land of assembly, its best to focus on speed and efficiency.  Yet, its always nice when we don’t have to bend over backwards to write a conditional.

This post is specifically for the 8085 CPU and the TRS-80 Model 100.

TRS-80 Model 100 – A New Challenge!

trs80-100

 

Behold!  The worlds first laptop computer circa 1983 (it’s the same age as me).  This little beauty played a vital role in computer history as it opened the way to true portability.  Not to mention the fact that it came with a 300 baud modem and could access the ‘internet’.  Back then, BBS systems were the internet, and anyone with one of these was able to go online in the early 80s.

Another cool feature was the Basic interpreter.  Most 8-bit micros came with Basic, and almost all American systems in this era came with a Basic interpreter written by Microsoft.  In our case here, the CPU is an Intel 80c85.  It just so happens that during this stage in Microsoft’s history, Bill Gates wrote this version of Basic himself!  Pretty cool eh?

The system comes with 24K static RAM (expandable up to 32K).  It can interface with a Printer, Modem, RS2-32 port and Cassette Recorder.

I actually just purchased one of these guys on ebay ($40) and can’t wait for my package to arrive.  This purchase opens the way for really learning 8085 assembly.  I could also learn Z80 assembly as the two CPUs are mostly binary compatible.  I will probably end up focusing on 8085 as I have quite a bit of 16-bit 8086 under my belt and will probably feel right at home.  Also, the unit I purchased is in decent shape, but I may end up doing a deep clean and possibly Retr0Bright it.

Suffice it to say, this is the first of many posts about this machine.

Beginning Apple II Development

apple-ii-logo-retro-johnny

It seems that there’s a lot of people these days writing retro / homebrew games for 8-bit systems. Hey, I’m all for it!  As you know, I’ve dabbled with Atari 2600 programming, and have had a really fun time writing 6502 assembly.  But, at the moment, I’ve reached a point of frustration with the limitations of the 2600.  Part of the reason for this, is there are a lot of cool programming techniques for the 6502 that you lack the memory to perform.  The Apple II is really a decent machine to program.  Not only does it support native assembly (you don’t have to cross-assemble), but it’s probably the most iconic computer of the 8-bit era.

Another reason I have wanted to get involved with Apple II Dev, is because so few people are actively doing it.  This might be due to the fact that there is so much software out there for the Apple II. It could also be that the High-Res graphics for the Apple II are marginally better than EGA style graphics. Regardless of what ‘other’ people are doing, I’m setting out on my own adventure.  I plan to blaze my own path by digging through old books.

Soon, I’m going to start threads about my journey and see what all I can accomplish from scratch. I’m not going to consult any home-brew sites or forums along the way. I will say, that the resources of Jordan Mechner’s Prince Of Persia Source Code Release was inspiring and informative. I will be making use of any 6502 assembly source I find.

If this interests you, feel free to add comments or subscribe to see what we can come up with. Anyway, I view this as the new (old) frontier for contemporary retro programming. (Man that sounds weird)

Yet, another tech blog. Or is it?

Hi, I’m Johnny Starr.  I have been writing about the MOS 6502 CPU for awhile now all over the web.  I used to maintain www.thestarrlab.com but I just don’t like Blogger anymore.  I’m also involved in the community at www.atariage.com as well as www.6502.org

So, why another blog?  I dunno.  Just seemed like a good idea.  As a systems engineer, I’ve learned my way around setting up cloud servers and felt like setting up a wordpress blog.

However, my goal is to get into the nitty gritties of 6502 based systems.  Namely, the Atari 2600 and Apple //.  I’ve been writing a lot of assembly lately and have discovered some cool stuff.  Who knows, I may end up getting into Z80 stuff as well along the way.  The idea is to have a centralized location to write about whatever the heck I’m into that month.

My professional blog is up as well at www.starrblog.com  Not as interesting in my opinion, but some good stuff is up there as well.

Gameboy Mod – Glowing Pokemon Cart

My buddy +Clay Killough called me up yesterday on some resistor values for a 5V power supply and a 3mm LED.  After speculating a bit, he was able to come up with a good solution.  Here’s the board:

It’s pretty amazing how many components are already on those gameboy carts eh?  You’ve even got a nice little battery for the SRAM to save your games.  Clay chose to use a small block of protoboard there in the center as a hub for his connections.  One of the beauties of a ground / solder plane, is that it can be really simple to do some refinish work over a decade later.  For something this simple, it was wise to make the LED circuit serial vs. parallel.  This decision allowed for economy of space, considering that he was working with a tiny cartridge.

The final result was a success:

All of this ingenuity makes me hungry for a mod of my own.  The JS1701 Project is still chugging along, but in the meantime I have been inspired to mod my gameboy.  Ironically, my current GB is a transparent Gameboy Color which was a gift from Clay:

I really don’t know what I want to do with this guy, but its going to be awesome!

JS1701 Project – 3:8 Multiplexer Fun

The first day of wiring was a success.  Granted I had only my lunch-break to get started.  I was able to get past a few kinks to get my 3:8 multiplexer started:

Right now I have 6 outputs but I’m going to get started on the last two this evening.  In this picture, anywhere you see a jumper wire, that is for testing and debugging.  For all perm wires I will be using 22 AWG solid wire.  I’ve found it is more sturdy and gets the job done well.  I don’t like having to cut custom lengths, but it went by faster than I thought. 

It’s kind of going to be a “rats nest” but only because I am trying to be economic in my breadboard real estate.  Based on my ALU schematic, the above takes place here:

Based on my calculations, I will be using up most of the breadboard, but should have plenty of room for the buses and control lines, while possibly sparing space for some additional logic.

For instance, the NOP instruction is not necessary within the ALU as the Control Unit can also handle this.  I chose 7 ALU functions, and thus didn’t need an 8th.  As a refresher, here are my 7 functions:

000 – ADD / SUBTRACT
001 – Logical AND
010 – Logical OR
011 – Logical Exclusive OR (XOR)
100 – Logical NOT
101 – Logical Shift-Left  (Multiply by 2)
110 – Logical Shift-Right (Divide by 2)
111 – NOP (No Operation)

For right now, I’m going to see how these 7 effect the instruction-set and move on from there.

JS1701 Project – I Fought TTL, And TTL Won

As the title implies, RTL and DTL just didn’t take off for me.  I tried jumping through hoop after hoop and finally realized that I don’t want to spend my time that way.  In the amount of time it took me to really get a complex circuit figured out, I could have used 4 ICs and been done with it.

So, I swallowed my pride and ordered some 74LS series ICs.  I’m still going with the breadboard scheme for now.  I’ve chosen to spend my lunches in my office working on the project, and don’t want to complicate things with soldering.  When I eventually move on to JS1701-B (an 8-bit version) I will probably go with Wirewrap.

Here is the beginnings of my project:

I bought the board on ebay for $25.00 and it came with a ton of jumpers.  Actually, they are really nice and the board is in excellent condition.  The layout is a bit challenging, but so far the board has been fully tested and is working like a charm.

The one thing I’m doing here that is a bit different than other projects I’ve seen, is that I will not be using anything but logic gates.  For instance, my 3:8 multiplexer is built using 3-input AND gates along with a hex inverter.  My D-Type flipflops will be built using 2-input NAND gates.  I realize that i could save money, time and space by using ICs that provide logic elements instead of just gates.  But, I really want to build this 4-bit CPU from gates only.

Perhaps my 8-bit project will call for more complex ICs.  I guess we’ll find out.

JS1701 Project – ALU Design

After brainstorming a bit, I decided to construct a 4-bit ALU of my own.  As I’ve mentioned before, the 74181 is a great ALU, but I wanted to make my own; even if it was less efficient.

As far as speed, I’m not sure how fast this ALU is, however I would guess that since most of the logic is done in parallel it should hold up pretty well.  Here’s a schematic of my working ALU:

Might need to click this pic to get anything out of it!

I realize that the schematic is a bit gross right now.  Because I built this thing using Logisim, it actually performs and has been fully tested.  I could have used the “tunnel” component to make this cleaner, but I wanted to see the circuit in it’s entirety.

A few notes on this guy.  Since my first project is going to be 4-bit CPU, I’m not too worried about speed yet.  Right now, you can see that I’m using a simple “ripple-carry-adder”.  It’s actually an Adder/Subtractor; with the ability to subtract using 2’s compliment.  I have added shift functions, both shift-left and shift-right.  I thought about implementing a rotates (left and right) but didn’t feel like upping the multiplexor past the 3:8 I’m using.  Like I mentioned before, this is just going to be a simple CPU.

Since I love assembly language so much, I’m having to really think about my Instruction Set.  So far, this is pretty close to what I would like to use:

opcode  mnemonic 
—————-
0000    ADD    Perform Addition
0001    AND    Logical AND
0010    OR     Logical OR
0011    XOR    Logical XOR
0100    NOT    Logical NOT         (performed on A)
0101    LSL    Logical Shift Left  (performed on A)
0110    LSR    Logical Shift Right (performed on A)
0111    NOP    No Operation (preserves A) 

1000    SUB    Perform Subtraction (activates CIN & A/S pins)
1001    INC    Increase A (activates CIN)
1010    DEC    Decrease A (activates A/S without CIN)
1011    CMP    Compare 2 Operands (uses A=B pin)
1100    MOV    Move A into B (registers & memory)
1101    JMP    Unconditional Jump To Address
1110    BEQ    Branch If Zero Flag
1111    BNE    Branch If NOT Zero Flag

The downside to going with 4-bits is that I only have 16 instructions to choose from (vs. 256 when going 8-bit.  For the most part, the ALU’s function signals can be fed with the 3 least significant bits of the instruction itself.  Notice that ADD and SUB both have LSB’s of ‘000’, this is handy because the ALU function is the same for subtract as it is for add.  We simply have to activate the CIN & A/S pins.  The A/S stands for “add/subtract” by the way.

For the most part, this is my first attempt at anything like this in my life.  I am mostly a software guy, so I am probably going about this wacky a bit.  I’ve had to face the fact that I’m going to screw up quite a bit on the road to success.  You can’t really improve otherwise.

As far as JS1701, I’m not really sure about the implementation.  I was dead-set on going with RTL, but now I’m having to realize that it would take way to long to construct even a 4-bit ALU.  I may end up going with 74LS00 ICs afterall.  But honestly, playing with Logisim is so much fun, I’m beginning to wonder if FPGA might be the way.  I guess I’m just ambivalent right now.

Digital Logic: Exploring Simple Devices

 I’m taking a step back from the JS1701 project for a few to study.  This is really important for all my future projects as I will need these skills to understand what I am building.  Although breadboarding is fun, its a lot more practical to use Logisim to study pure logic.

Originally, I was going to base JS1701 on the 74181 ALU.  When I say “base” it, I was pretty much going to rip it off until I understood it.  Here’s a look at the schematic:

I’ve found a few ALU videos on YouTube that have helped in understanding this circuit.  Suffice it to say, it’s a work of art.  Although the circuit is actually simple, its based on a lot of complex concepts including circuit simplification.  I realized that implementing the 74181 isn’t going to do me any favors as an engineer.  By building a CPU from scratch, I need to be able to create my own ALU.  I think that I will be able to learn each of the arithmetic and logic circuits and combine them in parallel.  Like I said, it probably won’t be as efficient as the 74181 but that isn’t the primary objective.

I have used Logisim to make an Adder, but I found this Shift-Left circuit to be much more interesting:

Disabled “shift” line.

Enabled “shift” line, performing the function.

By toggling the input, we see that the 4 bits shift once to the left.  The “enable” line gives us the ability to turn the function on and off.  The way this works is the CU (Control Unit) will send a signal to the ALU, which will decode the multi-bit signal to specific enable lines.  More on that to come.

JS1701 Project – RTL Revisions

Gotta give props to +Ed S for his insights on my previous post.  It appears that I may have jumped the gun a bit.  In fact, I was basing my NOR gates off of the IC implementation: 1 transistor per input.  This deals with the 3-input fan-in limitation of the more simple 1 transistor gate.  Here’s an example of XNOR using the complex method:  (was shooting for an XOR but lacked transistors)

Kind of messy eh?  Clearly with 2-input gates, this is overkill.  Let’s take a look at +Ed S‘s suggestion according to this Wikipedia page:

Pardon the quick and dirty layout, but here we have 3 NOR gates combined to function as 1 AND gate.  The black, yellow and white jumpers go to my logic test board which allows easy debugging:

So, the benefit here is that we are getting stable NOR gates at the cost of 1 transistor each.  Not bad considering that our previous scheme required 2 transistors for an AND gate.  This should allow us to rely on NOR logic while increasing our transistor cost by 30% or so.  Not great, but would allow for a stable project.

Since the adder in my ALU will require some 4-input gates, I can implement the RTL IC version of adding transistors for each input.  It appears that the project may be possible, but I want to give it some major testing first.