Admin | Edit

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 !) :
  • 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
Once all of this is done i reboot and the setup is done, i can access my host folder containing my sources by going to /media/[shared_folder_name]

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.



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.

Here is a mmap fbdev source template that i use for my Linux x86 code golf stuff, it has a minimal ELF header and output a centered white pixel.

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.


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 topLicence Creative Commons