Close
0%
0%

Lion FPGA CPU/Computer

A 16-bit (and a 32bit) FPGA CPU I call Lion CPU and a computer, the Lion computer. Everything built from scratch.

Similar projects worth following
I started to explore FPGAs and made a 16bit CPU, then I set a goal to make a computer like the early 80's home computers I used as a kid and I did.

I built a video controller, a UART, wrote an assembler and ported PA Tiny Basic adding fixed point and more. It started to feel like a home computer. I added SPI to use a SD Card and wrote simple FAT system support. For sound I made 3 audio channels and a noise channel.
Then I added hardware sprites.
I made a generator for Lion CPU code for the Java Grinder open source project and so I have a simple Java Compiler for Lion. Then I wrote "Astro", a simple demo game in Java. Of course I have added joystick port.
Αdded Vector graphics!
Manos wrote a nice windows emulator of 16bit Lion in C#.
A new 32-bit Lion is now completed with 256 colors, sampled audio, more sprites and all existing software is upgraded to 32bits, plus a C compiler.
Leon (Theodoulos Liontakis)


16bit Lion Specifications

CPU : Lion 16bit  @50Mhz

Memory:  8K rom + 56K ram + 32K video ram + 12K sprites ram + 64K paged ram + 4K vector ram

                support for up to 512K total ram in 64K pages

Video Mode 0 (text optimized):  640x240 pixels, 30x80 chars, 16 colors (2 per char)

Video Mode 1 (graphics optimized):  320x200 pixels, 25x53 chars, 16 colors

Sprites: 45 hardware sprites, 15 colors + transparency, 16x16 pixels, double buffered.

Sound: 3 channels + 1 noise channel, 8 bit digital volume control

Vector Graphics: hardware line drawing in 10bit resolution, 12bit DAC, 4K vector ram.

------------------------------------------------------------------------------------------------------------------------------

32bit Lion Specifications

CPU : Lion 32bit  @50Mhz

Memory:  16K rom + 1MB ram + 64K video ram + 16K sprites ram + 16K vector ram

                support for MB's of ram 

Video Mode 0 (text optimized):  640x240 pixels, 30x80 chars, 16 colors (2 per char)

Video Mode 1 (graphics optimized):  320x200 pixels, 25x53 chars, 256 colors

Sprites: 56 hardware sprites, 15 of 64 colors + transparency,  16x16 pixels, double buffered.

Sound: 3 channels + 1 noise channel, 8 bit digital volume control

             2 channels of 8bit  PCM audio with 16K buffer

Vector Graphics: hardware line drawing in 10bit resolution, 12bit DAC, 16K vector ram.

-----------------------------------------------------------------------------------------------------------------------------------

Common features

Storage: basic FAT support in SD card 30Mbytes

Ports:   2x joystick, 2x Serial, 1x VGA, 1x PS/2 keyboard, 1x audio

-----------------------------------------------------------------------------------------------------------------------------------

Software: Assembler, Palo Alto Tiny Basic (with fixed point arithmetic),

                 Java Grinder compiler (with floating point support), Small-C compiler,

                lcc c compiler, Astro java game,  Galaxians, pacman clone games.

And a Lion Windows emulator for the 16bit Lion written by Manos in C# see github project link.

Source code available at github (CPU+system VHDL/schematic, assembler, Rom+TBasic assembly)

More information and assembly description at my website (first project page).


Lion_mister.zip

Lion core for MiSTer with Virtual SDcard support, I added the Pacman clone game, the games play better with a joystick. This is a bit outdated, but it contains a working version of the 16bit Lion.

x-zip-compressed - 1.07 MB - 05/14/2020 at 22:10

Download

  • 1 × Cyclone V 5CEFA2F23I7 board
  • 1 × SD Card board with SPI interface
  • 1 × Power supply 12V dc 15W (for LCD) or 5V (without LCD support)
  • 1 × TTL to USB Serial board
  • 1 × LCD controller with vga input (Optional)

View all 7 components

  • New C compiler for Lion32

    Leon05/19/2022 at 21:55 0 comments

    I made a new (kind of) port of a compiler for Lion32. This time it's the lcc. I compile the intermediate bytecode that a version of lcc produces to Lion32 assembly. The bytecode is intended for a virtual machine environment but it fits me nice. Now I have a full C compiler with floats and unions and structures and multi-dimension arrays and everything.

    The only problem unsolved is with some cases of the switch command that I can't compile to relocatable code but it can be bypassed.

    I did that in about 10 days this time,  including the c, system and math libraries. The code produced has many unnecessary push and pops but I included an optimizer in the compiler that detects and merges any needless push-pop pair to a single move instruction, it does a  good job.

    Here one of the test programs:

    #include "clib.h"
    #include "syslib.h"
    
    float side=3.75f;
    float real=-0.5f;
    float imag=0.0f;
    float aspect;
    float dist,re,im,ci,cr,zr,zi,a,b; //float
    int key,counter,colr,tim1,tim2,lcolr;
    int scrw,scrh,maxiter;
    
    void main()
    {
    int x,y,lim;
    scrw=320;  scrh=200; maxiter=254;
    aspect=(float)scrw/(float)scrh;
    lim=8.0f; key=0;
    dist=side/(float)scrw;
    re=real-side/2.0f;
    im=imag-side/aspect/2.0f;
    IOout(24,1); // switches to graphics mode 1
    Screen(0,15); Cls();
    tim1=Timer(); lcolr=0;
    for (y=0; 2*y-1<scrh; y++)
    {
        ci=im+(float)y*dist;    
        for (x=0; x<scrw; x++)
        {
            cr=re+(float)x*dist;
            zr=cr;
            zi=ci;
            counter=64;
            do {
                a=zr*zr;
                b=zi*zi;
                zi=2.0f*zr*zi+ci;
                zr=a+cr-b;
                counter--;
            } while (counter>1 && 8.0f>(a+b));
            colr=65-counter;
            if (lcolr!=colr) { Screen( 0, colr); lcolr=colr; }
            Plot(x,y,1);
            Plot(x,scrh-y,1);
        }
    }
    tim2=Timer();
    tim1=tim2-tim1;
    Screen(0,30);
    PosYX(21,46); printf("%d",tim1);
    while (key!=32)    key=Inkey();
    }

  • New board

    Leon04/22/2022 at 08:25 0 comments

    I made a new base board for Lion32, a 4-layer one. In this board there is a ground layer and I mixed the sound channels, noise and digital sample output to a stereo sound output. It also features a 1MByte static RAM and a second serial port.

     I ordered the pcb from PCBWay as I have done so far for all my projects and I am very pleased with their service and the quality of the results.   

    This is a project I enjoy to keep returning to between my other projects mostly for retro computers.

    I received and tested the board, everything fine,  1MB ram available now and the system is more "quiet".

  • Syslib, floats & execute from TB

    Leon12/12/2021 at 13:42 0 comments

    After a long idle time I made a c library, the syslib, that contains useful system  functions for sound, sprites, scrolling, io, keyboard etc to be accessible from small c (Lion32 only).

    From the tiny basic prompt I can now execute c  programs from disk (and pass parameters) by using the prefix "!".

    So now  I can make some utilities, i already made two:

    !view filename  displays the contents of a text file.

    !play  filename  plays the raw audio sample from a file.

    I also made a floating point library to add in an indirect way 32bit floating point arithmetic to Small-C, so I use 32bit integers for storing floating point numbers and do arithmetic.

    this is a test program that correctly prints 7.50 as result:

    #include "stdio.h"
    #include "clib.h"
    #include "float.h"
    
    char s[20];
    main()
    {
        int f1,f2,f3;
        f1=stof("-2.5");
        f2=stof("10");
        f3=fadd(f2,f1);
        ftoa(s,f3,2);  strncat(s,"\n",1);
        printf(s); 
    }

  • Small-C port

    Leon04/17/2021 at 16:54 1 comment

    I almost finished the porting of Small-C to the Lion32 computer with 32bit integers instead of the 16bit that the original made for x86. I also made a linker for combining the object files it produces to a single executable file.

    I had a hard time with the different cpu endianness and the different cpu word size but I believe now I have solved all these problems.

    I almost finished the c library routines. Tiny Basic in Lion plays the role of a command line interpreter and so I added file and memory handling routines to it.

    If I could add structures in Small-C compiler it would be perfect and floating point would be nice too.

  • Lion's Color Palette

    Leon01/12/2021 at 21:50 0 comments

    Lion32's controller now has 64Κ of video ram and supports 256 colors in mode 1.

    In 16bit Lion mode 1  the resolution is 320x200 and every pixel's color is defined by 4bits so 16colors/pixel but  I just added the feature to choose the 4bit combination from a palette of colors.

    Every bit can be assigned to any of the 3bits per RGB color of the ladder DAC in the base board.

    This is an example of a palette choice with more shades of red and a bit of blue, a mandelbrot calculated using the 64bit fixed point arithmetic of Lion's Tiny Basic:

  • Lion shield board

    Leon10/19/2020 at 17:04 0 comments

    I made a shield board for the QMTECH Cyclone V Core Board to make the Lion computer circuit less messy.

    The board hosts:

    - XYZ DACs with separate voltage regulator

    - audio mixer opamp

    - the VGA resistor dac and connector

    - 512K fast 16bit sram

    - headers for all other connectors

  • 32-bit Lion

    Leon07/19/2020 at 15:30 0 comments

    The paged memory thing was troubling me a lot, so I made a new version 32 bit Lion CPU, I'll not surprisingly call it Lion32. Lion32 can have a 32bit address bus with tons of linear addressed memory.

    I made it as compatible as possible with the 16bit Lion and so the software had not to be rewritten although it needed much debugging but system software and Tiny Basic are working now with the 32bit Lion.

    I have to make the java grinder compiler 32bit version to be able to run the games and develop new 32bit software.

    Most new commands have the .D extension to indicate that they use a 32 bit length.

    MOV A1,10 is the 16bit operation while the MOV.D A1,10 is the 32bit

    the same with ADD.D SUB.D AND.D CMP.D etc

    All JUMPS and indirect addressing use 32 bits  

    Maybe I'll create a new project page for Lion32.

  • Lion core for MiSTer

    Leon03/24/2020 at 20:30 1 comment

    A friend lend me his MiSTer board and as I had a lot of time because of  various restrictions due to corona virus (here in Greece) I ported Lion to the mister board.

    Most things work well but there are some differences in keyboard behaviour and so to play the games well you need a usb joystick, also there is no serial port and XY-Display support as in the original Lion.

    VGA output is a bit dark and redish I don't know why. (now fixed)

    HDMI is better but both outputs are darker than in the real Lion computer (now fixed).

    You can find the core in a zip file at the files section.

  • Sound improvements

    Leon03/02/2020 at 11:40 0 comments

    In order to have better sound effects to add in the future to Galaxians clone or other games, I made some additions.

    In every channel I added the option to add a second frequency related to the playing one. This frequency can be up to an octave higher. It is controlled with a 4 bit parameter n.

    An other change is that the noise generator is clocked by the frequency of a channel when noise is enabled in that channel and its output is less harsh.

  • Lion got vector graphics too!

    Leon10/19/2019 at 14:38 0 comments

    Added a vector graphics controller in the fpga with 4K dedicated ram for 1024 vector end points.

    Now it uses 3x MPC4822 12bit dacs for all channels.

    It produces the x,y,z output signals that I feed in my recently acquired HP-1330A X-Y Display Monitor.

    I implemented the Bresenham's line algorithm in the fpga to draw a line from the previous drawn point to the last one.

    I converted the Astro java demo game for vector graphics!

    Raster and Vector graphics are totally independent and can display concurrently.

    The following picture was taken before implementing the line draw algorithm:


    And the next photo is with the line algorithm, unfortunately with my phone camera lines look fat, in reality they look much better:

View all 21 project logs

  • 1
    Step 1

    If  someone has serious intention to build it he may contact me for info.

View all instructions

Enjoy this project?

Share

Discussions

teraz wrote 05/21/2022 at 21:07 point

Can You compile ruby trought this new C compiler?

or emruby ?

  Are you sure? yes | no

Leon wrote 05/23/2022 at 07:54 point

sorry, no, no without a huge effort.

  Are you sure? yes | no

ee334 wrote 07/12/2021 at 12:22 point

Do You think about enclosure and mobile power (lipo, AA, 18650 etc) solar panel ?

  Are you sure? yes | no

Leon wrote 07/12/2021 at 17:44 point

I have thought about making a nice enclosure but for now I use a small project box for one Lion and a modified media pc enclosure for the one with the lcd screen (I have 2 Lions). I'll add a photo sometime.

  Are you sure? yes | no

ee334 wrote 07/12/2021 at 18:31 point

meybe create similar commodore 64 or raspberry pi 400 ?

  Are you sure? yes | no

teraz wrote 03/17/2022 at 17:13 point

or https://hackaday.com/2022/03/15/apocapi-now-is-a-cyberdeck-for-what-comes-after/

or https://github.com/penk/penkesu

  Are you sure? yes | no

Bharbour wrote 03/13/2021 at 17:01 point

Nice Job!

  Are you sure? yes | no

Leon wrote 03/13/2021 at 20:47 point

thanks

  Are you sure? yes | no

marazm wrote 01/03/2021 at 17:06 point

Add enclosure like ello 2, power, screen. Nice example https://hackaday.com/2021/01/07/building-a-pocket-sized-python-playground/

meybe cpu replace. This is very nice project. Many people need buy it . Meybe kickstarter?

  Are you sure? yes | no

Leon wrote 01/04/2021 at 11:46 point

thanks

  Are you sure? yes | no

marazm wrote 01/04/2021 at 19:28 point

Many people would like to optimize program, but they can't put it all together (and me too).

can You tell me how run it on qemu?

  Are you sure? yes | no

Leon wrote 01/05/2021 at 12:52 point

I know it is not well documented but I am working on the 32 bit version so in the future I'll write some better description-instructions and soon I'll upload eagle files for the board

  Are you sure? yes | no

Andre (baianinho) wrote 12/08/2020 at 14:02 point

Awesome project,thank you

  Are you sure? yes | no

Leon wrote 12/08/2020 at 16:05 point

thanks

  Are you sure? yes | no

Dusan Petrovic wrote 03/25/2019 at 12:32 point

This project is a great addition to the #Homebrew CPU list. Thanks Leon!

  Are you sure? yes | no

Leon wrote 03/25/2019 at 19:09 point

thank you

  Are you sure? yes | no

f4hdk wrote 03/24/2019 at 14:37 point

  Are you sure? yes | no

Leon wrote 03/25/2019 at 01:18 point

thanks for the tip

  Are you sure? yes | no

Goran Mahovlic wrote 01/08/2019 at 10:15 point

It would be great to see your console on our FPGA :) http://radiona.org/ulx3s/

  Are you sure? yes | no

Leon wrote 01/08/2019 at 14:59 point

Nice board!

  Are you sure? yes | no

Goran Mahovlic wrote 01/08/2019 at 22:43 point

Tnx, it was made for university in Zagreb(Croatia), and at some point we will try to push it to market.

  Are you sure? yes | no

marazm wrote 03/21/2021 at 15:29 point

@Goran Mahovlic  I  prefer https://tomu.im/qomu.html

  Are you sure? yes | no

Leon wrote 01/08/2019 at 00:56 point

thank you Goran

  Are you sure? yes | no

Goran Mahovlic wrote 01/07/2019 at 14:45 point

Great work!!!

  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