-
Notifications
You must be signed in to change notification settings - Fork 7
First Program
We will see in different ways how to write and compile a small program that displays "Hi profanOS!" on the screen.
For reasons of simplicity we will note LINUX$ the host shell
prompt which allows you to compile profanOS and PROFAN>
the shell of profanOS (Olivine by default).
- Writing and compiling in Linux
- Writing in Linux, Compiling in profanOS
- Writing and compiling in profanOS
In this first approach we will use linux to write and compile the program and we will only execute it in profan.
All file in directory zapps/ are compiled when the disk image
is created. So we will create a file zapps/c/hi.c and write
the following code with your favorite text editor:
#include <stdio.h>
int main(void) {
printf("Hi profanOS!\n");
return 0;
}# Just compile the disk image
LINUX$ make disk
# And run profanOS
LINUX$ make runDuring disk creation, the program was compiled in /bin/c/ we
can run it manually or just write its name (See Olivine).
# Full path
PROFAN> . /bin/c/hi.elf
# Using the env:PATH
PROFAN> hiIn this second approach we will use linux to write the program
and we will compile it in profanOS using tcc.
All file in directory sys_dir/user/ are moved to the profanOS
file system when the disk image is created. So we will create a
file sys_dir/user/hi.c and write the program in it.
#include <stdio.h>
int main(void) {
printf("Hi profanOS!\n");
return 0;
}Heavy profanOS programs are not directly in the main repo, but you can easily retrieve them.
# We can use the gui addons manager and scroll
# down to select tcc and download it.
LINUX$ make addons
# -- OR -- cli way
LINUX$ python3 tools/addons.py tcc# Build disk and start profanOS vm
LINUX$ make disk runIn profanOS, using tcc we can easily have an executable!
# Go to the user directory
PROFAN> cd /user
# Compile the program
PROFAN> tcc hi.c -o hi.elfUsing the . command we can run the program like any other.
# Run the program
PROFAN> . hi.elfTcc also has an option that allows you to compile and execute a C program in one go:
# Compile and run the program
PROFAN> tcc -run hi.cIn this third approach we will write and compile the program directly in profanOS.
# Select tcc in the gui addons manager
LINUX$ make addons
# Build disk and start profanOS vm
LINUX$ make disk runIn profanOS you can use the rim text editor with syntax highlighting
to write or edit code. To save the file press Ctrl + s and to exit
press Esc (it's simpler than in vim 🥲)
# Go to the user directory
PROFAN> cd /user
# Start the editor
PROFAN> rim hi.cWrite the program in the editor:
#include <stdio.h>
int main(void) {
printf("Hi profanOS!\n");
return 0;
}Compile the C program like last time
# Compile the program
PROFAN> tcc hi.c -o hi.elf
PROFAN> . hi.elf
# -- OR -- compile and run in one go
PROFAN> tcc -run hi.cIf you want to recover your program in linux, you cat it in the serial console.
# Cat the program and redirect the
# output to the serial port
PROFAN> cat hi.c > /dev/userialIn linux the program will be displayed in the terminal, you can copy it and paste it into a file.
You have seen three different ways to write and compile a program in profanOS. The choice of method depends on your preferences and the size of the program you want to write.
Interpreters for other languages are also available in the addons menu such as python, perl or lua 😊