My Linux graphics code golf setup
A part of my Linux graphics code golf development
is done on a Ubuntu Virtual Machine running on VirtualBox, the
whole point of this setup is to get all the latest tools such as
latest GCC version without much work and without messing with my
host system.
The development / testing part is done on my host system using
Visual Studio Code and
the compilation / assembly is done on the Virtual Machine using
tmux to get
scrollback since vgacon / fbcon soft scrollback
was removed in version 5.9 of the kernel.
Prototyping can also be done online in Compiler explorer.
Here is the whole step by step of my VirtualBox setup (this
should compile all my Linux code golf sources !) :
- get VirtualBox
- get latest Ubuntu (i generally use the latest non LTS Ubuntu Server version)
- create a VM on VirtualBox with the downloaded .iso (i disable sound and add host shared folder)
- run the VM and install the OS, i mostly use the defaults but switch keyboard layout to french
- once installed i install build stuff :
sudo apt install build-essential
- then clone ELFkickers
repo in home folder :
git clone https://github.com/BR903/ELFkickers.git
- compile sstrip from ELFkickers :
cd ~/ELFkickers/sstrip && make
- then i setup the shared folder by following this process
:
- add the VirtualBox guest addition image from the menu
- mount cdrom :
sudo mkdir -p /mnt/cdrom && sudo mount /dev/cdrom /mnt/cdrom
- install guest addition :
sudo ./mnt/cdrom/VBoxLinuxAdditions.run -nox11
- add vboxsf group :
sudo adduser $USER vboxsf
- install some more stuff for cross compilation (doing 32 bits
dev. on a 64 bits platform) :
sudo apt install gcc-multilib
- install nasm :
sudo apt install nasm
For tmux i used this cheatsheet and
this since i wasn't accustomed to it at first, most used
feature is scrollback mode with Ctrl + B (then
Page UP/DOWN) and creating terminal window with Ctrl
+ B then c (and switch window with Ctrl + B then n).
Perhaps it should be possible to do the testing part inside
the Virtual Machine but i didn't get it to work yet, the main issue
was changing the resolution of the console / fbdev, this didn't
work under VirtualBox.
Dev.
Assembly
Development process is straightforward and is just about
writing assembly code (generally 32 bits x86) with an assembler
such as NASM, i have a makefile
and a build shell script which just call make with
parameters to setup constants such as the resolution.
High-level languages
I think high level languages graphics code golf (C, Rust etc.)
on Linux is a very interesting approach because of accessibility /
readability of the sources and you can do it in a cross-platform
way.
One of the big issue i got with C is fighting with the
compiler output (which is manageable although it will never be as
optimal as assembly) but the bigger issue for me was GCC usage of
the stack such as stack alignment etc. which is added automatically
by GCC and which eat some bytes, this cannot be disabled as far as
i know, there is ways to get around it by removing the useless
instructions but C graphics code golfing still feels a bit shoddy
with all the uncertainty it adds.
One way to somehow control / direct the output of GCC is to
use the register keyword with -fomit-frame-pointer
option, giving hints to the compiler about which register it should
use for variables such as : register int f
__asm__("edi");
Perhaps a better way would be to build a high-level language
which target graphics code golf stuff with options that you don't
find in GCC such as disabling the stack in code generation
etc.
Anyway a big early chunk of my releases were in C (and often
not really that size optimized compared to my assembly or TIC
stuff) and i may do it again in the future since this
cross-platform approach is interesting.
For C stuff i rely heavily on the assembly output of the
generated code as feedback, i use objdump to see the output
assembly of my binary (replace -m i386 by -m
i386:x86-64 for 64 bits) :
objdump -b binary -M intel -D
-m i386 ../elf_binary
A collection of graphics templates for C stuff is available
here.
Testing
Most of my graphics Linux code golf stuff run under the
framebuffer
device which can be switched to on modern distributions by
going console mode with Ctrl + Alt + F2 (where
F1 is the GUI mode and Fn is
other console session) and running the binary from there.
By default the console mode run with a fixed display
resolution which may be different than the resolution the running
program is designed for, it is possible to switch the console mode
resolution by messing with GRUB or with fbset although i never
managed to make it work with fbset on my machine.
Changing console resolution with GRUB
- check supported resolution with "vbeinfo" in GRUB command
prompt, can also use hwinfo in regular terminal : sudo hwinfo
--framebuffer
- "GRUB_GFXMODE=WxH" in /etc/default/grub (where W/H is one of the supported resolution value)
- sudo update-grub
back to top