
Header only, no dependencies DOOM source port. Designed to run on any devices.
Primarily of interest to people that want to "run DOOM on their microwave".
See end of file for license information.
- Single header
- Pure-C, No includes dependencies: no stdlib, stdio, etc.
- Supports 32 bits and 64 bits
- Menu option to disable mouse move Forward/Backward
- Crosshair option
- Always-Run option
- Custom resolution
- Remove exit and have update return 0 on quit. Add doom_get_exit_code()
- Implement Sockets and Multiplayer
- Rebindable keys
- Unlocked FPS
- Release mouse in menus and use it for clicking
- Wipe screen freezes menu
- Use floats instead of fixed_t
- French and german
- Full color mode (Don't use COLORMAPS, use full 24 bits RGB)
Calldoom_init()
, then calldoom_update()
every frame, or as often as you can. This will run DOOM, without any video, inputs, sounds or music.
#defineDOOM_IMPLEMENTATION #include "PureDOOM.h"intmain(intargc,char**argv){doom_init(argc,argv,0);while (true) {doom_update(); }}
Most standard headers are available on most platforms. Define these preprocessors to toggle these features.
DOOM_IMPLEMENT_PRINT
. Allows printf, requires<stdio.h>
DOOM_IMPLEMENT_MALLOC
. Allows malloc/free, requires<stdlib.h>
DOOM_IMPLEMENT_FILE_IO
. Allows FILE, requires<stdio.h>
DOOM_IMPLEMENT_GETTIME
. Requires<sys/time.h>
or<winsock.h>
DOOM_IMPLEMENT_EXIT
. Allows exit(), requires<stdlib.h>
DOOM_IMPLEMENT_GETENV
. Requires<stdlib.h>
If your microwave doesn't have these headers, you can override their default implementations:
voiddoom_set_print(doom_print_fnprint_fn);voiddoom_set_malloc(doom_malloc_fnmalloc_fn,doom_free_fnfree_fn);voiddoom_set_file_io(doom_open_fnopen_fn,doom_close_fnclose_fn,doom_read_fnread_fn,doom_write_fnwrite_fn,doom_seek_fnseek_fn,doom_tell_fntell_fn,doom_eof_fneof_fn);voiddoom_set_gettime(doom_gettime_fngettime_fn);voiddoom_set_exit(doom_exit_fnexit_fn);voiddoom_set_getenv(doom_getenv_fngetenv_fn);
Every frame, after having calleddoom_update()
, you can get the screen pixels withdoom_get_framebuffer
and display it as you please.
while (true){doom_update();uint8_t*framebuffer=doom_get_framebuffer(4/* RGBA */);// ... Display framebuffer}
When you receive input events from your microwave touch pad, simply call one of the DOOM input events:
voiddoom_key_down(doom_key_tkey);voiddoom_key_up(doom_key_tkey);voiddoom_button_down(doom_button_tbutton);voiddoom_button_up(doom_button_tbutton);voiddoom_mouse_move(intdelta_x,intdelta_y);
Create a sound thread that outputs at 11025hz (DOOM_SAMPLERATE
), 512 samples, 16 bits, stereo. Then in your sound callback, calldoom_get_sound_buffer
to update and get the current DOOM's sound output. Make sure to add synchronization primitives around this anddoom_update
if your sound loop is in a thread.
Here is a quick example using SDL audio callback:
voidsdl_audio_callback(void*userdata,Uint8*stream,intlen){SDL_LockAudio();int16_t*buffer=doom_get_sound_buffer(len);SDL_UnlockAudio();memcpy(stream,buffer,len);}
You can use different bitrate, but make sure to resample because DOOM will always be 11025hz, 512 samples, 16 bits, 2 channels. For a total for 2048 bytes per buffer.
Set a timer in your application that runs at 140hz. In the timer's callback, tick DOOM's music as long as there are MIDI messages to send.
Here is an example using Window's MultiMedia to play MIDI events, using an SDL timer.
Uint32tick_music(Uint32interval,void*param){uint32_tmidi_msg;SDL_LockAudio();while (midi_msg=doom_tick_midi())midiOutShortMsg(midi_out_handle,midi_msg);SDL_UnlockAudio();return1000 /DOOM_MIDI_RATE/* 140 */;}
Default input setup in DOOM's source is not modern. It uses Arrows to move and','
/'.'
to strafe. You can calldoom_set_default_int
anddoom_set_default_str
to change them:
// Change default bindings to modern mappingdoom_set_default_int("key_up",DOOM_KEY_W);doom_set_default_int("key_down",DOOM_KEY_S);doom_set_default_int("key_strafeleft",DOOM_KEY_A);doom_set_default_int("key_straferight",DOOM_KEY_D);doom_set_default_int("key_use",DOOM_KEY_E);doom_set_default_int("mouse_move",0);// Mouse will not move forward
Refer to the defaults inm_misc.cpp
for the complete list.
See the filesrc/sdl_example.c
for a complete SDL example.
LIMITED USE SOFTWARE LICENSE AGREEMENT This Limited Use Software License Agreement (the "Agreement")is a legal agreement between you, the end-user, and Id Software, Inc.("ID"). By downloading or purchasing the software material, whichincludes source code (the "Source Code"), artwork data, music andsoftware tools (collectively, the "Software"), you are agreeing tobe bound by the terms of this Agreement. If you do not agree to theterms of this Agreement, promptly destroy the Software you may havedownloaded or copied.ID SOFTWARE LICENSE1. Grant of License. ID grants to you the right to use theSoftware. You have no ownership or proprietary rights in or to the Software, or the Trademark. For purposes of this section, "use" means loading the Software into RAM, as well as installation on a hard diskor other storage device. The Software, together with any archive copythereof, shall be destroyed when no longer used in accordance with this Agreement, or when the right to use the Software is terminated. You agree that the Software will not be shipped, transferred or exported into any country in violation of the U.S. Export Administration Act (or any other law governing such matters) and that you will not utilize, in any other manner, the Software in violation of any applicable law.2. Permitted Uses. For educational purposes only, you, theend-user, may use portions of the Source Code, such as particularroutines, to develop your own software, but may not duplicate theSource Code, except as noted in paragraph 4. The limited rightreferenced in the preceding sentence is hereinafter referred to as"Educational Use." By so exercising the Educational Use right youshall not obtain any ownership, copyright, proprietary or otherinterest in or to the Source Code, or any portion of the SourceCode. You may dispose of your own software in your sole discretion.With the exception of the Educational Use right, you may nototherwise use the Software, or an portion of the Software, whichincludes the Source Code, for commercial gain.3. Prohibited Uses: Under no circumstances shall you, theend-user, be permitted, allowed or authorized to commercially exploitthe Software. Neither you nor anyone at your direction shall do anyof the following acts with regard to the Software, or any portionthereof: Rent; Sell; Lease; Offer on a pay-per-play basis; Distribute for money or any other consideration; or In any other manner and through any medium whatsoevercommercially exploit or use for any commercial purpose.Notwithstanding the foregoing prohibitions, you may commerciallyexploit the software you develop by exercising the Educational Use right, referenced in paragraph 2. hereinabove.4. Copyright. The Software and all copyrights related thereto (including all characters and other images generated by the Softwareor depicted in the Software) are owned by ID and is protected byUnited States copyright laws and international treaty provisions. Id shall retain exclusive ownership and copyright in and to theSoftware and all portions of the Software and you shall have no ownership or other proprietary interest in such materials. You musttreat the Software like any other copyrighted material. You may nototherwise reproduce, copy or disclose to others, in whole or in anypart, the Software. You may not copy the written materialsaccompanying the Software. You agree to use your best efforts tosee that any user of the Software licensed hereunder complies withthis Agreement.5. NO WARRANTIES. ID DISCLAIMS ALL WARRANTIES, BOTH EXPRESSIMPLIED, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WITH RESPECTTO THE SOFTWARE. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGALRIGHTS. YOU MAY HAVE OTHER RIGHTS WHICH VARY FROM JURISDICTION TOJURISDICTION. ID DOES NOT WARRANT THAT THE OPERATION OF THE SOFTWAREWILL BE UNINTERRUPTED, ERROR FREE OR MEET YOUR SPECIFIC REQUIREMENTS.THE WARRANTY SET FORTH ABOVE IS IN LIEU OF ALL OTHER EXPRESSWARRANTIES WHETHER ORAL OR WRITTEN. THE AGENTS, EMPLOYEES, DISTRIBUTORS, AND DEALERS OF ID ARE NOT AUTHORIZED TO MAKE MODIFICATIONS TO THIS WARRANTY, OR ADDITIONAL WARRANTIES ON BEHALFOF ID. Exclusive Remedies. The Software is being offered to youfree of any charge. You agree that you have no remedy against ID, itsaffiliates, contractors, suppliers, and agents for loss or damage caused by any defect or failure in the Software regardless of the formof action, whether in contract, tort, includinegligence, strictliability or otherwise, with regard to the Software. This Agreementshall be construed in accordance with and governed by the laws of theState of Texas. Copyright and other proprietary matters will begoverned by United States laws and international treaties. IN ANY CASE, ID SHALL NOT BE LIABLE FOR LOSS OF DATA, LOSS OF PROFITS, LOSTSAVINGS, SPECIAL, INCIDENTAL, CONSEQUENTIAL, INDIRECT OR OTHERSIMILAR DAMAGES ARISING FROM BREACH OF WARRANTY, BREACH OF CONTRACT,NEGLIGENCE, OR OTHER LEGAL THEORY EVEN IF ID OR ITS AGENT HAS BEENADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANYOTHER PARTY. Some jurisdictions do not allow the exclusion orlimitation of incidental or consequential damages, so the abovelimitation or exclusion may not apply to you.