Close

Syslib, floats & execute from TB

A project log for 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.

leonLeon 12/12/2021 at 13:420 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); 
}

Discussions