A minimalist hardware abstraction layer.
It separates hardware into seven different devices with only a few API functions each. Everything the computer can do should be possible with just these API functions. Experience the joy of programming with an easily underatandable API.
This repo contains device interfaces, drivers and example programs.
- screen - interface
- keyboard - interface
- audio - interface
- clock - interface
- disk - interface
- processing unit (PU) - interface
- processing unit controller (PUC) - interface
- screen and keyboard
- audio
- clock
- disk
- processing unit (PU)
- processing unit controller (PUC)
- screen
- audio
- clock
- disk
- processing unit (PU)
- Server Demo 1 -- Echoes the request in upper case.
- Client Demo 1 -- Sends the message "Hello, world!" to a server.
- processing unit controller (PUC)
- screen and keyboard
You can clone this repository and try out any of the examples. Build by running make.sh
and then run ./program
to run the demo program.
A typical program has the following parts: A launcher, a program and a build script. The examples below assumes you have cloned the repository into a directory called infracore
.
Initialize all the devices that your program will use. Each device is created using a device driver. In this example the SDL driver is used for the screen and a file driver is used for the disk. The screen is 640x480 and the disk is 1024 bytes, two blocks of 512 bytes, and stored in the file disk.dat
.
CreateScreenLinuxSDL(&screen1, 640, 480, 1920/0.508);
CreateC89File(&disk1, "disk.dat", 2, 512);
Program(screen1, disk1);
CloseScreenLinuxSDL(screen1);
CloseC89File(disk1);
An infracore program consist of a function that takes the devices it uses as input. For example, this program can use the screen and read data from and write data to the disk.
void Program(ScreenStructure *screen1, DiskStructure *disk1){
...
}
Another example would be a game. It needs a screen to display the game, an audio device to play sound, a clock to keep track of time and a disk for the game data. Then you would pass the following devices to the program: screen, audio, clock and disk.
Finally, the program needs to be built.
# Drivers:
gcc -c infracore/drivers/screen-linux-sdl/screen-linux-sdl.c -I infracore/devices/screen/
gcc -c infracore/drivers/disk-c89-file/disk-c89-file.c -std=c89 -I infracore/devices/disk/
# Launcher:
gcc -c launcher.c -I infracore/devices/screen -I infracore/devices/disk
# Program:
gcc -c program.c -I infracore/devices/screen -I infracore/devices/disk
# Make executable:
gcc -o program program.o launcher.o screen-linux-sdl.o disk-c89-file.o -lm -lpthread -lSDL2 -lrt
The code here is based on the contents of the book Foundations of Computer Science.