Banana Doom

Banana Doom is a native Android port of the original DOOM with on-screen touch controls, gamepad and keyboard support, and a built-in OPL/FM music synthesizer.

README

1000870619

🍌 Banana Doom

A native Android port of the original DOOM (id Software's linuxdoom-1.10 source) with on-screen touch controls, gamepad and keyboard support, an OpenGL ES 2.0 video backend, a low-latency software sound mixer, and a built-in OPL/FM music synthesizer that plays the music straight from the WAD — no soundfonts, no extra files.

The original game logic, renderer and data formats are untouched in spirit: the 1990s C engine runs as-is inside a NativeActivity, and a small (~2,100 lines of C) platform layer replaces everything that used to talk to DOS/X11/OSS.

Android app  ──►  NativeActivity (Java, ~190 lines)  ──►  libdoom.so
                                                          ├─ doom/      original engine (C, 56 .c / 60 .h)
                                                          └─ platform/  Android glue: EGL/GLES2, AAudio,
                                                                        touch/gamepad input, FM music, JNI keyboard

You need a WAD file. The game data (doom1.wad, doom.wad, doom2.wad, freedoom1.wad, …) is not included in this repository. See Getting a WAD.


Table of contents

  1. Features
  2. Getting started
  3. Controls
  4. Project layout
  5. How it works
  6. Tuning constants
  7. Known caveats and housekeeping
  8. Troubleshooting
  9. Credits and license

Features

  • Original DOOM engine — the full software renderer, game logic, AI, menus, automap, intermission screens, save/load.
  • Supports multiple IWADs — Doom 2, Plutonia, TNT, Ultimate Doom, Doom (registered), Doom shareware, FreeDoom 1 & 2. The first one found is used.
  • Touch controls — floating analog stick, drag-to-turn, drag-while-firing aiming, context-aware buttons (FIRE / USE / weapon prev-next / MENU / MAP).
  • Gamepad and hardware keyboard support (Bluetooth/USB controllers, WASD, arrows, Ctrl, Space, …).
  • OpenGL ES 2.0 output — 320×200 indexed frame converted to RGBA, uploaded to a texture, drawn 4:3 letterboxed with nearest-neighbour filtering and vsync.
  • Low-latency audio through AAudio (shared, low-latency mode) with a 16-channel mixer, pitch shifting, stereo separation, and automatic stream re-opening after a device change.
  • Music without a soundfont — an OPL2-style two-operator FM synthesizer fed by the GENMIDI instrument bank that is already inside the WAD, i.e. the same patch bank the original DOS game used for AdLib/SoundBlaster.
  • System soft keyboard for save names via a hidden EditText and JNI, with Cyrillic → Latin transliteration so Russian/Ukrainian input becomes readable in DOOM's menu font.
  • Auto-pause when the app goes to the background (opens the DOOM menu, which freezes the game, and pauses audio).
  • Immersive fullscreen, display-cutout aware, screen kept on, forced landscape (sensor landscape).
  • Crash-proof startup — if no WAD is found (or a fatal engine error occurs) a readable in-game error screen is drawn instead of a silent crash.
  • 16 KB page-size compatible native libraries (required for newer Android versions/devices).
  • Builds for arm64-v8a and armeabi-v7a.

Getting started

Requirements
ComponentVersion used by this project
Android Gradle Plugin8.13.0
Gradle9.0.0 (wrapper included)
JDK17
Android SDKcompileSdk 36, targetSdk 34, minSdk 26
Android NDK29.0.14033849
CMake3.31.6 (Android SDK Manager package)
DeviceOpenGL ES 2.0, Android 8.0 (API 26)+

minSdk 26 is required because the audio backend uses AAudio.

Getting a WAD

You must provide an IWAD. Options:

  • Freedoom (free, open content): https://freedoom.github.io/ — use freedoom1.wad or freedoom2.wad.
  • Doom shareware (doom1.wad) — freely distributable shareware episode.
  • Your own copy of doom.wad, doom2.wad, plutonia.wad, tnt.wad, doomu.wad.

Then do one of the following:

  1. Bundle it into the APK — copy the file into app/src/main/assets/ before building. (.wad files are stored uncompressed in the APK via noCompress += "wad".) On first launch it is extracted to the app's private storage.
  2. Copy it to the device after installing the app:
    /sdcard/Android/data/com.banana.doom/files/doom1.wad
    
    For example: adb push doom1.wad /sdcard/Android/data/com.banana.doom/files/

⚠️ Do not commit commercial WAD files to a public repository

Build
git clone https://github.com/CanavarIT/Banana-Doom.git
cd Banana-Doom

# put a WAD into app/src/main/assets/

./gradlew assembleDebug          # Windows: gradlew.bat assembleDebug

The APK is produced at app/build/outputs/apk/debug/app-debug.apk. Install it with:

adb install -r app/build/outputs/apk/debug/app-debug.apk

For a release build use ./gradlew assembleRelease. Note that the release build type is currently signed with the debug key (see app/build.gradle.kts) — replace it with your own keystore before publishing.

You can also open the project directly in Android Studio or AndroidIDE (the project was created with AndroidIDE, hence the .acside/ folder).

To run on an emulator, add "x86_64" to abiFilters in app/build.gradle.kts (there is a comment marking the spot).


Controls

Touch screen
Area / controlAction in gameAction in menus / intermission
Left 45 % of the screen (touch anywhere)Floating analog stick: forward/back + strafeUp / Down / Left / Right arrows (with key repeat)
Right side (drag horizontally)Turn left/right—
FIRE buttonFire (Ctrl). Keep the finger down and drag to aim while shootingOK (Enter)
USE buttonOpen doors / switches (Space)YES — only visible on yes/no prompts
< / > buttonsPrevious / next owned weaponhidden
MAP buttonToggle automap (Tab)hidden
MENU buttonOpen menu (Esc)BACK (Esc)

Stick behaviour: half deflection = walk, full deflection = run (classic DOOM speeds).

Gamepad
InputAction
Left stickMove / strafe (menus: navigate)
Right stick (X axis)Turn
A / R2Fire
XUse
YAutomap
B / Start / Select / BackEscape / menu
L1 / R1Previous / next weapon
D-padArrow keys (left/right turn, up/down move)
D-pad centre / EnterEnter
Hardware keyboard

W / S move, A / D strafe, arrows move/turn, Ctrl fire, Space use, Shift run, Tab automap, Esc menu, 1–9/0 select weapons, F1–F10 DOOM function keys, Y / N answer prompts, - / = change screen size.

Volume keys and other unmapped keys are passed through to the system.


Project layout

BananaDoom/
├── build.gradle.kts, settings.gradle.kts, gradle/libs.versions.toml, gradle.properties
├── gradlew, gradlew.bat, gradle/wrapper/
└── app/
    ├── build.gradle.kts                  # Android + NDK/CMake configuration
    ├── proguard-rules.pro
    └── src/main/
        ├── AndroidManifest.xml           # NativeActivity-based launcher activity
        ├── assets/                       # drop your WAD here (PUT_WAD_HERE.txt)
        ├── java/com/banana/doom/
        │   └── MainActivity.java         # fullscreen + hidden EditText for soft keyboard
        ├── res/                          # icons, theme, app name
        └── cpp/
            ├── CMakeLists.txt            # builds libdoom.so
            ├── doom/                     # the original DOOM engine (linuxdoom-1.10 based)
            └── platform/                 # the Android port itself
                ├── android_main.c        # entry point, lifecycle, system layer, IWAD lookup, input dispatch
                ├── i_video.c             # EGL + OpenGL ES 2.0 output
                ├── touch.c               # on-screen controls: logic + drawing + 5x7 bitmap font
                ├── i_sound.c             # SFX mixer + AAudio stream
                ├── music.c               # MUS sequencer + FM synthesizer
                ├── textinput.c           # JNI bridge for the system soft keyboard
                └── plat.h                # shared declarations between platform modules

How it works

Architecture and threads

Everything game-related runs in a single shared library, libdoom.so, loaded by MainActivity (a thin subclass of android.app.NativeActivity) through the android.app.lib_name = doom manifest meta-data.

Three threads are involved:

ThreadWhat runs there
Game thread (created by native_app_glue)android_main() → D_DoomMain() → the DOOM game loop, rendering, and all input handling. native_app_glue delivers touch/key events through an ALooper that DOOM drains in I_StartTic() on this same thread, so the input state in touch.c needs no locking.
Audio thread (AAudio callback)audio_cb() in i_sound.c: mixes sound effects and calls mus_render() to synthesize music.
UI thread (Java)Views, the hidden EditText, and the soft keyboard. Talks to the game thread through a mutex-protected buffer (textinput.c).

Cross-thread rules are deliberately minimal and lock-free where it matters:

  • SFX channels are handed to the audio thread with __atomic acquire/release on a per-channel active flag.
  • Music state is guarded by a mutex that the game thread takes normally but the audio thread only trylocks — if it is busy, the audio thread outputs silence for that block instead of ever blocking.
  • Keyboard text arrives on the UI thread, is parked behind a mutex, and is consumed by kbd_poll() once per tic on the game thread.
Build system

app/build.gradle.kts

  • ndkVersion = "29.0.14033849", CMake 3.31.6, abiFilters = arm64-v8a, armeabi-v7a.
  • CMake arguments: -DANDROID_STL=none (the engine is pure C, no C++ runtime is linked) and -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON.
  • androidResources { noCompress += "wad" } so a bundled WAD stays uncompressed in the APK.
  • packaging.jniLibs.useLegacyPackaging = false together with android:extractNativeLibs="false" in the manifest: the .so files are mapped directly from the APK instead of being extracted on install.
  • Release: R8 minification and resource shrinking enabled, debug symbols stripped (debugSymbolLevel = NONE).

app/src/main/cpp/CMakeLists.txt

  • Builds one shared library doom from doom/*.c + platform/*.c (both found by file(GLOB … CONFIGURE_DEPENDS), so new files are picked up automatically) plus the NDK's android_native_app_glue.c, compiled straight into the library.

  • Links against android log EGL GLESv2 aaudio m.

  • Compiler flags and why:

    FlagReason
    -O2, -flto=thin, -ffunction-sections -fdata-sections, -Wl,--gc-sectionsFast software renderer, small binary
    -fvisibility=hiddenOnly JNI/glue entry points are exported
    -fno-strict-aliasing -fwrapvThe engine is 1990s C that relies on type punning and wrapping integer arithmetic
    -fsigned-charDOOM assumes plain char is signed (x86). On ARM/ARM64 Android it is unsigned, which breaks negative forwardmove/sidemove (inverted and jerky movement). Forcing the original behaviour fixes it everywhere
    -Wl,-z,max-page-size=1638416 KB page-size compatibility
Application entry and lifecycle

MainActivity (Java) sets up the window, then native_app_glue starts the game thread at android_main() (platform/android_main.c):

  1. Save the android_app pointer and register the command (on_cmd) and input (on_input) callbacks.
  2. chdir() into the app's internal data directory — DOOM's relative-path file I/O (default.cfg, doomsavN.dsg) therefore lands in private app storage without any engine changes.
  3. touch_init(), kbd_init() (registers the JNI keyboard bridge).
  4. Pump the looper until the EGL surface exists (gl_ready()).
  5. Call the original D_DoomMain() — from here on it is the normal DOOM startup: IdentifyVersion → M_LoadDefaults → Z_Init → W_InitMultipleFiles → R_Init → P_Init → I_Init (sound + music) → … → D_DoomLoop.

Lifecycle commands handled in on_cmd:

CommandHandling
APP_CMD_INIT_WINDOWgl_attach(window): create EGL display/surface/context and GL resources
APP_CMD_TERM_WINDOWgl_detach(): tear everything down
APP_CMD_PAUSEPause the audio stream, cancel all touches, and — if a level is running and no menu is open — call M_StartControlPanel(), which pauses the game
APP_CMD_RESUMEResume audio
destroyRequestedSave default.cfg, release GL, exit

I_StartTic() (called by the engine before each tic) is where the platform layer gets its time slice. It calls pump() in a loop and blocks on the looper while there is no window, the app is paused, or GL is not ready — so the game is truly frozen (no CPU spin) while in the background.

Timing: I_GetTime() is CLOCK_MONOTONIC converted to DOOM tics (TICRATE, 35 Hz). TryRunTics() and the screen-wipe loop use I_Sleep(1) instead of busy-waiting, which keeps CPU usage and heat down.

IWAD discovery and file locations

IdentifyVersion() in d_main.c walks a table of known IWADs in this priority order:

doom2.wad → plutonia.wad → tnt.wad → doomu.wad → doom.wad → doom1.wad → freedoom1.wad → freedoom2.wad

For each name, I_FindIWAD() (in android_main.c) looks, in order, for the lowercase and the UPPERCASE file name in:

  1. externalDataPath — /sdcard/Android/data/com.banana.doom/files/ (easy to reach with adb or a file manager)
  2. internalDataPath — the private app directory
  3. APK assets — if the file is bundled, it is streamed out of the APK with AAssetManager into the internal directory (written to a .tmp file and atomically rename()d, so an interrupted copy never leaves a corrupt WAD). Next launch finds it in step 2.

The detected file sets gamemode / gamemission (shareware, registered, retail, commercial; Doom 2 / Plutonia / TNT), which in turn selects the correct episode/map structure, lump names and text.

Files written by the game (all in the internal data dir, which is the working directory):

FileContent
default.cfg7 settings: mouse sensitivity (used as touch-look sensitivity), SFX volume, music volume, show messages, screen blocks, detail level, gamma
doomsav0.dsg … doomsav5.dsgSavegames
Video: EGL + OpenGL ES 2.0

Implemented in platform/i_video.c. The engine still renders into its classic 320×200, 8-bit indexed framebuffer (screens[0]); the platform layer turns that into pixels on screen:

  1. I_SetPalette() — called by the engine whenever the palette changes (damage flashes, item pickups, gamma…). The 256 palette entries are run through DOOM's gammatable[usegamma] and stored as packed RGBA in pal32[].
  2. I_FinishUpdate(), once per frame:
    • converts all 64,000 pixels screens[0] → rgba[] through pal32[];
    • uploads them into a 320×200 RGBA texture with glTexSubImage2D;
    • draws a textured quad (GL_TRIANGLE_STRIP) letterboxed to 4:3, centred (DOOM's pixels are 1:1.2, so 320×200 is displayed at 4:3, as on the original hardware);
    • draws the touch-control overlay;
    • eglSwapBuffers (swap interval 1 → vsync).
  3. The texture uses GL_NEAREST min/mag filtering and GL_CLAMP_TO_EDGE for crisp pixels.

Two tiny shader programs are used:

  • Texture program — passthrough position/UV, texture2D(...).rgb.
  • Colour program — takes vertices in pixel coordinates plus an RGBA colour, and converts them to clip space in the vertex shader via a uRes uniform. All overlay graphics (stick, buttons, text) are built as plain coloured triangle lists and drawn with alpha blending in one glDrawArrays call.

EGL specifics: an RGB888 EGL_OPENGL_ES2_BIT window config is chosen, ANativeWindow_setBuffersGeometry is set to the config's native visual ID, and the surface size is re-queried every frame (check_size()) so rotation/resizing re-lays out the touch controls automatically. Because gl_detach()/gl_attach() run on every window loss/creation, all GL objects (programs, texture) are re-created in gl_setup() each time the surface comes back.

Input

All input enters through on_input() in android_main.c and is translated into native DOOM events (D_PostEvent) or into a few extra "touch/analog" variables read by G_BuildTiccmd().

Touch controls (platform/touch.c)

Layout — everything is expressed in units of min(width, height), so the layout scales to any screen. Buttons are anchored to the right edge/bottom (MENU and MAP to the top), clamped to stay on screen, and hit-tested with a slightly enlarged radius (HIT_PAD) so small buttons remain easy to press.

Floating stick — touching anywhere in the left 45 % of the screen (and not on a button) starts a stick centred on the touch point. Its output goes through:

  1. normalisation to −1…1 (the stick radius is 0.16 × min(W,H));
  2. a soft radial dead zone (0.15) that remaps continuously, preserving direction;
  3. exponential smoothing (0.35) to remove touch-digitizer jitter that otherwise makes strafing stutter, plus a snap-to-zero below 0.04;
  4. a walk/run curve: half deflection maps to DOOM's walk speed, full deflection to run speed, using the engine's original tables — forwardmove = {25, 50}, sidemove = {24, 40}.

The result is written to touch_fwd / touch_side, which `G_BuildTiccmd