Home / Docs / DOOM Port

Historical engineering note. This is a point-in-time debug log from early in the DOOM bring-up, preserved from the project archive; the "NOT WORKING" status below is historical, and so are the kernel/games/doom/ file paths throughout: DOOM was later moved out of the kernel entirely. The port has since been completed and DOOM now runs on MayteraOS in a desktop window, launched from the Applications menu as a userland program at /GAMES/DOOM/DOOM.ELF (source: userland/apps/doom/); no DOOM source remains in the kernel tree.

DOOM Port for MayteraOS - Debug Notes

The port is built from id Software's DOOM engine source, released under id's own DOOM Source Code License (a separate, more restrictive license than the GPL, carried in every source file's header). It requires a user-supplied DOOM.WAD on the boot disk; no WAD game data is included with or distributed by MayteraOS.

Status at the time: NOT WORKING

Issue: Z_Malloc fails with zone size=0

Problem Summary

DOOM's zone memory allocator (z_zone.c) is receiving 0 bytes from I_ZoneBase(), causing all Z_Malloc calls to fail.

Root Cause Analysis

The Bug

I_ZoneBase() in i_system.c returns mb_used * 1024 * 1024 bytes, but mb_used is 0 at call time.

Why mb_used is 0

  1. mb_used is defined in i_system.c as int mb_used = 32;
  2. m_misc.c has config entry {"mb_used", &mb_used, 32}
  3. M_LoadDefaults() runs BEFORE Z_Init() and sets mb_used = defaults[i].defaultvalue
  4. However, something is still setting it to 0

Suspected Issues

  • The config default array in m_misc.c may not be applying correctly
  • There may be another place resetting mb_used
  • Compiler optimization might be causing issues with extern variable linkage

Files Modified

kernel/games/doom/i_system.c

int mb_used = 32;  // Changed from 6

byte* I_ZoneBase (int* size) {
    *size = mb_used*1024*1024;
    byte *ptr = (byte *)malloc(*size);
    kprintf("[DOOM] I_ZoneBase: requested %d bytes, got ptr=%p\n", *size, ptr);
    return ptr;
}

kernel/games/doom/m_misc.c

{"mb_used", &mb_used, 32},  // Changed default from 2 to 32

kernel/games/doom/z_zone.c

Added debug output:

kprintf("[DOOM] Z_Malloc FAIL: requested %d bytes, zone size=%d\n", size, mainzone->size);

kernel/mm/heap.c

#define HEAP_INITIAL_SIZE   (64 * MB)  // Changed from 16MB

kernel/gui/desktop.c

Added serial command handler (not fully working):

static void process_serial_commands(void);
// Called from desktop_run() main loop

What Works

  • WAD file loading (the user-supplied 11MB DOOM.WAD loads successfully)
  • M_Init() starts
  • R_Init() starts loading lumps
  • Kernel heap allocation (64MB initial)

What Fails

  • Z_Init() gets 0 bytes from I_ZoneBase()
  • All subsequent Z_Malloc() calls fail
  • DOOM enters error loop

Suggested Fix (Not Yet Tested)

Hardcode the zone size directly in I_ZoneBase to bypass mb_used:

byte* I_ZoneBase (int* size) {
    *size = 32 * 1024 * 1024;  // Hardcode 32MB
    byte *ptr = (byte *)malloc(*size);
    kprintf("[DOOM] I_ZoneBase: allocated %d bytes at %p\n", *size, ptr);
    return ptr;
}

Serial Command Feature

Added but not fully working at the time. Issue: the QEMU serial socket did not receive input correctly.

Location: kernel/gui/desktop.c - process_serial_commands()

The intent at the time was a serial command to launch DOOM plus a command listing. That handler was never shipped in this form; today DOOM is launched from the desktop (Applications menu), not by a dedicated serial command.

Backups

Timestamped backups of the modified files (d_main.c, desktop.c, heap.c, i_system.c, z_zone.c) were taken before the change, per the project backup workflow.

Next Steps to Fix

  1. Hardcode zone size in I_ZoneBase (bypass mb_used)
  2. Or: Add kprintf in M_LoadDefaults to trace mb_used value
  3. Or: Initialize mb_used in Z_Init before calling I_ZoneBase
  4. Test with DOOM1.WAD (shareware, smaller) if the user's registered WAD still fails

Test Procedure

  1. Start the test VM
  2. Wait ~90 seconds for GUI to load
  3. Click DOOM icon in Applications menu
  4. Check the captured serial log for [DOOM] lines