https://github.com/permutationlock/dumb_cycle
A snake game for x86_64-linux written in C99 with no preprocessor or libraries.
https://github.com/permutationlock/dumb_cycle
assembly c99 linux qbe x86-64
Last synced: about 2 months ago
JSON representation
A snake game for x86_64-linux written in C99 with no preprocessor or libraries.
- Host: GitHub
- URL: https://github.com/permutationlock/dumb_cycle
- Owner: permutationlock
- Created: 2024-04-03T20:14:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-09T07:43:12.000Z (about 1 year ago)
- Last Synced: 2025-01-20T20:40:56.662Z (3 months ago)
- Topics: assembly, c99, linux, qbe, x86-64
- Language: C
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DumbCycle
A simple Snake/LightCycle game for `x86_64` Linux implemented in
assembly and C99 with no linked libraries (no libc) and no preprocessor
directives (no `#ifdef`, `#define`, `#include`, etc).Images are drawn to the screen using the "dumb buffer" API provided by the
Direct Rendering Manager (DRM) subsystem of Linux. Keyboard input is read
directly from a keyboard device file. DumbCycle should run on any `x86_64`
Linux system with DRM support, a video card, and a keyboard[^1].DumbCycle can be compiled with any C compiler that supports C99 and ATT
syntax `x86_64` assembly. The primary motivation for eschewing the C
preprocessor is to allow the project to compile using only
[cproc-qbe][1], [QBE][2], and [GNU binutils][3] (for `as` and `ld`).
Passing the game code through cproc and QBE results just over 2000
lines of simple and readable `x86_64` assembly.## Building and running
Run the game by executing `make run` (or `make run_cproc`) with the required
permissions[^1]. You can also run `make` and `./dumb_cycle`, but `make run`
also executes `clear` to automatically restore terminal when the game exits.## Playing
Steer with WASD and avoid the walls. Press ESC to exit.
## References
- [musl libc][4]
- [libdrm][5]
- [linux kernel][6]
- [drm\_howto][7][^1]: The executable must have permissions to open the video device
`/dev/dri/card0` and the input devices in `/dev/input/`.
No other programs should be drawing to `/dev/dri/card0`, i.e.
you need to close your X11 and/or Wayland server.[1]: https://sr.ht/~mcf/cproc/
[2]: https://c9x.me/compile/
[3]: https://sourceware.org/binutils/
[4]: https://musl-libc.org
[5]: https://gitlab.freedesktop.org/mesa/drm
[6]: https://github.com/torvalds/linux
[7]: https://github.com/dranger003/drm-howto