Author Topic: Snake! on my TTL breadboard CPU with 256 bytes (video and source code)  (Read 1582 times)

0 Members and 1 Guest are viewing this topic.

Offline visrealmTopic starter

  • Contributor
  • Posts: 29
  • Country: au
  • Aussie software guy and electronics enthusiast
    • GitHub
I recently added a character LCD to my Ben Eater-inspired breadboard CPU, and started writing programs for it.

This is the best I've managed so far in the 256 bytes of program memory it has:



Note: Despite being a C++ programmer for decades, my asm skills are quite sub-standard.  As are my electronics skills.  :D

I have also written an emulator for my CPU. So you can check out the source ASM and run it in your browser here: https://cpu.visualrealmsoftware.com/asm/?e=Snake%20(LCD)&s=500 (Just hit Emulate)

All source code is available for my CPU, my emulator and my character LCD emulator (which I've split out to a seperate repo)

Enjoy !:)

Troy
« Last Edit: April 20, 2020, 06:16:36 am by visrealm »
 
The following users thanked this post: mikerj, MK14, xavier60

Offline excitedbox

  • Regular Contributor
  • *
  • Posts: 104
  • Country: de
Nice. I got up to 30 but then I got myself stuck in a corner. Also took me forever to find one of them cause it was up against an edge. That is some really cool work though. Any plans of building his VGA board and getting it to run on a TV?
 
The following users thanked this post: visrealm

Online MK14

  • Super Contributor
  • ***
  • Posts: 5010
  • Country: gb
Thanks.
I really enjoyed your very life-like, emulator.
I managed to modify, and then eventually write program(s), on it. Which ran well.

It is really cool, seeing the LEDs (and displays), flash on and off, in real time, on the emulator.

I heard about his (Ben Eater) custom TTL computer (cpu), a somewhat long time ago. But assumed, it was too limited, to be interesting.
But now I've played with it, the instruction set was actually a fair bit better, than I was expecting. For such a relatively simple computer.

EDIT:
PROs:
I didn't realise. But yours seems to have (improvements over the original one) more and better instructions, with 256 bytes of ram, rather than 16 bytes. I.e. much better. The LCD 16x2 is a nice addition as well.

Slight CONs:
The clra ...Clear all registers (Ra -> Rd), was confusing to me.

As I took 'CLRA', to mean clear register/accumulator A, rather than clear all 4 registers/accumulators.
Since some assemblers, would use CLRA to mean 'Clear only the A accumulator'.
I hadn't read your manual, at the time of playing with it. I got errors when I tried to clrb, clrc etc in my code, as I'd misunderstood its functionality.

Overall, it's amazing and brilliant!  :)
« Last Edit: April 24, 2020, 10:44:25 am by MK14 »
 
The following users thanked this post: visrealm

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22436
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Cool!  Lot of work, not just the build but the assembler too, but the emulator too!

The clra ...Clear all registers (Ra -> Rd), was confusing to me.

As I took 'CLRA', to mean clear register/accumulator A, rather than clear all 4 registers/accumulators.
Since some assemblers, would use CLRA to mean 'Clear only the A accumulator'.
I hadn't read your manual, at the time of playing with it. I got errors when I tried to clrb, clrc etc in my code, as I'd misunderstood its functionality.

Poking asm without reading the manual?  Brave! ...or dumb? :P (Just kidding)

Yeah, becomes clear when contrasted with CLR Rx.  Although it's interesting that MVx src are listed at all.  Are these not just assembly aliases of MOV Rx, src?  (Impossible to tell without encoding given alongside it.)  Or, why enumerate them but not others?

Interesting choice to make Rb the... well, it's not the accumulator as such I guess, but the default (implicit) source.  I'm not sure offhand if this is actually much (or any?) worse than the usual way (accumulator default destination).

And one register is named Acc, though it's not obvious that "ALU output" necessarily works the same as all the other registers?  And if arithmetic and logic instructions return data to a selected register (not just Acc), is it really accumulating anything..?

Well, nevermind.  Again, cool stuff, great work!

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: MK14, visrealm

Online MK14

  • Super Contributor
  • ***
  • Posts: 5010
  • Country: gb
Cool!  Lot of work, not just the build but the assembler too, but the emulator too!

Poking asm without reading the manual?  Brave! ...or dumb? :P (Just kidding)

Yeah, becomes clear when contrasted with CLR Rx.  Although it's interesting that MVx src are listed at all.  Are these not just assembly aliases of MOV Rx, src?  (Impossible to tell without encoding given alongside it.)  Or, why enumerate them but not others?

Interesting choice to make Rb the... well, it's not the accumulator as such I guess, but the default (implicit) source.  I'm not sure offhand if this is actually much (or any?) worse than the usual way (accumulator default destination).

And one register is named Acc, though it's not obvious that "ALU output" necessarily works the same as all the other registers?  And if arithmetic and logic instructions return data to a selected register (not just Acc), is it really accumulating anything..?

Well, nevermind.  Again, cool stuff, great work!

Tim

I know you were joking, but...
When I was seeing it for the first time, I didn't know of the existence of the assembly language manual, or where it was. Also, I was NOT expecting to write any programs for the unit. So, no need to read it anyway.

But, I was then fascinated, and playing with the prime number programs. But, they were taking ages, just to count from 1, to 2. Then eventually 3, Then some time later 4 etc etc. But I wanted to see much bigger (potentially) prime numbers.
Also, at the time, I didn't initially realise the buttons and controls/potentiometers, are actually user adjustable in real time (Wow, just wow!   :-+ :-+). So, the (at max speed), worlds slowest computer not the fastest computer, was defaulting, to a really slow clock speed setting.

So, I adjusted the assembly listing, (I didn't realise there was an alternative prime number program, which already lets you choose the selected number, via a constant near the top), to make it start at a much bigger number.
Then the bug (excitement, not fault) caught me, and I modified more and more stuff. Until I ended up writing complete programs.

My latest program (unfortunately NOT saved), calculated to 32 bits!
Using all 4, 8 bit registers.
By setting the clock speed to maximum (apparently around 6,500 instructions per second), I was (eventually, after much patience), able to count to 2^24 + 1, and beyond!.
At some point, I cheated, optimised it, by putting in a huge bunch of increment instructions, set to be a binary multiple (e.g. exactly 16 Incs), so that the carry flag would still be set correctly, and only one (to make a loop) jnc instruction was needed for every 16 (later 32 or even 64) increment instructions.

It worked out very well. The 256 bytes is much more practicable, than its (I believe) original 16 bytes. Which wasn't very useful, beyond some early learning experiences for people.
The extra instructions, really helps as well.
I've NOT been able to find out much about the original spec "Ben Eater" computer anyway. I've just taken educated guesses, from watching one or more of his videos about how to make it, and what it does.

Another way of naming it, would be to have a register name, which means all of registers, A, B, C and D, such as K, E, Z (EDIT: Z is no good, as could get confused with a zero flag) or something.
Then when you say CLRK, it doesn't get confused with register/Accumulator RA.

E.g. Some processors (if I remember correctly), have Accumulators A and B. But when they are used together (combined), they are called D.

I.e. like the 6809 (and others).
https://en.wikipedia.org/wiki/Motorola_6809

Quote
in the 6809 are the use of two 8-bit accumulators (A and B, which can be combined into a single 16-bit register, D)

EDIT: Don't worry too much about it (like me). There are only 26 letters of the alphabet, and many/most instruction sets, end of with some confusing mnemonics in them. (E.g. Motorola (old company name) has a Sign Extend B into A instruction!, with a funny name).
I.e. the (please don't laugh), 'SEX instruction'. (Ignore the PUN, PLEASE!).
https://atjs.mbnet.fi/mc6809/Information/6809.htm
« Last Edit: April 24, 2020, 06:01:36 pm by MK14 »
 
The following users thanked this post: visrealm

Offline visrealmTopic starter

  • Contributor
  • Posts: 29
  • Country: au
  • Aussie software guy and electronics enthusiast
    • GitHub
Wow! Sorry, I missed these replies. Must have notifications turned off.

Thanks for the feedback, all. I definitely have some work to do on the intruction set (and mnemonics). I was completely winging-it. It's missing a few instructions I'd like to add, some mnemonics suck, etc.  Previous to this, my assembly experience was very limited.

@MK14 - Awesome work, man!  I didn't expect anyone to spend more that a minute or two playing with it. That's fantastic :)  There's some undocumented features. One being, you can set a URL parameter s=<speed> to set the starting speed of the emulator (1 -> 500).  If you use that when loading the assembler, it also passes on to the emulator.  eg.  https://cpu.visualrealmsoftware.com/asm?s=300

I have planned to have a #directive in the assembler to tell it to run this program at a given speed, but, haven't yet.

For anyone interested, I've recently uploaded a video showing how this works with the assembler, emulator, program loader, and the physical machine.

You can check it out here:



My 8-bit breadboard computer, assembler, emulator and esp8266 program loader. An overview.

Cheers
Troy
« Last Edit: April 30, 2020, 07:31:14 am by visrealm »
 
The following users thanked this post: MK14

Offline visrealmTopic starter

  • Contributor
  • Posts: 29
  • Country: au
  • Aussie software guy and electronics enthusiast
    • GitHub
Any plans of building his VGA board and getting it to run on a TV?

Naa. Not without first giving it a larger address space anyway. 256 bytes is much more useful that 16 (can fit a game in 256), but not nearly enough do do anything useful with VGA. It has a 32KB SRAM on board, but I'm only using 8/9 of the 15 address bits. That's my next immediate plan.
« Last Edit: April 30, 2020, 07:46:42 am by visrealm »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf