- Minix running on a virtual machine through VMware Player;
- Eclipse, with Remote System Explorer.
In this tutorial I will help you to create and set a project. I will also teach you how to create some useful scripts which we will be using a lot during the project development.
So, let me think of a simple project which will be fun to develop... What about Flappy Bird? It makes use of graphics, keyboard, mouse to click the menu buttons, timer, and could easily use more stuff. I think it is a good idea! Let us start?
Create a new project folderFirst of all launch Minix, you know the drill:
After logging create a new folder, this will be our project directory. I called mine flappy-nix.
Now open eclipse and open the RSE perspective. We already have a connection to minix which we created on the previous tutorial. If you open My Home (use the same login and password), the folder we have just created should be listed.
Create the project folder structureNow is a good time to create our project folder structure. So go ahead and create the following folders through RSE:
- conf - this will contain a configuration file needed to install the program
- res - this folder will contain all the game resources, such as images
- src - this is where our source code will be stored
Next, create main.c inside the src folder.
Create the MakefileAlso create the Makefile inside src.
The Makefile is like a set of rules to compile our project. It is a file with no extension, and has to be exactly named Makefile - with the first letter capitalized.
Paste the snippet below to your Makefile.
Notice that PROG should have the same name as the project folder. You should also remember that every time you create a source file they should be declared in SRCS (only the .c files, not the .h). That's why SRCS = main.c. We will be adding more source files later. gnu gcc flappy-nix main.c -Wall -O3 -llm -ldriver -lsys -L.
We will also need a low memory library. Download it and drag it to the src folder.
Create amazing scriptsTrust me, scripts are great! They save a lot of time and typing. I will show you how to create three scripts you will fall in love with.
To create a script right-click the project folder, select New > File and then type the name of the script.
install.shThis script does the following:
- Installs the system configuration file required to execute it with the right permissions;
- Copies the res folder to a safe and convenient destination;
- Modifies the remaining scripts permissions.
Paste this snippet to install.sh:
cp conf/flappy-nix /etc/system.conf.d mkdir /home/flappy-nix cp -vr res/ /home/flappy-nix chmodcompile.sh chmod run.sh
compile.shThis script compiles the project. Paste the snippet below to compile.sh:
src make clean install mv flappy-nix ../ .. strip --strip-all flappy-nix
run.shThis script executes the project. Paste the following snippet to run.sh:
service runAfter all these copy/pasting, you should have exactly what is shown on the picture below. /flappy-nix
Why did we bother to create these scripts?
Well, because every time we need to compile our project (for example), instead of typing all the stuff we pasted to compile.sh by hand, we will just have to type: sh compile.sh! Isn't that great? You want to run the project? Easy! You just have to type: sh run.sh.
We need to do one more thing: create the system configuration file. This is a must!
Right-click the conf folder, select New > File and type flappy-nix. Then paste the snippet below.
service flappy-nixsystem DEVIO IRQCTL UMAP INT86 PRIVCTL READBIOS IOPENABLE ipc SYSTEM rs vm pm vfs io 40:4 70:2 2f8:8 3f8:8 irq uid 0
Finishing upWe have already done a lot during this tutorial! I think it is enough for now. So let's just check if everything is working as it should.
Open main.c and write a simple hello world program, such as the following:
Now go to minix, go to the project folder and enter superuser mode by typing the command: su.
Then execute the scripts by the following order:
It should give an error, but that's ok for now as long as you see the "Hello, minix!" message.
Here is a screenshot of my output for comparison:
Killing a serviceIf for some reason you run your program again and you get something like:
Request to RS failed : Resource busy (error 16)
That means that the program did not finish correctly and it's service is still running in the background. To kill/stop it, just run the command:
service down name_of_the_service_to_be_killed
In our case, it would be:
service down flappy-nix
This will kill the service and thus enable you to run it again. But do not get away with it this way, you should look for what is causing the problem and fix it.
This is a very useful command for the entire development of the project.