├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── TODO ├── elfloader.cpp ├── elfloader.h ├── main.cpp ├── newlib_syscalls.h ├── newlib_trans.cpp ├── newlib_trans.h ├── rv_av.h ├── rv_bits.h ├── rv_cpu.cpp ├── rv_cpu.h ├── rv_elf.h ├── rv_exceptions.h ├── rv_global.h ├── rv_memory.cpp ├── rv_memory.h ├── rv_sdl.cpp ├── rv_sdl.h └── sdldoom ├── COPYING ├── Changelog ├── DOOMLIC.TXT ├── FILES ├── FILES2 ├── Makefile ├── README.SDL ├── README.asm ├── README.b ├── README.book ├── README.gl ├── TODO ├── am_map.c ├── am_map.h ├── d_englsh.h ├── d_event.h ├── d_french.h ├── d_items.c ├── d_items.h ├── d_main.c ├── d_main.h ├── d_net.c ├── d_net.h ├── d_player.h ├── d_textur.h ├── d_think.h ├── d_ticcmd.h ├── doom1.wad ├── doomdata.h ├── doomdef.c ├── doomdef.h ├── doomstat.c ├── doomstat.h ├── doomtype.h ├── dstrings.c ├── dstrings.h ├── f_finale.c ├── f_finale.h ├── f_wipe.c ├── f_wipe.h ├── g_game.c ├── g_game.h ├── hu_lib.c ├── hu_lib.h ├── hu_stuff.c ├── hu_stuff.h ├── i_main.c ├── i_net.c ├── i_net.h ├── i_sound.c ├── i_sound.h ├── i_system.c ├── i_system.h ├── i_video.c ├── i_video.h ├── info.c ├── info.h ├── m_argv.c ├── m_argv.h ├── m_bbox.c ├── m_bbox.h ├── m_cheat.c ├── m_cheat.h ├── m_fixed.c ├── m_fixed.h ├── m_menu.c ├── m_menu.h ├── m_misc.c ├── m_misc.h ├── m_random.c ├── m_random.h ├── m_swap.c ├── m_swap.h ├── p_ceilng.c ├── p_doors.c ├── p_enemy.c ├── p_floor.c ├── p_inter.c ├── p_inter.h ├── p_lights.c ├── p_local.h ├── p_map.c ├── p_maputl.c ├── p_mobj.c ├── p_mobj.h ├── p_plats.c ├── p_pspr.c ├── p_pspr.h ├── p_saveg.c ├── p_saveg.h ├── p_setup.c ├── p_setup.h ├── p_sight.c ├── p_spec.c ├── p_spec.h ├── p_switch.c ├── p_telept.c ├── p_tick.c ├── p_tick.h ├── p_user.c ├── r_bsp.c ├── r_bsp.h ├── r_data.c ├── r_data.h ├── r_defs.h ├── r_draw.c ├── r_draw.h ├── r_local.h ├── r_main.c ├── r_main.h ├── r_plane.c ├── r_plane.h ├── r_segs.c ├── r_segs.h ├── r_sky.c ├── r_sky.h ├── r_state.h ├── r_things.c ├── r_things.h ├── rv_av_api.c ├── rv_av_api.h ├── s_sound.c ├── s_sound.h ├── sounds.c ├── sounds.h ├── st_lib.c ├── st_lib.h ├── st_stuff.c ├── st_stuff.h ├── tables.c ├── tables.h ├── v_video.c ├── v_video.h ├── w_wad.c ├── w_wad.h ├── wi_stuff.c ├── wi_stuff.h ├── z_zone.c └── z_zone.h /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | cmake-build-debug/ 4 | cmake-build-release/ 5 | *.o 6 | test 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(risc_666) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | 6 | if(APPLE) 7 | add_definitions(-DRISC_666_OSX) 8 | elseif(UNIX) 9 | add_definitions(-DRISC_666_LINUX) 10 | endif() 11 | 12 | add_definitions(-DRISC_666) 13 | add_executable(risc_666 main.cpp elfloader.h elfloader.cpp rv_memory.h rv_memory.cpp rv_global.h rv_exceptions.h rv_cpu.h rv_cpu.cpp rv_bits.h newlib_syscalls.h newlib_trans.h newlib_trans.cpp rv_sdl.h rv_av.h rv_sdl.cpp) 14 | target_link_libraries(risc_666 SDL2 pthread) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RISC-666 2 | A RISC-V user-mode emulator that runs DooM 3 | 4 | ![DooM Menu 1](https://github.com/lcq2/lcq2.github.io/blob/master/risc_666/risc_666_1.png?raw=true "Shareware screen 1") 5 | ![DooM Menu 2](https://github.com/lcq2/lcq2.github.io/blob/master/risc_666/risc_666_2.png?raw=true "Shareware screen 2") 6 | ![DooM Menu 3](https://github.com/lcq2/lcq2.github.io/blob/master/risc_666/risc_666_3.png?raw=true "Shareware screen 3") 7 | ![DooM video](https://github.com/lcq2/lcq2.github.io/blob/master/risc_666/risc_666.gif?raw=true "Video") 8 | 9 | (the video is slow because of gif conversion) 10 | ## Introduction 11 | Some months ago I came across the "new" RISC-V architecture and I found it very interesting. So I started to play around with it a bit and I discovered that I really liked it, mostly for its simplicity. So the first idea that came into my mind was of course to port DooM to it. But I needed a system where to run code, of course buying a RISC-V dev board or using qemu is too easy and trivial, so I choose to write my own RISC-V emulator and be sure that it could at least run DooM, as a general benchmark. 12 | 13 | First I wrote a general-purpose emulator, that you can find in my "trashcan" repo, to avoid being distracted by things not related to CPU emulation. Then I took out the CPU emulator from it and adapted it to run a generic ELF binary. 14 | 15 | The emulation model I choose is similar to "qemu user emulation", basically I'm only emulating the CPU itself, everything else is execute on the host operating system (i.e. I emulate all the syscalls). 16 | 17 | ## DooM version used 18 | This port of DooM is based on https://github.com/makava/sdldoom-1.10-mod, ported to SDL2. It's a very old port of DooM to SDL1.2, but I needed some reference implementation that was "legacy" enough to be still based around direct framebuffer access, instead of modern OpenGL ports. 19 | 20 | All graphics-related code runs in the CPU emulator of course, but SDL initialization and frame update happen on the host. 21 | Basically this means that from the point of view of DooM running in my emulator, the framebuffer is just a malloc'ed buffer, that gets pushed to the host through a syscall. 22 | 23 | See rv_av_api.h and rv_av_api.c for more details. 24 | 25 | ## Missing 26 | - ~~Input handling~~ 27 | - Audio 28 | - Network 29 | - Support for custom WADs and DooM mods in general 30 | - Support for Hexen, Heretic 31 | - A lot... 32 | 33 | hey this is just an experiment :D 34 | 35 | ## How to use it 36 | ### Building RISC-666 37 | To build the emulator, you should create a "build" folder under risc-666 and do an out of three build with cmake, like this: 38 | ```console 39 | [user@desktop risc-666]$ mkdir build 40 | [user@desktop risc-666]$ cd build 41 | [user@desktop build]$ cmake -DCMAKE_BUILD_TYPE=Release ../ 42 | [user@desktop build]$ make 43 | ``` 44 | 45 | ### Building DooM for RISC-V 46 | You need a RISC-V toolchain based off newlib. Ideally the one you can find here: https://github.com/riscv/riscv-gnu-toolchain. 47 | To build it: 48 | ```console 49 | [user@desktop ~]$ ./configure --prefix=/opt/toolchains/riscv32 --with-arch=rv32g --with-abi=ilp32d 50 | [user@desktop ~]$ make 51 | ``` 52 | *BE SURE TO NOT USE COMPRESSED INSTRUCTION (YOU MUST USE RV32G!!!) !!!* 53 | 54 | When the toolchain is ready, be sure to have it in your path, then inside sdldoom directory just do "make". This will create a "doom" executable. Copy "doom" executable and "doom1.wad" in the same folder where "risc_666" executable is located. 55 | Then just do: 56 | ```console 57 | [user@desktop ~]$ ./risc_666 doom 58 | ``` 59 | and DooM should start. Be sure to have SDL2 before building risc_666. 60 | To exit the emulation...send a SIGKILL to the process :D 61 | 62 | ### OSX notes 63 | This has been tested on OSX 10.12.6 with brew packages. It should work with other types of package managers, but I cannot support it. Let me know if it works. 64 | 65 | ## Coming soon 66 | - ~~Input handling~~ 67 | - Audio 68 | - Scaled "hires" mode 69 | 70 | ## About doom1.wad 71 | This is the shareware demo of course. It's the only thing I have right now to test it. 72 | 73 | ## RISC-V emulation details 74 | Currently only rv32iam is supported, it's enough for what I need. In the future I will add floating point and compressed instructions to reduce overall code size. 75 | 76 | This is a personal toy project, never intented to be a full featured RISC-V emulator, for that I'm working on riscv-emu (which is on hold for now). 77 | 78 | ### Toolchain details 79 | I'm using this toolchain: https://github.com/riscv/riscv-gnu-toolchain to build target executables. The toolchain is built in newlib mode, without compressed instructions. 80 | 81 | Basically this means that printf("%f", ff) will croak, but it's ok for now :D 82 | 83 | Using newlib means that basically network support, and other stuff, will never be there. This means that in the near future I will update to "musl", however that's not a priority right now. But updating to "musl" will make syscall emulation much, much easier. 84 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | Project goal: emulate as much as possible latest DooM versions, ideally from DooM to Hexen, possibly Final Doom. 4 | 5 | Roughtly in the order I'm going to do it: 6 | - better input handling 7 | - TEST TEST TEST 8 | - cleanup and polish rv_av_* APIs, used to interact with host audio/video 9 | - TEST TEST TEST 10 | - audio and music 11 | - TEST TEST TEST 12 | - scaled hires graphics 13 | - TEST TEST TEST 14 | - add support for compressed RISC-V instructions 15 | - TEST TEST TEST 16 | - add support for floating point (not strictly needed for old-school DooM, but it's better to have it) 17 | - TEST TEST TEST 18 | - switch from newlib to musl (this will essentially drop multiplatform support, I'll need to work on a translation layer) 19 | - TEST TEST TEST 20 | - merge with more modern ports (e.g. PrBoom and similar) or doomclassic as released in Doom3-BFG 21 | - TEST TEST TEST 22 | - add support for Hexen and Heretic, they're too good to be left out 23 | - TEST TEST TEST 24 | - JIT, either through LLVM or manual 25 | - TEST TEST TEST 26 | 27 | Yeah, there's a lot fo testing to be done...especially with full versions... 28 | -------------------------------------------------------------------------------- /elfloader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "elfloader.h" 10 | #include "rv_memory.h" 11 | 12 | #define ELF_RISCV_MACHINE 243 13 | 14 | 15 | template 16 | auto offset_ptr(const void *data, size_t offset = 0) 17 | { 18 | return reinterpret_cast(reinterpret_cast(data)+offset); 19 | } 20 | 21 | uint8_t elf_segment::protection() const 22 | { 23 | uint8_t prot_flags = 0; 24 | 25 | if ((segment_->p_flags & PF_R) == PF_R) { 26 | prot_flags |= RV_MEMORY_R; 27 | } 28 | 29 | if ((segment_->p_flags & PF_W) == PF_W) { 30 | prot_flags |= RV_MEMORY_W; 31 | } 32 | 33 | if ((segment_->p_flags & PF_X) == PF_X) { 34 | prot_flags |= RV_MEMORY_X; 35 | } 36 | 37 | return prot_flags; 38 | } 39 | 40 | bool elf_loader::check_magic(const Elf32_Ehdr *hdr) const 41 | { 42 | return hdr->e_ident[EI_MAG0] == ELFMAG0 && 43 | hdr->e_ident[EI_MAG1] == ELFMAG1 && 44 | hdr->e_ident[EI_MAG2] == ELFMAG2 && 45 | hdr->e_ident[EI_MAG3] == ELFMAG3; 46 | } 47 | 48 | elf_loader::~elf_loader() 49 | { 50 | 51 | } 52 | 53 | void elf_loader::load() 54 | { 55 | // load target ELF into memory 56 | struct stat st; 57 | if (stat(filename_.c_str(), &st) == -1) { 58 | throw std::runtime_error("stat() failed"); 59 | } 60 | 61 | buffer_.resize(st.st_size); 62 | 63 | int fd = open(filename_.c_str(), O_RDONLY); 64 | if (fd == -1) { 65 | throw std::runtime_error("open() failed"); 66 | } 67 | 68 | ssize_t bytes_read = read(fd, buffer_.data(), st.st_size); 69 | close(fd); 70 | if (bytes_read == -1 || bytes_read != st.st_size) { 71 | throw std::runtime_error("read() failed"); 72 | } 73 | 74 | const uint8_t*const buf = buffer_.data(); 75 | 76 | fprintf(stderr, "[i] checking ELF file...\n"); 77 | // check elf magic 78 | header_ = offset_ptr(buf); 79 | if (!check_magic(header_)) { 80 | throw std::runtime_error("invalid ELF file"); 81 | } 82 | 83 | // ensure this is a 32bit executable 84 | if (header_->e_ident[EI_CLASS] != ELFCLASS32) { 85 | throw std::runtime_error("only 32bit ELFs supported"); 86 | } 87 | 88 | // ensure RISC-V machine 89 | if (header_->e_machine != ELF_RISCV_MACHINE) { 90 | throw std::runtime_error("invalid e_machine, only RISC-V supported"); 91 | } 92 | 93 | // store program headers into segments_ array for easy access 94 | if (header_->e_phnum == 0) { 95 | throw std::runtime_error("invalid ELF, at least one program header required"); 96 | } 97 | 98 | fprintf(stderr, "[i] loading program segments...\n"); 99 | auto *phdr = offset_ptr(header_, header_->e_phoff); 100 | for (size_t i = 0; i < header_->e_phnum; ++i) { 101 | // we care only about PT_LOAD, since these segments are actually mapped 102 | // for now, we ignore the protection flag 103 | if (phdr->p_type == PT_LOAD) { 104 | fprintf(stderr, "[i] segment %d - vaddr: 0x%08x, vsize: %d\n", i, phdr->p_vaddr, phdr->p_memsz); 105 | segments_.emplace_back(phdr); 106 | } 107 | phdr = offset_ptr(phdr, header_->e_phentsize); 108 | } 109 | 110 | fprintf(stderr, "[i] loading symbols...\n"); 111 | // first we need to locate the symbol table within the sections 112 | auto *shdr = offset_ptr(header_, header_->e_shoff); 113 | for (size_t i = 0; i < header_->e_shnum; ++i) { 114 | if (shdr->sh_type == SHT_SYMTAB) { 115 | symbol_table_ = shdr; 116 | } 117 | sections_.push_back(shdr); 118 | shdr = offset_ptr(shdr, header_->e_shentsize); 119 | } 120 | 121 | if (sections_.empty()) { 122 | throw std::runtime_error("missing sections"); 123 | } 124 | if (symbol_table_ == nullptr) { 125 | throw std::runtime_error("missing symbol table"); 126 | } 127 | 128 | uint32_t num_syms = symbol_table_->sh_size / symbol_table_->sh_entsize; 129 | fprintf(stderr, "[i] found %d symbols...\n", num_syms); 130 | 131 | // scan all the symbol table and build a "name" => "address" map 132 | auto *psym = offset_ptr(header_, symbol_table_->sh_offset); 133 | auto strtable = offset_ptr(header_, sections_[symbol_table_->sh_link]->sh_offset); 134 | for (uint32_t i = 0; i < num_syms; ++i) { 135 | // first of all, we're interested only in GLOBAL symbols of type STT_FUNC 136 | // note: st_name IS NOT a pointer to a string, but an index into the string table 137 | if (psym->st_info == ELF32_ST_INFO(STB_GLOBAL, STT_FUNC)) { 138 | // now lookup name 139 | auto sym_name = offset_ptr(strtable, psym->st_name); 140 | symbols_.emplace(sym_name, psym->st_value); 141 | } 142 | psym = offset_ptr(psym, symbol_table_->sh_entsize); 143 | } 144 | 145 | fprintf(stderr, "[i] entry point at 0x%08x\n", entry_point()); 146 | } 147 | -------------------------------------------------------------------------------- /elfloader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "rv_elf.h" 10 | 11 | class elf_segment 12 | { 13 | public: 14 | elf_segment() = default; 15 | elf_segment(const Elf32_Phdr* s) : segment_{s} {} 16 | 17 | auto offset() const { return segment_->p_offset; } 18 | auto virtual_address() const { return segment_->p_vaddr; } 19 | auto physical_address() const { return segment_->p_paddr; } 20 | auto file_size() const { return segment_->p_filesz; } 21 | auto memory_size() const { return segment_->p_memsz; } 22 | auto alignment() const { return segment_->p_align; } 23 | uint8_t protection() const; 24 | 25 | private: 26 | const Elf32_Phdr* segment_ = nullptr; 27 | }; 28 | 29 | class elf_loader 30 | { 31 | public: 32 | explicit elf_loader(std::string filename) : filename_{std::move(filename)} {} 33 | ~elf_loader(); 34 | void load(); 35 | 36 | const auto& segments() const { return segments_; } 37 | 38 | template 39 | const T* pointer_to(const elf_segment& segm) const 40 | { 41 | return reinterpret_cast(buffer_.data() + segm.offset()); 42 | } 43 | 44 | Elf32_Addr entry_point() const { return header_->e_entry; } 45 | 46 | private: 47 | bool check_magic(const Elf32_Ehdr* hdr) const; 48 | 49 | private: 50 | std::string filename_; 51 | std::vector buffer_; 52 | std::vector segments_; 53 | std::vector sections_; 54 | const Elf32_Shdr* symbol_table_ = nullptr; 55 | 56 | // this definitely takes too much memory, needs to be fixed in the future 57 | std::unordered_map symbols_; 58 | const Elf32_Ehdr *header_ = nullptr; 59 | }; 60 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "elfloader.h" 7 | #include "rv_memory.h" 8 | #include "rv_cpu.h" 9 | #include "rv_global.h" 10 | 11 | void usage(const char *path) 12 | { 13 | fprintf(stderr, "Usage: %s [-m memory_size] [arg 1] ... [argn n]\n", path); 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | int opt = -1; 19 | unsigned long int convres = (unsigned long int)-1; 20 | rv_uint memory_size = 128_MiB; 21 | int ret_val = EXIT_SUCCESS; 22 | 23 | while((opt = getopt(argc, argv, "m:")) != -1) { 24 | switch (opt) { 25 | case 'm': 26 | convres = strtoul(optarg, nullptr, 10); 27 | if (convres > 512_MiB || errno == ERANGE) { 28 | fprintf(stderr, "[e] error: > 512 MiB is too much for DooM, sorry...\n"); 29 | exit(EXIT_FAILURE); 30 | } 31 | memory_size = (rv_uint)convres; 32 | break; 33 | 34 | default: 35 | usage(argv[0]); 36 | exit(EXIT_FAILURE); 37 | } 38 | } 39 | 40 | if (optind >= argc) { 41 | fprintf(stderr, "missing executable to emulate!\n"); 42 | exit(EXIT_FAILURE); 43 | } 44 | 45 | elf_loader loader{std::string(argv[optind])}; 46 | try { 47 | loader.load(); 48 | rv_memory memory(memory_size); 49 | 50 | // first 64k are mapped RWX 51 | memory.protect_region(0, 0x10000, RV_MEMORY_RWX); 52 | 53 | rv_uint last_vaddr = 0; 54 | rv_uint last_vsize = 0; 55 | 56 | // this is wrong, there's no guarantee that the last segment comes last in memory 57 | // but for now it's ok...for newlib layout at least 58 | for (const auto& seg : loader.segments()) { 59 | last_vaddr = seg.virtual_address(); 60 | last_vsize = seg.memory_size(); 61 | memory.set_region(last_vaddr, loader.pointer_to(seg), seg.file_size()); 62 | memory.protect_region(last_vaddr, last_vsize, seg.protection()); 63 | } 64 | 65 | // TODO: align to segment->alignment 66 | if (last_vsize % 0x1000 != 0) 67 | last_vsize = last_vsize + (0x1000 - (last_vsize%0x1000)); 68 | 69 | rv_uint end_of_data = last_vaddr + last_vsize; 70 | 71 | // setup one guard page before the stack 72 | end_of_data += 0x1000; 73 | 74 | // setup memory protection for stack (rw) 75 | memory.protect_region(end_of_data, memory.stack_size(), RV_MEMORY_RW); 76 | 77 | // the stack starts right after the first guard page 78 | memory.set_stack(end_of_data + memory.stack_size()); 79 | end_of_data += memory.stack_size(); 80 | 81 | memory.prepare_environment(argc, argv, optind); 82 | 83 | // setup a second guard page after the stack 84 | end_of_data += 0x1000; 85 | 86 | // finally set the program break and map all the remaining ram 87 | memory.set_brk(end_of_data); 88 | memory.protect_region(end_of_data, memory.ram_end() - end_of_data, RV_MEMORY_RW); 89 | 90 | rv_cpu cpu(memory); 91 | cpu.reset(loader.entry_point()); 92 | #ifdef PROFILEME 93 | // start profiling thread 94 | std::thread([&cpu]() { 95 | using namespace std::chrono_literals; 96 | uint64_t prev_cycle = cpu.cycle_count(); 97 | 98 | for (;;) { 99 | std::this_thread::sleep_for(1s); 100 | uint64_t cur_cycle = cpu.cycle_count(); 101 | uint64_t delta = cur_cycle - prev_cycle; 102 | prev_cycle = cur_cycle; 103 | fprintf(stderr, "[i] MIPS: %.2f\n", double(delta)/double(1e6)); 104 | } 105 | }).detach(); 106 | #endif 107 | 108 | for (;;) { 109 | cpu.run(500000); 110 | if (cpu.emulation_exit()) 111 | break; 112 | } 113 | fprintf(stderr, "[i] target exited with: %d\n", cpu.emulation_exit_status()); 114 | } 115 | catch(const std::runtime_error& ex) { 116 | fprintf(stderr, "[e] error: %s", ex.what()); 117 | ret_val = EXIT_FAILURE; 118 | 119 | } 120 | return ret_val; 121 | } -------------------------------------------------------------------------------- /newlib_syscalls.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define SYS_getcwd 17 4 | #define SYS_dup 23 5 | #define SYS_fcntl 25 6 | #define SYS_faccessat 48 7 | #define SYS_chdir 49 8 | #define SYS_openat 56 9 | #define SYS_close 57 10 | #define SYS_getdents 61 11 | #define SYS_lseek 62 12 | #define SYS_read 63 13 | #define SYS_write 64 14 | #define SYS_writev 66 15 | #define SYS_pread 67 16 | #define SYS_pwrite 68 17 | #define SYS_fstatat 79 18 | #define SYS_fstat 80 19 | #define SYS_exit 93 20 | #define SYS_exit_group 94 21 | #define SYS_kill 129 22 | #define SYS_rt_sigaction 134 23 | #define SYS_times 153 24 | #define SYS_uname 160 25 | #define SYS_gettimeofday 169 26 | #define SYS_getpid 172 27 | #define SYS_getuid 174 28 | #define SYS_geteuid 175 29 | #define SYS_getgid 176 30 | #define SYS_getegid 177 31 | #define SYS_brk 214 32 | #define SYS_munmap 215 33 | #define SYS_mremap 216 34 | #define SYS_mmap 222 35 | #define SYS_open 1024 36 | #define SYS_link 1025 37 | #define SYS_unlink 1026 38 | #define SYS_mkdir 1030 39 | #define SYS_access 1033 40 | #define SYS_stat 1038 41 | #define SYS_lstat 1039 42 | #define SYS_time 1062 43 | #define SYS_getmainvars 2011 -------------------------------------------------------------------------------- /newlib_trans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "newlib_trans.h" 6 | 7 | int newlib_translate_open_flags(int newlib_flags) 8 | { 9 | #define NEWLIB__FOPEN (-1) /* from sys/file.h, kernel use only */ 10 | #define NEWLIB__FREAD 0x0001 /* read enabled */ 11 | #define NEWLIB__FWRITE 0x0002 /* write enabled */ 12 | #define NEWLIB__FAPPEND 0x0008 /* append (writes guaranteed at the end) */ 13 | #define NEWLIB__FMARK 0x0010 /* internal; mark during gc() */ 14 | #define NEWLIB__FDEFER 0x0020 /* internal; defer for next gc pass */ 15 | #define NEWLIB__FASYNC 0x0040 /* signal pgrp when data ready */ 16 | #define NEWLIB__FSHLOCK 0x0080 /* BSD flock() shared lock present */ 17 | #define NEWLIB__FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ 18 | #define NEWLIB__FCREAT 0x0200 /* open with file create */ 19 | #define NEWLIB__FTRUNC 0x0400 /* open with truncation */ 20 | #define NEWLIB__FEXCL 0x0800 /* error on open if file exists */ 21 | #define NEWLIB__FNBIO 0x1000 /* non blocking I/O (sys5 style) */ 22 | #define NEWLIB__FSYNC 0x2000 /* do all writes synchronously */ 23 | #define NEWLIB__FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ 24 | #define NEWLIB__FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ 25 | #define NEWLIB__FNOCTTY 0x8000 /* don't assign a ctty on this open */ 26 | #define NEWLIB_O_ACCMODE (NEWLIB_O_RDONLY|NEWLIB_O_WRONLY|NEWLIB_O_RDWR) 27 | #define NEWLIB_O_RDONLY 0 /* +1 == FREAD */ 28 | #define NEWLIB_O_WRONLY 1 /* +1 == FWRITE */ 29 | #define NEWLIB_O_RDWR 2 /* +1 == FREAD|FWRITE */ 30 | #define NEWLIB_O_APPEND NEWLIB__FAPPEND 31 | #define NEWLIB_O_CREAT NEWLIB__FCREAT 32 | #define NEWLIB_O_TRUNC NEWLIB__FTRUNC 33 | #define NEWLIB_O_EXCL NEWLIB__FEXCL 34 | #define NEWLIB_O_SYNC NEWLIB__FSYNC 35 | #define NEWLIB_O_NONBLOCK NEWLIB__FNONBLOCK 36 | #define NEWLIB_O_NOCTTY NEWLIB__FNOCTTY 37 | 38 | int flags = 0; 39 | if (newlib_flags & NEWLIB_O_RDONLY) 40 | flags |= O_RDONLY; 41 | if (newlib_flags & NEWLIB_O_WRONLY) 42 | flags |= O_WRONLY; 43 | if (newlib_flags & NEWLIB_O_RDWR) 44 | flags |= O_RDWR; 45 | if (newlib_flags & NEWLIB_O_APPEND) 46 | flags |= O_APPEND; 47 | if (newlib_flags & NEWLIB_O_CREAT) 48 | flags |= O_CREAT; 49 | if (newlib_flags & NEWLIB_O_TRUNC) 50 | flags |= O_TRUNC; 51 | if (newlib_flags & NEWLIB_O_EXCL) 52 | flags |= O_EXCL; 53 | if (newlib_flags & NEWLIB_O_SYNC) 54 | flags |= O_SYNC; 55 | if (newlib_flags & NEWLIB_O_NONBLOCK) 56 | flags |= O_NONBLOCK; 57 | if (newlib_flags & NEWLIB_O_NOCTTY) 58 | flags |= O_NOCTTY; 59 | return flags; 60 | } 61 | 62 | void newlib_translate_stat(newlib_stat *dst, struct stat *src) 63 | { 64 | dst->st_dev = src->st_dev; 65 | dst->st_ino = src->st_ino; 66 | dst->st_mode = src->st_mode; 67 | dst->st_nlink = (unsigned int)src->st_nlink; 68 | dst->st_uid = src->st_uid; 69 | dst->st_gid = src->st_gid; 70 | dst->st_rdev = src->st_rdev; 71 | dst->st_size = src->st_size; 72 | dst->st_blksize = (int)src->st_blksize; 73 | dst->st_blocks = src->st_blocks; 74 | #ifdef RISC_666_LINUX 75 | dst->st_atim.tv_sec = (uint32_t)src->st_atim.tv_sec; 76 | dst->st_atim.tv_nsec = (uint32_t)src->st_atim.tv_nsec; 77 | dst->st_mtim.tv_sec = (uint32_t)src->st_mtim.tv_sec; 78 | dst->st_mtim.tv_nsec = (uint32_t)src->st_mtim.tv_nsec; 79 | dst->st_ctim.tv_sec = (uint32_t)src->st_ctim.tv_sec; 80 | dst->st_ctim.tv_nsec = (uint32_t)src->st_ctim.tv_nsec; 81 | #elif RISC_666_OSX 82 | dst->st_atim.tv_sec = (uint32_t)src->st_atimespec.tv_sec; 83 | dst->st_atim.tv_nsec = (uint32_t)src->st_atimespec.tv_nsec; 84 | dst->st_mtim.tv_sec = (uint32_t)src->st_mtimespec.tv_sec; 85 | dst->st_mtim.tv_nsec = (uint32_t)src->st_mtimespec.tv_nsec; 86 | dst->st_ctim.tv_sec = (uint32_t)src->st_ctimespec.tv_sec; 87 | dst->st_ctim.tv_nsec = (uint32_t)src->st_ctimespec.tv_nsec; 88 | #endif 89 | } 90 | 91 | void newlib_translate_timeval(newlib_timeval *dst, struct timeval *src) 92 | { 93 | dst->tv_sec = (uint32_t)src->tv_sec; 94 | dst->tv_usec = (uint32_t)src->tv_usec; 95 | } -------------------------------------------------------------------------------- /newlib_trans.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct newlib_timeval 5 | { 6 | uint32_t tv_sec; 7 | uint32_t tv_usec; 8 | }; 9 | 10 | struct newlib_timespec 11 | { 12 | uint32_t tv_sec; 13 | uint32_t tv_nsec; 14 | }; 15 | 16 | struct newlib_stat 17 | { 18 | unsigned long long st_dev; 19 | unsigned long long st_ino; 20 | unsigned int st_mode; 21 | unsigned int st_nlink; 22 | unsigned int st_uid; 23 | unsigned int st_gid; 24 | unsigned long long st_rdev; 25 | unsigned long long __pad1; 26 | long long st_size; 27 | int st_blksize; 28 | int __pad2; 29 | long long st_blocks; 30 | struct newlib_timespec st_atim; 31 | struct newlib_timespec st_mtim; 32 | struct newlib_timespec st_ctim; 33 | int __glibc_reserved[2]; 34 | }; 35 | 36 | int newlib_translate_open_flags(int newlib_flags); 37 | void newlib_translate_stat(newlib_stat *dst, struct stat *src); 38 | void newlib_translate_timeval(newlib_timeval *dst, struct timeval *src); -------------------------------------------------------------------------------- /rv_bits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | struct rv_bitfield 6 | { 7 | using value_type = T; 8 | 9 | static constexpr value_type mask = l << s; 10 | static constexpr value_type shamt = s; 11 | 12 | constexpr operator value_type() const { return mask; } 13 | }; 14 | 15 | // & operator 16 | template 17 | constexpr T operator &(T val, const rv_bitfield& bitf) 18 | { 19 | return val & bitf.mask; 20 | } 21 | 22 | // | operator 23 | template 24 | constexpr T operator |(T val, const rv_bitfield& bitf) 25 | { 26 | return val | bitf.mask; 27 | } 28 | 29 | template 30 | constexpr T operator <<(T val, const rv_bitfield& bitf) 31 | { 32 | return val << bitf.shamt; 33 | } 34 | 35 | template 36 | constexpr T operator >>(T val, const rv_bitfield& bitf) 37 | { 38 | return val >> bitf.shamt; 39 | } 40 | -------------------------------------------------------------------------------- /rv_cpu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "rv_global.h" 6 | #include "rv_memory.h" 7 | #include "rv_sdl.h" 8 | 9 | class rv_cpu 10 | { 11 | public: 12 | rv_cpu() = delete; 13 | explicit rv_cpu(rv_memory& memory); 14 | 15 | void reset(rv_uint pc = 0); 16 | void run(size_t nCycles); 17 | 18 | uint64_t cycle_count() const { return cycle_; } 19 | 20 | bool emulation_exit() const { return emulation_exit_; } 21 | int emulation_exit_status() const { return emulation_exit_status_; } 22 | 23 | private: 24 | uint32_t decode_rd(uint32_t insn) const { return (insn >> 7) & 0x1F; } 25 | uint32_t decode_rs1(uint32_t insn) const { return (insn >> 15) & 0x1F; } 26 | uint32_t decode_rs2(uint32_t insn) const { return (insn >> 20) & 0x1F; } 27 | uint32_t decode_funct3(uint32_t insn) const { return (insn >> 12) & 0b111; } 28 | 29 | // extract [low, high] bits from a 32bit value 30 | uint32_t bits(uint32_t val, uint32_t low, uint32_t high) const { return (val >> low) & ((1 << (high - low + 1)) - 1); } 31 | 32 | // extract a single bit from a 32bit value 33 | uint32_t bit(uint32_t val, uint32_t bit) const { return (val >> bit) & 1; } 34 | 35 | void next_insn(rv_uint cnt = 4) { pc_ += cnt; } 36 | void jump_insn(rv_uint newpc) { pc_ = newpc; } 37 | 38 | void raise_exception(rv_exception code); 39 | 40 | void raise_illegal_instruction() { raise_exception(rv_exception::illegal_instruction); } 41 | void raise_memory_exception() { raise_exception(memory_.last_exception()); } 42 | void raise_breakpoint_exception() { raise_exception(rv_exception::breakpoint); } 43 | 44 | inline void execute_lui(uint32_t insn); 45 | inline void execute_auipc(uint32_t insn); 46 | inline void execute_jal(uint32_t insn); 47 | inline void execute_jalr(uint32_t insn); 48 | inline void execute_branch(uint32_t insn); 49 | inline void execute_load(uint32_t insn); 50 | inline void execute_store(uint32_t insn); 51 | inline void execute_amo(uint32_t insn); 52 | inline void execute_imm(uint32_t insn); 53 | inline void execute_op(uint32_t insn); 54 | inline void execute_misc_mem(uint32_t insn); 55 | inline void execute_system(uint32_t insn); 56 | 57 | bool csr_read(uint32_t csr, rv_uint& csr_value, bool write_back = false); 58 | bool csr_write(uint32_t csr, rv_uint csr_value); 59 | 60 | bool csr_rw(uint32_t csr, uint32_t rd, rv_uint new_value, uint32_t csrop); 61 | 62 | void dump_regs(); 63 | 64 | void stop_emulation(int exit_code); 65 | void handle_user_exception(); 66 | void handle_illegal_instruction(); 67 | void handle_memory_access_fault(); 68 | void handle_breakpoint_exception(); 69 | void dispatch_syscall(rv_uint syscall_no, 70 | rv_uint arg0, 71 | rv_uint arg1, 72 | rv_uint arg2, 73 | rv_uint arg3, 74 | rv_uint arg4, 75 | rv_uint arg5 76 | ); 77 | 78 | // syscalls emulation 79 | rv_uint syscall_fstat(rv_uint arg0, rv_uint arg1); 80 | rv_uint syscall_stat(rv_uint arg0, rv_uint arg1); 81 | rv_uint syscall_brk(rv_uint arg0); 82 | rv_uint syscall_open(rv_uint arg0, rv_uint arg1, rv_uint arg2); 83 | rv_uint syscall_write(rv_uint arg0, rv_uint arg1, rv_uint arg2); 84 | rv_uint syscall_read(rv_uint arg0, rv_uint arg1, rv_uint arg2); 85 | rv_uint syscall_close(rv_uint arg0); 86 | rv_uint syscall_lseek(rv_uint arg0, rv_uint arg1, rv_uint arg2); 87 | rv_uint syscall_exit(rv_uint arg0); 88 | rv_uint syscall_openat(rv_uint arg0, rv_uint arg1, rv_uint arg2, rv_uint arg3); 89 | rv_uint syscall_gettimeofday(rv_uint arg0, rv_uint arg1); 90 | 91 | private: 92 | rv_uint pc_; 93 | std::array regs_; 94 | rv_uint amo_res_; 95 | rv_memory& memory_; 96 | rv_sdl sdl_; 97 | 98 | bool exception_raised_; 99 | rv_exception exception_code_; 100 | 101 | bool emulation_exit_; 102 | int emulation_exit_status_; 103 | 104 | // Counter/Timers 105 | uint64_t time_; 106 | uint64_t cycle_; 107 | uint64_t instret_; 108 | }; -------------------------------------------------------------------------------- /rv_exceptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "rv_global.h" 3 | 4 | enum class rv_exception: uint32_t 5 | { 6 | // interrupts 7 | machine_software_interrupt = (1U << 31) | 3, 8 | machine_timer_interrupt = (1U << 31) | 7, 9 | machine_external_interrupt = (1U << 31) | 11, 10 | local_interrupt0 = (1U << 31) | 16, 11 | local_interrupt1 = (1U << 31) | 17, 12 | local_interrupt2 = (1U << 31) | 18, 13 | local_interrupt3 = (1U << 31) | 19, 14 | local_interrupt4 = (1U << 31) | 20, 15 | local_interrupt5 = (1U << 31) | 21, 16 | local_interrupt6 = (1U << 31) | 22, 17 | local_interrupt7 = (1U << 31) | 23, 18 | local_interrupt8 = (1U << 31) | 24, 19 | local_interrupt9 = (1U << 31) | 25, 20 | local_interrupt10 = (1U << 31) | 26, 21 | local_interrupt11 = (1U << 31) | 27, 22 | local_interrupt12 = (1U << 31) | 28, 23 | local_interrupt13 = (1U << 31) | 29, 24 | local_interrupt14 = (1U << 31) | 30, 25 | local_interrupt15 = (1U << 31) | 31, 26 | 27 | // exceptions 28 | instruction_address_misaligned = 0, 29 | instruction_access_fault = 1, 30 | illegal_instruction = 2, 31 | breakpoint = 3, 32 | load_address_misaligned = 4, 33 | load_access_fault = 5, 34 | store_address_misaligned = 6, 35 | store_access_fault = 7, 36 | ecall_from_umode = 8, 37 | ecall_from_smode = 9, 38 | ecall_from_mmode = 11, 39 | instruction_page_fault = 12, 40 | load_page_fault = 13, 41 | store_page_fault = 15 42 | }; -------------------------------------------------------------------------------- /rv_global.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define likely(x) __builtin_expect(!!(x), 1) 5 | #define unlikely(x) __builtin_expect(!!(x), 0) 6 | 7 | // native integer type (not C integer) 8 | // we only support XLEN == 32, so this is always a 32bit integer (signed/unsigned) 9 | using rv_uint = uint32_t; 10 | using rv_int = int32_t; 11 | 12 | // native long integer type (not C long) 13 | // 64bit for XLEN == 32, 128bit for XLEN == 64 14 | using rv_ulong = uint64_t; 15 | using rv_long = int64_t; 16 | 17 | constexpr unsigned long long operator ""_MiB(unsigned long long v) 18 | { 19 | return v*1024*1024; 20 | } -------------------------------------------------------------------------------- /rv_memory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "rv_exceptions.h" 5 | #include "rv_memory.h" 6 | 7 | constexpr rv_uint RV_STACK_SIZE = 4*1024*1024; 8 | 9 | rv_memory::rv_memory(rv_uint ram_size) 10 | { 11 | ram_ = new uint8_t[ram_size](); 12 | ram_begin_ = 0; 13 | ram_end_ = ram_size; 14 | 15 | // reserve ram_size/4096 "entries" in our mpu 16 | mpu_.resize(ram_size >> 12); 17 | std::fill(mpu_.begin(), mpu_.end(), 0); 18 | } 19 | 20 | rv_memory::~rv_memory() 21 | { 22 | delete [] ram_; 23 | } 24 | 25 | void rv_memory::set_region(rv_uint address, const uint8_t *data, size_t len) 26 | { 27 | assert(address <= (ram_end_-len)); 28 | assert(data != nullptr); 29 | 30 | // fill region with provided data 31 | memcpy(ram_+address, data, len); 32 | } 33 | 34 | void rv_memory::protect_region(rv_uint address, size_t len, uint8_t prot) 35 | { 36 | assert(address <= (ram_end_-len)); 37 | 38 | // setup protection flags for the requested range up to page boundary 39 | // this will overwrite whatever flags were set previously 40 | if (len % 0x1000 != 0) 41 | len = len + (0x1000 - len%0x1000); 42 | 43 | auto npages = len >> 12; 44 | auto pageindex = address >> 12; 45 | std::fill(mpu_.begin()+pageindex, mpu_.begin()+pageindex+npages+1, prot); 46 | } 47 | 48 | bool rv_memory::set_brk(rv_uint offset) 49 | { 50 | if (offset > ram_end_ || offset < stack_begin_) 51 | return false; 52 | brk_ = offset; 53 | return true; 54 | } 55 | 56 | void rv_memory::prepare_environment(int argc, char *argv[], int optind) 57 | { 58 | // optind points to the first non option argument, which is the target to emulate 59 | // after the executable name, we have the arguments to pass to the emulated target 60 | int num_args = argc - optind; 61 | 62 | // 1 entry for argc 63 | // n entries for argv[n] 64 | // 1 entry for the null entry 65 | rv_uint target_stack = stack_begin() - sizeof(rv_uint) -(num_args+1)*sizeof(rv_uint); 66 | stack_pointer_ = target_stack; 67 | 68 | write(target_stack, num_args); 69 | target_stack += sizeof(rv_uint); 70 | 71 | // argument strings are stored at 0x100 72 | // we cannot use 0x0 because according to RISC-V specs, reading from 0 is hardwired to fault 73 | char *target_env = reinterpret_cast(ram_ptr(0x100)); 74 | 75 | // fix this mess... 76 | while (optind < argc) { 77 | auto arg_len = strlen(argv[optind]); 78 | if (arg_len > 31) 79 | arg_len = 31; 80 | strncpy(target_env, argv[optind], arg_len); 81 | target_env[arg_len] = '\0'; 82 | write(target_stack, target_ptr((uint8_t *) target_env)); 83 | target_stack += sizeof(rv_uint); 84 | target_env += arg_len+1; 85 | optind += 1; 86 | } 87 | write(target_stack, 0x00); 88 | } 89 | 90 | void rv_memory::set_stack(rv_uint stack_begin) 91 | { 92 | if (stack_begin > ram_end_) { 93 | throw std::runtime_error("invalid stack location"); 94 | } 95 | stack_begin_ = stack_begin; 96 | stack_end_ = stack_begin - stack_size(); 97 | } -------------------------------------------------------------------------------- /rv_memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "rv_global.h" 5 | #include "rv_bits.h" 6 | #include "rv_exceptions.h" 7 | 8 | constexpr auto RV_MEMORY_R = rv_bitfield<1,0,uint8_t>{}; 9 | constexpr auto RV_MEMORY_W = rv_bitfield<1,1,uint8_t>{}; 10 | constexpr auto RV_MEMORY_X = rv_bitfield<1,2,uint8_t>{}; 11 | 12 | constexpr auto RV_MEMORY_RW = RV_MEMORY_R | RV_MEMORY_W; 13 | constexpr auto RV_MEMORY_RX = RV_MEMORY_R | RV_MEMORY_X; 14 | constexpr auto RV_MEMORY_RWX = RV_MEMORY_R | RV_MEMORY_W | RV_MEMORY_X; 15 | 16 | class rv_memory 17 | { 18 | public: 19 | rv_memory() = delete; 20 | rv_memory(rv_uint ram_size); 21 | ~rv_memory(); 22 | 23 | void set_region(rv_uint address, const uint8_t* data, size_t len); 24 | void protect_region(rv_uint address, size_t len, uint8_t prot); 25 | 26 | rv_uint fault_address() const { return fault_address_; } 27 | rv_exception last_exception() const { return last_exception_; } 28 | 29 | 30 | template bool fetch(rv_uint address, T& value) const 31 | { 32 | if (address <= (ram_end_ - sizeof(T)) && ((mpu_[address >> 12] & RV_MEMORY_RX) == RV_MEMORY_RX)) { 33 | value = *(T *)(ram_ + address); 34 | return true; 35 | } 36 | fault_address_ = address; 37 | last_exception_ = rv_exception::instruction_access_fault; 38 | return false; 39 | } 40 | 41 | template bool read(rv_uint address, T& value) const 42 | { 43 | if (address <= (ram_end_ - sizeof(T)) && ((mpu_[address >> 12] & RV_MEMORY_R) == RV_MEMORY_R)) { 44 | value = *(T *)(ram_ + address); 45 | return true; 46 | } 47 | fault_address_ = address; 48 | last_exception_ = rv_exception::load_access_fault; 49 | return false; 50 | } 51 | 52 | template bool write(rv_uint address, T value) 53 | { 54 | if (address <= (ram_end_ - sizeof(T)) && ((mpu_[address >> 12] & RV_MEMORY_W) == RV_MEMORY_W)) { 55 | *(T *)(ram_ + address) = value; 56 | return true; 57 | } 58 | fault_address_ = address; 59 | last_exception_ = rv_exception::store_access_fault; 60 | return false; 61 | } 62 | 63 | bool set_brk(rv_uint offset); 64 | rv_uint brk() const { return brk_; } 65 | 66 | constexpr rv_uint stack_size() const { return (rv_uint)4_MiB; } 67 | 68 | rv_uint stack_begin() const { return stack_begin_; } 69 | void set_stack(rv_uint stack_begin); 70 | rv_uint stack_pointer() const { return stack_pointer_; } 71 | rv_uint stack_end() const { return stack_end_; } 72 | 73 | rv_uint ram_begin() const { return ram_begin_; } 74 | rv_uint ram_end() const { return ram_end_; } 75 | uint8_t* ram_ptr(rv_uint offset) { return ram_+offset; } 76 | rv_uint target_ptr(uint8_t *_ram_ptr) const { return (rv_uint)(_ram_ptr - ram_); } 77 | 78 | void prepare_environment(int argc, char *argv[], int optind); 79 | private: 80 | uint8_t *ram_; 81 | rv_uint ram_begin_; 82 | rv_uint ram_end_; 83 | rv_uint stack_begin_; 84 | rv_uint stack_end_; 85 | rv_uint stack_pointer_; 86 | rv_uint brk_; 87 | std::vector mpu_; 88 | 89 | mutable rv_uint fault_address_ = 0; 90 | mutable rv_exception last_exception_; 91 | }; 92 | -------------------------------------------------------------------------------- /rv_sdl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "rv_av.h" 5 | #include "rv_global.h" 6 | #include "rv_memory.h" 7 | 8 | class rv_sdl 9 | { 10 | public: 11 | rv_sdl() = delete; 12 | explicit rv_sdl(rv_memory& memory) : memory_{memory} {} 13 | 14 | rv_uint syscall_init(rv_uint arg0, rv_uint arg1); 15 | rv_uint syscall_set_framebuffer(rv_uint arg0); 16 | rv_uint syscall_delay(rv_uint arg0); 17 | rv_uint syscall_update(); 18 | rv_uint syscall_set_palette(rv_uint arg0, rv_uint arg1); 19 | rv_uint syscall_poll_event(rv_uint arg0); 20 | rv_uint syscall_get_ticks(); 21 | rv_uint syscall_get_mouse_state(rv_uint arg0, rv_uint arg1); 22 | rv_uint syscall_warp_mouse(rv_uint arg0, rv_uint arg1); 23 | rv_uint syscall_shutdown(); 24 | 25 | private: 26 | void log_sdl_error(const char* syscall_name, const char* sdl_func); 27 | 28 | private: 29 | rv_memory& memory_; 30 | SDL_Window *main_window_ = nullptr; 31 | SDL_Renderer *main_renderer_ = nullptr; 32 | SDL_Surface *main_surface_ = nullptr; 33 | SDL_Surface *screen_surface_ = nullptr; 34 | SDL_Texture *main_texture_ = nullptr; 35 | int width_ = -1; 36 | int height_ = -1; 37 | }; -------------------------------------------------------------------------------- /sdldoom/DOOMLIC.TXT: -------------------------------------------------------------------------------- 1 | 2 | 3 | LIMITED USE SOFTWARE LICENSE AGREEMENT 4 | 5 | This Limited Use Software License Agreement (the "Agreement") 6 | is a legal agreement between you, the end-user, and Id Software, Inc. 7 | ("ID"). By downloading or purchasing the software material, which 8 | includes source code (the "Source Code"), artwork data, music and 9 | software tools (collectively, the "Software"), you are agreeing to 10 | be bound by the terms of this Agreement. If you do not agree to the 11 | terms of this Agreement, promptly destroy the Software you may have 12 | downloaded or copied. 13 | 14 | ID SOFTWARE LICENSE 15 | 16 | 1. Grant of License. ID grants to you the right to use the 17 | Software. You have no ownership or proprietary rights in or to the 18 | Software, or the Trademark. For purposes of this section, "use" means 19 | loading the Software into RAM, as well as installation on a hard disk 20 | or other storage device. The Software, together with any archive copy 21 | thereof, shall be destroyed when no longer used in accordance with 22 | this Agreement, or when the right to use the Software is terminated. 23 | You agree that the Software will not be shipped, transferred or 24 | exported into any country in violation of the U.S. Export 25 | Administration Act (or any other law governing such matters) and that 26 | you will not utilize, in any other manner, the Software in violation 27 | of any applicable law. 28 | 29 | 2. Permitted Uses. For educational purposes only, you, the 30 | end-user, may use portions of the Source Code, such as particular 31 | routines, to develop your own software, but may not duplicate the 32 | Source Code, except as noted in paragraph 4. The limited right 33 | referenced in the preceding sentence is hereinafter referred to as 34 | "Educational Use." By so exercising the Educational Use right you 35 | shall not obtain any ownership, copyright, proprietary or other 36 | interest in or to the Source Code, or any portion of the Source 37 | Code. You may dispose of your own software in your sole discretion. 38 | With the exception of the Educational Use right, you may not 39 | otherwise use the Software, or an portion of the Software, which 40 | includes the Source Code, for commercial gain. 41 | 42 | 3. Prohibited Uses: Under no circumstances shall you, the 43 | end-user, be permitted, allowed or authorized to commercially exploit 44 | the Software. Neither you nor anyone at your direction shall do any 45 | of the following acts with regard to the Software, or any portion 46 | thereof: 47 | 48 | Rent; 49 | 50 | Sell; 51 | 52 | Lease; 53 | 54 | Offer on a pay-per-play basis; 55 | 56 | Distribute for money or any other consideration; or 57 | 58 | In any other manner and through any medium whatsoever 59 | commercially exploit or use for any commercial purpose. 60 | 61 | Notwithstanding the foregoing prohibitions, you may commercially 62 | exploit the software you develop by exercising the Educational Use 63 | right, referenced in paragraph 2. hereinabove. 64 | 65 | 4. Copyright. The Software and all copyrights related thereto 66 | (including all characters and other images generated by the Software 67 | or depicted in the Software) are owned by ID and is protected by 68 | United States copyright laws and international treaty provisions. 69 | Id shall retain exclusive ownership and copyright in and to the 70 | Software and all portions of the Software and you shall have no 71 | ownership or other proprietary interest in such materials. You must 72 | treat the Software like any other copyrighted material. You may not 73 | otherwise reproduce, copy or disclose to others, in whole or in any 74 | part, the Software. You may not copy the written materials 75 | accompanying the Software. You agree to use your best efforts to 76 | see that any user of the Software licensed hereunder complies with 77 | this Agreement. 78 | 79 | 5. NO WARRANTIES. ID DISCLAIMS ALL WARRANTIES, BOTH EXPRESS 80 | IMPLIED, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 81 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WITH RESPECT 82 | TO THE SOFTWARE. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL 83 | RIGHTS. YOU MAY HAVE OTHER RIGHTS WHICH VARY FROM JURISDICTION TO 84 | JURISDICTION. ID DOES NOT WARRANT THAT THE OPERATION OF THE SOFTWARE 85 | WILL BE UNINTERRUPTED, ERROR FREE OR MEET YOUR SPECIFIC REQUIREMENTS. 86 | THE WARRANTY SET FORTH ABOVE IS IN LIEU OF ALL OTHER EXPRESS 87 | WARRANTIES WHETHER ORAL OR WRITTEN. THE AGENTS, EMPLOYEES, 88 | DISTRIBUTORS, AND DEALERS OF ID ARE NOT AUTHORIZED TO MAKE 89 | MODIFICATIONS TO THIS WARRANTY, OR ADDITIONAL WARRANTIES ON BEHALF 90 | OF ID. 91 | 92 | Exclusive Remedies. The Software is being offered to you 93 | free of any charge. You agree that you have no remedy against ID, its 94 | affiliates, contractors, suppliers, and agents for loss or damage 95 | caused by any defect or failure in the Software regardless of the form 96 | of action, whether in contract, tort, includinegligence, strict 97 | liability or otherwise, with regard to the Software. This Agreement 98 | shall be construed in accordance with and governed by the laws of the 99 | State of Texas. Copyright and other proprietary matters will be 100 | governed by United States laws and international treaties. IN ANY 101 | CASE, ID SHALL NOT BE LIABLE FOR LOSS OF DATA, LOSS OF PROFITS, LOST 102 | SAVINGS, SPECIAL, INCIDENTAL, CONSEQUENTIAL, INDIRECT OR OTHER 103 | SIMILAR DAMAGES ARISING FROM BREACH OF WARRANTY, BREACH OF CONTRACT, 104 | NEGLIGENCE, OR OTHER LEGAL THEORY EVEN IF ID OR ITS AGENT HAS BEEN 105 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY 106 | OTHER PARTY. Some jurisdictions do not allow the exclusion or 107 | limitation of incidental or consequential damages, so the above 108 | limitation or exclusion may not apply to you. 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /sdldoom/Makefile: -------------------------------------------------------------------------------- 1 | CC=riscv32-unknown-elf-gcc 2 | CFLAGS=-fsigned-char -O2 -I. 3 | DEPS = \ 4 | am_map.h \ 5 | d_englsh.h \ 6 | d_event.h \ 7 | d_french.h \ 8 | d_items.h \ 9 | d_main.h \ 10 | d_net.h \ 11 | d_player.h \ 12 | d_textur.h \ 13 | d_think.h \ 14 | d_ticcmd.h \ 15 | doomdata.h \ 16 | doomdef.h \ 17 | doomstat.h \ 18 | doomtype.h \ 19 | dstrings.h \ 20 | f_finale.h \ 21 | f_wipe.h \ 22 | g_game.h \ 23 | hu_lib.h \ 24 | hu_stuff.h \ 25 | i_sound.h \ 26 | i_system.h \ 27 | i_net.h \ 28 | i_video.h \ 29 | info.h \ 30 | m_argv.h \ 31 | m_bbox.h \ 32 | m_cheat.h \ 33 | m_fixed.h \ 34 | m_menu.h \ 35 | m_misc.h \ 36 | m_random.h \ 37 | m_swap.h \ 38 | p_inter.h \ 39 | p_local.h \ 40 | p_mobj.h \ 41 | p_pspr.h \ 42 | p_saveg.h \ 43 | p_setup.h \ 44 | p_spec.h \ 45 | p_tick.h \ 46 | r_bsp.h \ 47 | r_data.h \ 48 | r_defs.h \ 49 | r_draw.h \ 50 | r_local.h \ 51 | r_main.h \ 52 | r_plane.h \ 53 | r_segs.h \ 54 | r_sky.h \ 55 | r_state.h \ 56 | r_things.h \ 57 | s_sound.h \ 58 | sounds.h \ 59 | st_lib.h \ 60 | st_stuff.h \ 61 | tables.h \ 62 | v_video.h \ 63 | w_wad.h \ 64 | wi_stuff.h \ 65 | z_zone.h 66 | 67 | OBJS = \ 68 | rv_av_api.o \ 69 | am_map.o \ 70 | d_items.o \ 71 | d_main.o \ 72 | d_net.o \ 73 | doomdef.o \ 74 | doomstat.o \ 75 | dstrings.o \ 76 | f_finale.o \ 77 | f_wipe.o \ 78 | g_game.o \ 79 | hu_lib.o \ 80 | hu_stuff.o \ 81 | i_main.o \ 82 | i_sound.o \ 83 | i_system.o \ 84 | i_net.o \ 85 | i_video.o \ 86 | info.o \ 87 | m_argv.o \ 88 | m_bbox.o \ 89 | m_cheat.o \ 90 | m_fixed.o \ 91 | m_menu.o \ 92 | m_misc.o \ 93 | m_random.o \ 94 | m_swap.o \ 95 | p_ceilng.o \ 96 | p_doors.o \ 97 | p_enemy.o \ 98 | p_floor.o \ 99 | p_inter.o \ 100 | p_lights.o \ 101 | p_map.o \ 102 | p_maputl.o \ 103 | p_mobj.o \ 104 | p_plats.o \ 105 | p_pspr.o \ 106 | p_saveg.o \ 107 | p_setup.o \ 108 | p_sight.o \ 109 | p_spec.o \ 110 | p_switch.o \ 111 | p_telept.o \ 112 | p_tick.o \ 113 | p_user.o \ 114 | r_bsp.o \ 115 | r_data.o \ 116 | r_draw.o \ 117 | r_main.o \ 118 | r_plane.o \ 119 | r_segs.o \ 120 | r_sky.o \ 121 | r_things.o \ 122 | s_sound.o \ 123 | sounds.o \ 124 | st_lib.o \ 125 | st_stuff.o \ 126 | tables.o \ 127 | v_video.o \ 128 | w_wad.o \ 129 | wi_stuff.o \ 130 | z_zone.o 131 | 132 | %.o: %.c $(DEPS) 133 | $(CC) -c -o $@ $< $(CFLAGS) 134 | 135 | doom: $(OBJS) 136 | $(CC) -o $@ $^ $(CFLAGS) 137 | 138 | .PHONY: clean 139 | 140 | clean: 141 | rm -f *.o doom 142 | -------------------------------------------------------------------------------- /sdldoom/README.SDL: -------------------------------------------------------------------------------- 1 | 2 | Simple DirectMedia Library: 3 | 4 | This is a quick and dirty port of DOOM to the SDL library. 5 | The only thing that is system dependent really is the endianness detection 6 | 7 | It was very simple, and only took an afternoon, thanks to the efforts 8 | of all those folks who have ported this game to everything but the toaster. :) 9 | 10 | Here's the web page for my library: 11 | http://www.devolution.com/~slouken/SDL/ 12 | 13 | Thanks go to all those involved in the DOOM game. ID Software comes to mind. :) 14 | 15 | Note the addition of a "-fullscreen" command line option. 16 | 17 | See ya! 18 | -Sam Lantinga (slouken@devolution.com) 19 | 20 | -------------------------------------------------------------------------------- /sdldoom/README.b: -------------------------------------------------------------------------------- 1 | 2 | README for Linux DOOM Source distribution 3 | ========================================= 4 | 5 | 6 | DISCLAIMER 7 | ---------- 8 | This is not "The DOOM Source Code" dump for a bunch 9 | of reasons. It is based on a DOOM development directory 10 | snapshot as of January 10th, but has been stripped and 11 | changed. Thus it is the DOOM source, but there are many 12 | minor differences to the source as last used by id 13 | Software. 14 | 15 | Note that thus neither John Carmack nor Dave Taylor nor 16 | anybody else at id is responsible for the contents of 17 | this archive, or the changes introduced to the original 18 | source. 19 | 20 | If there are any questions, contact me at bk@gamers.org, 21 | or preferably post to the mailing list at 22 | 23 | doom-editing@gamers.org 24 | 25 | (send mail to majordomo@gamers.org, content just 26 | a single "info doom-editing"). I will post any updates 27 | or notifcation of corrections there. I will probably 28 | put some stuff at 29 | 30 | http://www.gamers.org/dEngine/doom/ 31 | 32 | as well. Look there for the "Unofficial DOOM Specs" as 33 | minimal recommended documentation. 34 | 35 | 36 | 37 | REMARKS 38 | ------- 39 | I made a few minor bug fixes, added some experimental sound 40 | code, and, and changed the handling of IWAD dependend game 41 | modes. Most of the changes though have been shuffling 42 | around sources in a sometimes futile attempt to separate 43 | modules more cleanly, and make certain parts easier 44 | to locate and modify. There is still much left to do, but 45 | I hope that the current source is a good base to start 46 | with, especially with a cooperative effort in mind. Those 47 | so inclined will find the source prepared for CVS. 48 | 49 | There is a list of changes and fixes I did not get around 50 | to in TODO, and an incomplete worklog in ChangeLog, that 51 | also includes some minor ToDo statements scattered throughout 52 | the log. 53 | 54 | 55 | a) Linux SVGA 56 | There is no SVGA support. For development and debug 57 | purposes, the X11 version seems to be more handy. 58 | 59 | b) Sound - see README.sound, 60 | and the sndserver.tgz archive. 61 | 62 | c) GLDOOM - see README.gl 63 | 64 | d) Win32 65 | There was no Win32 support in the original dump. 66 | 67 | e) DOS 68 | Original DOS support (including the texture 69 | mapping and fixed point assembler) has been 70 | removed, mainly because of the lack of sound 71 | support. 72 | 73 | f) DoomEd 74 | The NeXTStep DoomEd sources in the dump were 75 | garbled (filenames - prolly an issue of ISO9660 76 | with or w/o extensions). Somehow Bear never got 77 | around to send me a list of the correct filenames, 78 | and I won't bother guessing without a NeXT box 79 | at hand. 80 | 81 | There is a plethora of useful editors 82 | for DOOM. I suggest using DEU for X11. 83 | 84 | g) BSP Tools 85 | The BSP builder and other tools have 86 | been released by John Carmack long ago, 87 | and since improved/replaced by others. 88 | Again, I recommend taking a pick among 89 | the tools available for Linux. 90 | 91 | h) DOOM game tools 92 | There are a number of tools that have 93 | not been released, namely those which 94 | compiled the Things and State Tables, 95 | the frame animation LUT's, sound tables 96 | etc. Basically, they compile similarly 97 | complex LUT's to generate C files. The 98 | tools are omitted from this distribution. 99 | 100 | There are some files in the 101 | distribution (info.h/c, sounds.h/c) 102 | that are essentially the output of these 103 | tools. This is the data that defines 104 | DOOM (as a game) for all practical 105 | purposes. 106 | 107 | I recommend keeping them, as they are 108 | part of the source. In the long run, 109 | handling them as well as the action/ 110 | animation functions as a separate game.so 111 | library (as with Quake2) seems to be a 112 | good idea. 113 | 114 | i) Artwork 115 | Neither the original artwork nor the 116 | misc. WAD files are included in this 117 | archive. You will at least need the 118 | shareware WAD file to run the executable, 119 | but it shouldn't be to difficult to get 120 | a hold of that. 121 | 122 | Note that the mechanism to detect the 123 | presence of a registered or commercial 124 | version is still in the source, and 125 | homebrew maps are still disabled. This 126 | is easily removed now, but as FinalDOOM, 127 | Ultimate DOOM and DOOM 2 are still in 128 | the shops, it is probably polite not 129 | to distribute a source or binary without 130 | that mechanism. 131 | 132 | This version of Linuxdoom supports Plutonia 133 | and TNT WAD from FinalDOOM as well. No 134 | guarantees, though. 135 | 136 | 137 | Enjoy! 138 | 139 | 140 | b. 97/12/22 141 | -------------------------------------------------------------------------------- /sdldoom/README.book: -------------------------------------------------------------------------------- 1 | 2 | The DOOM Book 3 | 4 | Shortly after the Wolfenstein 3D source release, 5 | I sent a mail to Jay Wilbur suggesting a book 6 | about the DOOM engine. I anticipated a similar 7 | release of the DOOM sources within a year or 8 | two, and the obvious problems with the Wolfenstein 9 | sources (lack of accompanying artwork, a code 10 | base not maintained for quite some time) seemed 11 | to demand a better approach. I talked to some 12 | publishing company reps at the Book Fair in 1995, 13 | and while they were cautiously interested, id was 14 | not. 15 | 16 | In the last weeks of 1996, following a visit at 17 | id Software two months earlier, and after the 18 | departure of Jay Wilbur, John Carmack asked me 19 | whether I was still interested in doing the book. 20 | I was, Bear sent me a code dump, and Todd 21 | Hollenshead set out to address the legal concerns 22 | (of which were many). 23 | 24 | Unfortunately, what might have worked in 1995 25 | turned out to be a doomed attempt in 1997. I won't 26 | go into the details - let's just say that my 27 | leaving university and going back to full time 28 | writing for a living repeatedly forced me to 29 | change priorities on what looked more and more 30 | like a project unlikely to generate any revenue. 31 | 32 | By mid of the year, when the legal issues had 33 | finally been settled, it didn't look like I was 34 | going to find a publisher at all. Following the 35 | Book Fair in 1997 and some more discussions 36 | (with about a dozen publishers, total), I gritted 37 | my teeth and decided to abandon the project. 38 | 39 | Note that the book project as such wasn't supposed 40 | to hold up the source release to the public. 41 | However, given the legal concerns relating to 42 | the third party sound code in DOS DOOM, and the 43 | lack of Win32 support as well as the advantages of 44 | an OpenGL based release, the idea was to put 45 | together a consistent, stable code base prior to 46 | public release - most of which was supposed to be 47 | an offspring of my reformatting and modifying the 48 | code for the book. 49 | 50 | None of this worked out as intended. However, I 51 | hope that, at long last, this distribution 52 | will finally provide a good point to start for 53 | any cooperative effort to extend the already 54 | impressive lifespan of DOOM into the age of 55 | multiplayer servers and hardware-accelerated 56 | clients. 57 | 58 | -------------------------------------------------------------------------------- /sdldoom/TODO: -------------------------------------------------------------------------------- 1 | 2 | - create Web repository for sources, patches, 3 | news, and pointer to doom-editing mailing 4 | list. 5 | 6 | - get DOOM Public License from id 7 | 8 | ----------------------------------------------- 9 | 10 | - remove m_fixed, switch to floating point 11 | More stable, and prolly even faster. 12 | 13 | - make SCREENWIDTH/HEIGHT work at startup? 14 | Well, the HUD/STBar stuff is tied to the 15 | scales implied by the graphics. Rather do 16 | GLDOOM and use texture mapping. 17 | 18 | - fix aspect ratio? 19 | 320x200 is nothing viable nowadays. 20 | A 320x240 base (4:3) would be a lot better. 21 | See above on width/height. 22 | 23 | - limited look up/down by y-shearing? 24 | Prolly not worth it, rather switch to GLDOOM. 25 | 26 | - switch to C++? 27 | The action function pointers have varying 28 | argument lists (no parameter, one, etc.). 29 | C++ doesn't like that much. A major rewrite. 30 | 31 | - switch to doommain.c plus libdoom? Have 32 | libref, libgame etc.? 33 | Another major rewrite. 34 | 35 | - use XFree86 DGA, prolly not that much faster 36 | than MIT SHM, but allows for directly sampled 37 | mouse (and even freelook). Recommended for 38 | GLDOOM. 39 | 40 | - put together an accompanying developer toolkit 41 | source distribution: DEU, RMB, BSP for Linux/X. 42 | 43 | - move info.h, info.c, sounds.h, sounds.c and 44 | other data to a separate lump in the WAD, 45 | or into a libgame.so, to separate the 46 | generic stuff (refresh, I/O) from the 47 | DOOM specifics. 48 | 49 | - decide whether precaching all sounds is 50 | better than retrieving and releasing 51 | every so often. DOOM seems to do that 52 | frequently (8bit stuff, originally for 53 | DOS), and the Linux sound is 16bit 54 | (conversion in the mixing, requires 55 | some padding) - we prolly got the memory 56 | to spare. 57 | 58 | - 16bpp CLUT. The lightmaps and the 59 | framebuffer could be changed to switch 60 | to 64K colors. Prolly better to do 61 | GLDOOM right away. 62 | 63 | - remove checks for commercial etc., in 64 | non-essential issues (enabling PWAD's). 65 | 66 | - change (simplify) determination of 67 | sky texture (done by game version). 68 | Explicit? 69 | 70 | - remove all game version checks 71 | 72 | - different handling of Demo - don't 73 | exit on "different game version" 74 | 75 | - how about shareware/retail "You are here" 76 | intermission animation? Wasn't in 77 | commercial (DOOM 2). 78 | 79 | - double shotgun in DOOM1, all weapons with 80 | shareware 81 | 82 | - checks for required lumps. We need fallbacks 83 | for lumps that are not present, that is, 84 | default sounds etc. to be used instead, 85 | or removing THINGS w/o sprites etc. 86 | 87 | - client/server? I'd suggest ripping off some stuff 88 | from the abandoned IBM WebView project 89 | 90 | - Blockmap 91 | The BLOCKMAP lump might be (partly) redundant, 92 | as the BSP allows for clipping (except certain 93 | LineDefs that will not spawn Segs). 94 | 95 | - LOS 96 | REJECT and intersection based LOS checking could be 97 | done using the BSP. In case of REJECT, certain 98 | monster AI special effects would be lost, though. 99 | 100 | - correct handling of height in collision. This is 101 | not done, and the checks are scattered around in 102 | many places. It does require handling of "player 103 | on top of monster" situations, too - we have to 104 | make sure the players falls off far enough to 105 | avoid getting "stuck in monster". 106 | 107 | - remove obsolete menus (Detail. Music Volume?) 108 | 109 | - clip explosion range damage (and sprites) using 110 | REJECT? That is, if one Sector/SSector not 111 | visible from the other, do not apply damage, 112 | not render sprite if player in other sector. 113 | Hmmm - explosion behind small pillar might not be 114 | visible at all, but do we care? 115 | 116 | 117 | - Ungraceful and untimely demise of Linuxdoom (core 118 | instead of I_Error) will leave idle sndserver 119 | processes in your system, blocking /dev/bsp. 120 | A timeout on lack of input for "sndserver"? 121 | 122 | - threaded sndserver? SHM mixing buffer? 123 | Or internal, timer-based? 124 | -------------------------------------------------------------------------------- /sdldoom/am_map.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // AutoMap module. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | #ifndef __AMMAP_H__ 23 | #define __AMMAP_H__ 24 | 25 | // Used by ST StatusBar stuff. 26 | #define AM_MSGHEADER (('a'<<24)+('m'<<16)) 27 | #define AM_MSGENTERED (AM_MSGHEADER | ('e'<<8)) 28 | #define AM_MSGEXITED (AM_MSGHEADER | ('x'<<8)) 29 | 30 | 31 | // Called by main loop. 32 | boolean AM_Responder (event_t* ev); 33 | 34 | // Called by main loop. 35 | void AM_Ticker (void); 36 | 37 | // Called by main loop, 38 | // called instead of view drawer if automap active. 39 | void AM_Drawer (void); 40 | 41 | // Called to force the automap to quit 42 | // if the level is completed while it is up. 43 | void AM_Stop (void); 44 | 45 | 46 | 47 | #endif 48 | //----------------------------------------------------------------------------- 49 | // 50 | // $Log:$ 51 | // 52 | //----------------------------------------------------------------------------- 53 | -------------------------------------------------------------------------------- /sdldoom/d_event.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __D_EVENT__ 24 | #define __D_EVENT__ 25 | 26 | 27 | #include "doomtype.h" 28 | 29 | 30 | // 31 | // Event handling. 32 | // 33 | 34 | // Input event types. 35 | typedef enum 36 | { 37 | ev_keydown, 38 | ev_keyup, 39 | ev_mouse, 40 | ev_joystick 41 | } evtype_t; 42 | 43 | // Event structure. 44 | typedef struct 45 | { 46 | evtype_t type; 47 | int data1; // keys / mouse/joystick buttons 48 | int data2; // mouse/joystick x move 49 | int data3; // mouse/joystick y move 50 | } event_t; 51 | 52 | 53 | typedef enum 54 | { 55 | ga_nothing, 56 | ga_loadlevel, 57 | ga_newgame, 58 | ga_loadgame, 59 | ga_savegame, 60 | ga_playdemo, 61 | ga_completed, 62 | ga_victory, 63 | ga_worlddone, 64 | ga_screenshot 65 | } gameaction_t; 66 | 67 | 68 | 69 | // 70 | // Button/action code definitions. 71 | // 72 | typedef enum 73 | { 74 | // Press "Fire". 75 | BT_ATTACK = 1, 76 | // Use button, to open doors, activate switches. 77 | BT_USE = 2, 78 | 79 | // Flag: game events, not really buttons. 80 | BT_SPECIAL = 128, 81 | BT_SPECIALMASK = 3, 82 | 83 | // Flag, weapon change pending. 84 | // If true, the next 3 bits hold weapon num. 85 | BT_CHANGE = 4, 86 | // The 3bit weapon mask and shift, convenience. 87 | BT_WEAPONMASK = (8+16+32), 88 | BT_WEAPONSHIFT = 3, 89 | 90 | // Pause the game. 91 | BTS_PAUSE = 1, 92 | // Save the game at each console. 93 | BTS_SAVEGAME = 2, 94 | 95 | // Savegame slot numbers 96 | // occupy the second byte of buttons. 97 | BTS_SAVEMASK = (4+8+16), 98 | BTS_SAVESHIFT = 2, 99 | 100 | } buttoncode_t; 101 | 102 | 103 | 104 | 105 | // 106 | // GLOBAL VARIABLES 107 | // 108 | #define MAXEVENTS 64 109 | 110 | extern event_t events[MAXEVENTS]; 111 | extern int eventhead; 112 | extern int eventtail; 113 | 114 | extern gameaction_t gameaction; 115 | 116 | 117 | #endif 118 | //----------------------------------------------------------------------------- 119 | // 120 | // $Log:$ 121 | // 122 | //----------------------------------------------------------------------------- 123 | -------------------------------------------------------------------------------- /sdldoom/d_items.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // 21 | //----------------------------------------------------------------------------- 22 | 23 | static const char 24 | rcsid[] = "$Id:$"; 25 | 26 | // We are referring to sprite numbers. 27 | #include "info.h" 28 | 29 | #ifdef __GNUG__ 30 | #pragma implementation "d_items.h" 31 | #endif 32 | #include "d_items.h" 33 | 34 | 35 | // 36 | // PSPRITE ACTIONS for waepons. 37 | // This struct controls the weapon animations. 38 | // 39 | // Each entry is: 40 | // ammo/amunition type 41 | // upstate 42 | // downstate 43 | // readystate 44 | // atkstate, i.e. attack/fire/hit frame 45 | // flashstate, muzzle flash 46 | // 47 | weaponinfo_t weaponinfo[NUMWEAPONS] = 48 | { 49 | { 50 | // fist 51 | am_noammo, 52 | S_PUNCHUP, 53 | S_PUNCHDOWN, 54 | S_PUNCH, 55 | S_PUNCH1, 56 | S_NULL 57 | }, 58 | { 59 | // pistol 60 | am_clip, 61 | S_PISTOLUP, 62 | S_PISTOLDOWN, 63 | S_PISTOL, 64 | S_PISTOL1, 65 | S_PISTOLFLASH 66 | }, 67 | { 68 | // shotgun 69 | am_shell, 70 | S_SGUNUP, 71 | S_SGUNDOWN, 72 | S_SGUN, 73 | S_SGUN1, 74 | S_SGUNFLASH1 75 | }, 76 | { 77 | // chaingun 78 | am_clip, 79 | S_CHAINUP, 80 | S_CHAINDOWN, 81 | S_CHAIN, 82 | S_CHAIN1, 83 | S_CHAINFLASH1 84 | }, 85 | { 86 | // missile launcher 87 | am_misl, 88 | S_MISSILEUP, 89 | S_MISSILEDOWN, 90 | S_MISSILE, 91 | S_MISSILE1, 92 | S_MISSILEFLASH1 93 | }, 94 | { 95 | // plasma rifle 96 | am_cell, 97 | S_PLASMAUP, 98 | S_PLASMADOWN, 99 | S_PLASMA, 100 | S_PLASMA1, 101 | S_PLASMAFLASH1 102 | }, 103 | { 104 | // bfg 9000 105 | am_cell, 106 | S_BFGUP, 107 | S_BFGDOWN, 108 | S_BFG, 109 | S_BFG1, 110 | S_BFGFLASH1 111 | }, 112 | { 113 | // chainsaw 114 | am_noammo, 115 | S_SAWUP, 116 | S_SAWDOWN, 117 | S_SAW, 118 | S_SAW1, 119 | S_NULL 120 | }, 121 | { 122 | // super shotgun 123 | am_shell, 124 | S_DSGUNUP, 125 | S_DSGUNDOWN, 126 | S_DSGUN, 127 | S_DSGUN1, 128 | S_DSGUNFLASH1 129 | }, 130 | }; 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /sdldoom/d_items.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Items: key cards, artifacts, weapon, ammunition. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __D_ITEMS__ 24 | #define __D_ITEMS__ 25 | 26 | #include "doomdef.h" 27 | 28 | #ifdef __GNUG__ 29 | #pragma interface 30 | #endif 31 | 32 | 33 | // Weapon info: sprite frames, ammunition use. 34 | typedef struct 35 | { 36 | ammotype_t ammo; 37 | int upstate; 38 | int downstate; 39 | int readystate; 40 | int atkstate; 41 | int flashstate; 42 | 43 | } weaponinfo_t; 44 | 45 | extern weaponinfo_t weaponinfo[NUMWEAPONS]; 46 | 47 | #endif 48 | //----------------------------------------------------------------------------- 49 | // 50 | // $Log:$ 51 | // 52 | //----------------------------------------------------------------------------- 53 | -------------------------------------------------------------------------------- /sdldoom/d_main.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // System specific interface stuff. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | 25 | #ifndef __D_MAIN__ 26 | #define __D_MAIN__ 27 | 28 | #include "d_event.h" 29 | 30 | #ifdef __GNUG__ 31 | #pragma interface 32 | #endif 33 | 34 | 35 | 36 | #define MAXWADFILES 20 37 | extern char* wadfiles[MAXWADFILES]; 38 | 39 | void D_AddFile (char *file); 40 | 41 | 42 | 43 | // 44 | // D_DoomMain() 45 | // Not a globally visible function, just included for source reference, 46 | // calls all startup code, parses command line options. 47 | // If not overrided by user input, calls N_AdvanceDemo. 48 | // 49 | void D_DoomMain (void); 50 | 51 | // Called by IO functions when input is detected. 52 | void D_PostEvent (event_t* ev); 53 | 54 | 55 | 56 | // 57 | // BASE LEVEL 58 | // 59 | void D_PageTicker (void); 60 | void D_PageDrawer (void); 61 | void D_AdvanceDemo (void); 62 | void D_StartTitle (void); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /sdldoom/d_net.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Networking stuff. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __D_NET__ 24 | #define __D_NET__ 25 | 26 | #include "d_player.h" 27 | 28 | 29 | #ifdef __GNUG__ 30 | #pragma interface 31 | #endif 32 | 33 | 34 | // 35 | // Network play related stuff. 36 | // There is a data struct that stores network 37 | // communication related stuff, and another 38 | // one that defines the actual packets to 39 | // be transmitted. 40 | // 41 | 42 | #define DOOMCOM_ID 0x12345678l 43 | 44 | // Max computers/players in a game. 45 | #define MAXNETNODES 8 46 | 47 | 48 | // Networking and tick handling related. 49 | #define BACKUPTICS 12 50 | 51 | typedef enum 52 | { 53 | CMD_SEND = 1, 54 | CMD_GET = 2 55 | 56 | } command_t; 57 | 58 | 59 | // 60 | // Network packet data. 61 | // 62 | typedef struct 63 | { 64 | // High bit is retransmit request. 65 | unsigned checksum; 66 | // Only valid if NCMD_RETRANSMIT. 67 | byte retransmitfrom; 68 | 69 | byte starttic; 70 | byte player; 71 | byte numtics; 72 | ticcmd_t cmds[BACKUPTICS]; 73 | 74 | } doomdata_t; 75 | 76 | 77 | 78 | 79 | typedef struct 80 | { 81 | // Supposed to be DOOMCOM_ID? 82 | long id; 83 | 84 | // DOOM executes an int to execute commands. 85 | short intnum; 86 | // Communication between DOOM and the driver. 87 | // Is CMD_SEND or CMD_GET. 88 | short command; 89 | // Is dest for send, set by get (-1 = no packet). 90 | short remotenode; 91 | 92 | // Number of bytes in doomdata to be sent 93 | short datalength; 94 | 95 | // Info common to all nodes. 96 | // Console is allways node 0. 97 | short numnodes; 98 | // Flag: 1 = no duplication, 2-5 = dup for slow nets. 99 | short ticdup; 100 | // Flag: 1 = send a backup tic in every packet. 101 | short extratics; 102 | // Flag: 1 = deathmatch. 103 | short deathmatch; 104 | // Flag: -1 = new game, 0-5 = load savegame 105 | short savegame; 106 | short episode; // 1-3 107 | short map; // 1-9 108 | short skill; // 1-5 109 | 110 | // Info specific to this node. 111 | short consoleplayer; 112 | short numplayers; 113 | 114 | // These are related to the 3-display mode, 115 | // in which two drones looking left and right 116 | // were used to render two additional views 117 | // on two additional computers. 118 | // Probably not operational anymore. 119 | // 1 = left, 0 = center, -1 = right 120 | short angleoffset; 121 | // 1 = drone 122 | short drone; 123 | 124 | // The packet data to be sent. 125 | doomdata_t data; 126 | 127 | } doomcom_t; 128 | 129 | 130 | 131 | // Create any new ticcmds and broadcast to other players. 132 | void NetUpdate (void); 133 | 134 | // Broadcasts special packets to other players 135 | // to notify of game exit 136 | void D_QuitNetGame (void); 137 | 138 | //? how many ticks to run? 139 | void TryRunTics (void); 140 | 141 | 142 | #endif 143 | 144 | //----------------------------------------------------------------------------- 145 | // 146 | // $Log:$ 147 | // 148 | //----------------------------------------------------------------------------- 149 | 150 | -------------------------------------------------------------------------------- /sdldoom/d_player.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __D_PLAYER__ 24 | #define __D_PLAYER__ 25 | 26 | 27 | // The player data structure depends on a number 28 | // of other structs: items (internal inventory), 29 | // animation states (closely tied to the sprites 30 | // used to represent them, unfortunately). 31 | #include "d_items.h" 32 | #include "p_pspr.h" 33 | 34 | // In addition, the player is just a special 35 | // case of the generic moving object/actor. 36 | #include "p_mobj.h" 37 | 38 | // Finally, for odd reasons, the player input 39 | // is buffered within the player data struct, 40 | // as commands per game tick. 41 | #include "d_ticcmd.h" 42 | 43 | #ifdef __GNUG__ 44 | #pragma interface 45 | #endif 46 | 47 | 48 | 49 | 50 | // 51 | // Player states. 52 | // 53 | typedef enum 54 | { 55 | // Playing or camping. 56 | PST_LIVE, 57 | // Dead on the ground, view follows killer. 58 | PST_DEAD, 59 | // Ready to restart/respawn??? 60 | PST_REBORN 61 | 62 | } playerstate_t; 63 | 64 | 65 | // 66 | // Player internal flags, for cheats and debug. 67 | // 68 | typedef enum 69 | { 70 | // No clipping, walk through barriers. 71 | CF_NOCLIP = 1, 72 | // No damage, no health loss. 73 | CF_GODMODE = 2, 74 | // Not really a cheat, just a debug aid. 75 | CF_NOMOMENTUM = 4 76 | 77 | } cheat_t; 78 | 79 | 80 | // 81 | // Extended player object info: player_t 82 | // 83 | typedef struct player_s 84 | { 85 | mobj_t* mo; 86 | playerstate_t playerstate; 87 | ticcmd_t cmd; 88 | 89 | // Determine POV, 90 | // including viewpoint bobbing during movement. 91 | // Focal origin above r.z 92 | fixed_t viewz; 93 | // Base height above floor for viewz. 94 | fixed_t viewheight; 95 | // Bob/squat speed. 96 | fixed_t deltaviewheight; 97 | // bounded/scaled total momentum. 98 | fixed_t bob; 99 | 100 | // This is only used between levels, 101 | // mo->health is used during levels. 102 | int health; 103 | int armorpoints; 104 | // Armor type is 0-2. 105 | int armortype; 106 | 107 | // Power ups. invinc and invis are tic counters. 108 | int powers[NUMPOWERS]; 109 | boolean cards[NUMCARDS]; 110 | boolean backpack; 111 | 112 | // Frags, kills of other players. 113 | int frags[MAXPLAYERS]; 114 | weapontype_t readyweapon; 115 | 116 | // Is wp_nochange if not changing. 117 | weapontype_t pendingweapon; 118 | 119 | boolean weaponowned[NUMWEAPONS]; 120 | int ammo[NUMAMMO]; 121 | int maxammo[NUMAMMO]; 122 | 123 | // True if button down last tic. 124 | int attackdown; 125 | int usedown; 126 | 127 | // Bit flags, for cheats and debug. 128 | // See cheat_t, above. 129 | int cheats; 130 | 131 | // Refired shots are less accurate. 132 | int refire; 133 | 134 | // For intermission stats. 135 | int killcount; 136 | int itemcount; 137 | int secretcount; 138 | 139 | // Hint messages. 140 | char* message; 141 | 142 | // For screen flashing (red or bright). 143 | int damagecount; 144 | int bonuscount; 145 | 146 | // Who did damage (NULL for floors/ceilings). 147 | mobj_t* attacker; 148 | 149 | // So gun flashes light up areas. 150 | int extralight; 151 | 152 | // Current PLAYPAL, ??? 153 | // can be set to REDCOLORMAP for pain, etc. 154 | int fixedcolormap; 155 | 156 | // Player skin colorshift, 157 | // 0-3 for which color to draw player. 158 | int colormap; 159 | 160 | // Overlay view sprites (gun, etc). 161 | pspdef_t psprites[NUMPSPRITES]; 162 | 163 | // True if secret level has been done. 164 | boolean didsecret; 165 | 166 | } player_t; 167 | 168 | 169 | // 170 | // INTERMISSION 171 | // Structure passed e.g. to WI_Start(wb) 172 | // 173 | typedef struct 174 | { 175 | boolean in; // whether the player is in game 176 | 177 | // Player stats, kills, collected items etc. 178 | int skills; 179 | int sitems; 180 | int ssecret; 181 | int stime; 182 | int frags[4]; 183 | int score; // current score on entry, modified on return 184 | 185 | } wbplayerstruct_t; 186 | 187 | typedef struct 188 | { 189 | int epsd; // episode # (0-2) 190 | 191 | // if true, splash the secret level 192 | boolean didsecret; 193 | 194 | // previous and next levels, origin 0 195 | int last; 196 | int next; 197 | 198 | int maxkills; 199 | int maxitems; 200 | int maxsecret; 201 | int maxfrags; 202 | 203 | // the par time 204 | int partime; 205 | 206 | // index of this player in game 207 | int pnum; 208 | 209 | wbplayerstruct_t plyr[MAXPLAYERS]; 210 | 211 | } wbstartstruct_t; 212 | 213 | 214 | #endif 215 | //----------------------------------------------------------------------------- 216 | // 217 | // $Log:$ 218 | // 219 | //----------------------------------------------------------------------------- 220 | -------------------------------------------------------------------------------- /sdldoom/d_textur.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Typedefs related to to textures etc., 19 | // isolated here to make it easier separating modules. 20 | // 21 | //----------------------------------------------------------------------------- 22 | 23 | 24 | #ifndef __D_TEXTUR__ 25 | #define __D_TEXTUR__ 26 | 27 | #include "doomtype.h" 28 | 29 | 30 | 31 | 32 | // 33 | // Flats? 34 | // 35 | // a pic is an unmasked block of pixels 36 | typedef struct 37 | { 38 | byte width; 39 | byte height; 40 | byte data; 41 | } pic_t; 42 | 43 | 44 | 45 | 46 | #endif 47 | //----------------------------------------------------------------------------- 48 | // 49 | // $Log:$ 50 | // 51 | //----------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /sdldoom/d_think.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // MapObj data. Map Objects or mobjs are actors, entities, 19 | // thinker, take-your-pick... anything that moves, acts, or 20 | // suffers state changes of more or less violent nature. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | 25 | #ifndef __D_THINK__ 26 | #define __D_THINK__ 27 | 28 | 29 | #ifdef __GNUG__ 30 | #pragma interface 31 | #endif 32 | 33 | 34 | 35 | // 36 | // Experimental stuff. 37 | // To compile this as "ANSI C with classes" 38 | // we will need to handle the various 39 | // action functions cleanly. 40 | // 41 | typedef void (*actionf_v)(); 42 | typedef void (*actionf_p1)( void* ); 43 | typedef void (*actionf_p2)( void*, void* ); 44 | 45 | typedef union 46 | { 47 | actionf_p1 acp1; 48 | actionf_v acv; 49 | actionf_p2 acp2; 50 | 51 | } actionf_t; 52 | 53 | 54 | 55 | 56 | 57 | // Historically, "think_t" is yet another 58 | // function pointer to a routine to handle 59 | // an actor. 60 | typedef actionf_t think_t; 61 | 62 | 63 | // Doubly linked list of actors. 64 | typedef struct thinker_s 65 | { 66 | struct thinker_s* prev; 67 | struct thinker_s* next; 68 | think_t function; 69 | 70 | } thinker_t; 71 | 72 | 73 | 74 | #endif 75 | //----------------------------------------------------------------------------- 76 | // 77 | // $Log:$ 78 | // 79 | //----------------------------------------------------------------------------- 80 | -------------------------------------------------------------------------------- /sdldoom/d_ticcmd.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // System specific interface stuff. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __D_TICCMD__ 24 | #define __D_TICCMD__ 25 | 26 | #include "doomtype.h" 27 | 28 | #ifdef __GNUG__ 29 | #pragma interface 30 | #endif 31 | 32 | // The data sampled per tick (single player) 33 | // and transmitted to other peers (multiplayer). 34 | // Mainly movements/button commands per game tick, 35 | // plus a checksum for internal state consistency. 36 | typedef struct 37 | { 38 | char forwardmove; // *2048 for move 39 | char sidemove; // *2048 for move 40 | short angleturn; // <<16 for angle delta 41 | short consistancy; // checks for net game 42 | byte chatchar; 43 | byte buttons; 44 | } ticcmd_t; 45 | 46 | 47 | 48 | #endif 49 | //----------------------------------------------------------------------------- 50 | // 51 | // $Log:$ 52 | // 53 | //----------------------------------------------------------------------------- 54 | -------------------------------------------------------------------------------- /sdldoom/doom1.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcq2/risc-666/bf4f31c59f94760006139975e344c7db3508103c/sdldoom/doom1.wad -------------------------------------------------------------------------------- /sdldoom/doomdata.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // all external data is defined here 19 | // most of the data is loaded into different structures at run time 20 | // some internal structures shared by many modules are here 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | #ifndef __DOOMDATA__ 25 | #define __DOOMDATA__ 26 | 27 | // The most basic types we use, portability. 28 | #include "doomtype.h" 29 | 30 | // Some global defines, that configure the game. 31 | #include "doomdef.h" 32 | 33 | 34 | 35 | // 36 | // Map level types. 37 | // The following data structures define the persistent format 38 | // used in the lumps of the WAD files. 39 | // 40 | 41 | // Lump order in a map WAD: each map needs a couple of lumps 42 | // to provide a complete scene geometry description. 43 | enum 44 | { 45 | ML_LABEL, // A separator, name, ExMx or MAPxx 46 | ML_THINGS, // Monsters, items.. 47 | ML_LINEDEFS, // LineDefs, from editing 48 | ML_SIDEDEFS, // SideDefs, from editing 49 | ML_VERTEXES, // Vertices, edited and BSP splits generated 50 | ML_SEGS, // LineSegs, from LineDefs split by BSP 51 | ML_SSECTORS, // SubSectors, list of LineSegs 52 | ML_NODES, // BSP nodes 53 | ML_SECTORS, // Sectors, from editing 54 | ML_REJECT, // LUT, sector-sector visibility 55 | ML_BLOCKMAP // LUT, motion clipping, walls/grid element 56 | }; 57 | 58 | 59 | // A single Vertex. 60 | typedef struct 61 | { 62 | short x; 63 | short y; 64 | } mapvertex_t; 65 | 66 | 67 | // A SideDef, defining the visual appearance of a wall, 68 | // by setting textures and offsets. 69 | typedef struct 70 | { 71 | short textureoffset; 72 | short rowoffset; 73 | char toptexture[8]; 74 | char bottomtexture[8]; 75 | char midtexture[8]; 76 | // Front sector, towards viewer. 77 | short sector; 78 | } mapsidedef_t; 79 | 80 | 81 | 82 | // A LineDef, as used for editing, and as input 83 | // to the BSP builder. 84 | typedef struct 85 | { 86 | short v1; 87 | short v2; 88 | short flags; 89 | short special; 90 | short tag; 91 | // sidenum[1] will be -1 if one sided 92 | short sidenum[2]; 93 | } maplinedef_t; 94 | 95 | 96 | // 97 | // LineDef attributes. 98 | // 99 | 100 | // Solid, is an obstacle. 101 | #define ML_BLOCKING 1 102 | 103 | // Blocks monsters only. 104 | #define ML_BLOCKMONSTERS 2 105 | 106 | // Backside will not be present at all 107 | // if not two sided. 108 | #define ML_TWOSIDED 4 109 | 110 | // If a texture is pegged, the texture will have 111 | // the end exposed to air held constant at the 112 | // top or bottom of the texture (stairs or pulled 113 | // down things) and will move with a height change 114 | // of one of the neighbor sectors. 115 | // Unpegged textures allways have the first row of 116 | // the texture at the top pixel of the line for both 117 | // top and bottom textures (use next to windows). 118 | 119 | // upper texture unpegged 120 | #define ML_DONTPEGTOP 8 121 | 122 | // lower texture unpegged 123 | #define ML_DONTPEGBOTTOM 16 124 | 125 | // In AutoMap: don't map as two sided: IT'S A SECRET! 126 | #define ML_SECRET 32 127 | 128 | // Sound rendering: don't let sound cross two of these. 129 | #define ML_SOUNDBLOCK 64 130 | 131 | // Don't draw on the automap at all. 132 | #define ML_DONTDRAW 128 133 | 134 | // Set if already seen, thus drawn in automap. 135 | #define ML_MAPPED 256 136 | 137 | 138 | 139 | 140 | // Sector definition, from editing. 141 | typedef struct 142 | { 143 | short floorheight; 144 | short ceilingheight; 145 | char floorpic[8]; 146 | char ceilingpic[8]; 147 | short lightlevel; 148 | short special; 149 | short tag; 150 | } mapsector_t; 151 | 152 | // SubSector, as generated by BSP. 153 | typedef struct 154 | { 155 | short numsegs; 156 | // Index of first one, segs are stored sequentially. 157 | short firstseg; 158 | } mapsubsector_t; 159 | 160 | 161 | // LineSeg, generated by splitting LineDefs 162 | // using partition lines selected by BSP builder. 163 | typedef struct 164 | { 165 | short v1; 166 | short v2; 167 | short angle; 168 | short linedef; 169 | short side; 170 | short offset; 171 | } mapseg_t; 172 | 173 | 174 | 175 | // BSP node structure. 176 | 177 | // Indicate a leaf. 178 | #define NF_SUBSECTOR 0x8000 179 | 180 | typedef struct 181 | { 182 | // Partition line from (x,y) to x+dx,y+dy) 183 | short x; 184 | short y; 185 | short dx; 186 | short dy; 187 | 188 | // Bounding box for each child, 189 | // clip against view frustum. 190 | short bbox[2][4]; 191 | 192 | // If NF_SUBSECTOR its a subsector, 193 | // else it's a node of another subtree. 194 | unsigned short children[2]; 195 | 196 | } mapnode_t; 197 | 198 | 199 | 200 | 201 | // Thing definition, position, orientation and type, 202 | // plus skill/visibility flags and attributes. 203 | typedef struct 204 | { 205 | short x; 206 | short y; 207 | short angle; 208 | short type; 209 | short options; 210 | } mapthing_t; 211 | 212 | 213 | 214 | 215 | 216 | #endif // __DOOMDATA__ 217 | //----------------------------------------------------------------------------- 218 | // 219 | // $Log:$ 220 | // 221 | //----------------------------------------------------------------------------- 222 | 223 | -------------------------------------------------------------------------------- /sdldoom/doomdef.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // DoomDef - basic defines for DOOM, e.g. Version, game mode 21 | // and skill level, and display parameters. 22 | // 23 | //----------------------------------------------------------------------------- 24 | 25 | static const char 26 | rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; 27 | 28 | 29 | #ifdef __GNUG__ 30 | #pragma implementation "doomdef.h" 31 | #endif 32 | #include "doomdef.h" 33 | 34 | // Location for any defines turned variables. 35 | 36 | // None. 37 | 38 | 39 | -------------------------------------------------------------------------------- /sdldoom/doomstat.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Put all global tate variables here. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | static const char 25 | rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; 26 | 27 | 28 | #ifdef __GNUG__ 29 | #pragma implementation "doomstat.h" 30 | #endif 31 | #include "doomstat.h" 32 | 33 | 34 | // Game Mode - identify IWAD as shareware, retail etc. 35 | GameMode_t gamemode = indetermined; 36 | GameMission_t gamemission = doom; 37 | 38 | // Language. 39 | Language_t language = english; 40 | 41 | // Set if homebrew PWAD stuff has been added. 42 | boolean modifiedgame; 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sdldoom/doomtype.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Simple basic typedefs, isolated here to make it easier 19 | // separating modules. 20 | // 21 | //----------------------------------------------------------------------------- 22 | 23 | 24 | #ifndef __DOOMTYPE__ 25 | #define __DOOMTYPE__ 26 | 27 | 28 | #ifndef __BYTEBOOL__ 29 | #define __BYTEBOOL__ 30 | // Fixed to use builtin bool type with C++. 31 | #ifdef __cplusplus 32 | typedef bool boolean; 33 | #else 34 | #ifdef __BEOS__ /* boolean is a builtin type for MWCC */ 35 | #define boolean D_BOOL 36 | #undef false 37 | #define false D_false 38 | #undef true 39 | #define true D_true 40 | #endif 41 | typedef enum {false, true} boolean; 42 | #endif 43 | typedef unsigned char byte; 44 | #endif 45 | 46 | 47 | // Predefined with some OS. 48 | #ifdef LINUX 49 | #include 50 | #else 51 | #ifndef MAXCHAR 52 | #define MAXCHAR ((char)0x7f) 53 | #endif 54 | #ifndef MAXSHORT 55 | #define MAXSHORT ((short)0x7fff) 56 | #endif 57 | 58 | // Max pos 32-bit int. 59 | #ifndef MAXINT 60 | #define MAXINT ((int)0x7fffffff) 61 | #endif 62 | #ifndef MAXLONG 63 | #define MAXLONG ((long)0x7fffffff) 64 | #endif 65 | #ifndef MINCHAR 66 | #define MINCHAR ((char)0x80) 67 | #endif 68 | #ifndef MINSHORT 69 | #define MINSHORT ((short)0x8000) 70 | #endif 71 | 72 | // Max negative 32-bit integer. 73 | #ifndef MININT 74 | #define MININT ((int)0x80000000) 75 | #endif 76 | #ifndef MINLONG 77 | #define MINLONG ((long)0x80000000) 78 | #endif 79 | #endif 80 | 81 | 82 | 83 | 84 | #endif 85 | //----------------------------------------------------------------------------- 86 | // 87 | // $Log:$ 88 | // 89 | //----------------------------------------------------------------------------- 90 | -------------------------------------------------------------------------------- /sdldoom/dstrings.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Globally defined strings. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | static const char 25 | rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; 26 | 27 | 28 | #ifdef __GNUG__ 29 | #pragma implementation "dstrings.h" 30 | #endif 31 | #include "dstrings.h" 32 | 33 | 34 | 35 | char* endmsg[NUM_QUITMESSAGES+1]= 36 | { 37 | // DOOM1 38 | QUITMSG, 39 | "please don't leave, there's more\ndemons to toast!", 40 | "let's beat it -- this is turning\ninto a bloodbath!", 41 | "i wouldn't leave if i were you.\ndos is much worse.", 42 | "you're trying to say you like dos\nbetter than me, right?", 43 | "don't leave yet -- there's a\ndemon around that corner!", 44 | "ya know, next time you come in here\ni'm gonna toast ya.", 45 | "go ahead and leave. see if i care." 46 | 47 | // QuitDOOM II messages 48 | "you want to quit?\nthen, thou hast lost an eighth!", 49 | "don't go now, there's a \ndimensional shambler waiting\nat the dos prompt!", 50 | "get outta here and go back\nto your boring programs.", 51 | "if i were your boss, i'd \n deathmatch ya in a minute!", 52 | "look, bud. you leave now\nand you forfeit your body count!", 53 | "just leave. when you come\nback, i'll be waiting with a bat.", 54 | "you're lucky i don't smack\nyou for thinking about leaving." 55 | 56 | // FinalDOOM? 57 | "fuck you, pussy!\nget the fuck out!", 58 | "you quit and i'll jizz\nin your cystholes!", 59 | "if you leave, i'll make\nthe lord drink my jizz.", 60 | "hey, ron! can we say\n'fuck' in the game?", 61 | "i'd leave: this is just\nmore monsters and levels.\nwhat a load.", 62 | "suck it down, asshole!\nyou're a fucking wimp!", 63 | "don't quit now! we're \nstill spending your money!", 64 | 65 | // Internal debug. Different style, too. 66 | "THIS IS NO MESSAGE!\nPage intentionally left blank." 67 | }; 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /sdldoom/dstrings.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // 18 | // $Log:$ 19 | // 20 | // DESCRIPTION: 21 | // DOOM strings, by language. 22 | // 23 | //----------------------------------------------------------------------------- 24 | 25 | 26 | #ifndef __DSTRINGS__ 27 | #define __DSTRINGS__ 28 | 29 | 30 | // All important printed strings. 31 | // Language selection (message strings). 32 | // Use -DFRENCH etc. 33 | 34 | #ifdef FRENCH 35 | #include "d_french.h" 36 | #else 37 | #include "d_englsh.h" 38 | #endif 39 | 40 | // Misc. other strings. 41 | #define SAVEGAMENAME "doomsav" 42 | 43 | 44 | // 45 | // File locations, 46 | // relative to current position. 47 | // Path names are OS-sensitive. 48 | // 49 | #define DEVMAPS "devmaps" 50 | #define DEVDATA "devdata" 51 | 52 | 53 | // Not done in french? 54 | 55 | // QuitDOOM messages 56 | #define NUM_QUITMESSAGES 22 57 | 58 | extern char* endmsg[]; 59 | 60 | 61 | #endif 62 | //----------------------------------------------------------------------------- 63 | // 64 | // $Log:$ 65 | // 66 | //----------------------------------------------------------------------------- 67 | -------------------------------------------------------------------------------- /sdldoom/f_finale.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __F_FINALE__ 24 | #define __F_FINALE__ 25 | 26 | 27 | #include "doomtype.h" 28 | #include "d_event.h" 29 | // 30 | // FINALE 31 | // 32 | 33 | // Called by main loop. 34 | boolean F_Responder (event_t* ev); 35 | 36 | // Called by main loop. 37 | void F_Ticker (void); 38 | 39 | // Called by main loop. 40 | void F_Drawer (void); 41 | 42 | 43 | void F_StartFinale (void); 44 | 45 | 46 | 47 | 48 | #endif 49 | //----------------------------------------------------------------------------- 50 | // 51 | // $Log:$ 52 | // 53 | //----------------------------------------------------------------------------- 54 | -------------------------------------------------------------------------------- /sdldoom/f_wipe.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Mission start screen wipe/melt, special effects. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __F_WIPE_H__ 24 | #define __F_WIPE_H__ 25 | 26 | // 27 | // SCREEN WIPE PACKAGE 28 | // 29 | 30 | enum 31 | { 32 | // simple gradual pixel change for 8-bit only 33 | wipe_ColorXForm, 34 | 35 | // weird screen melt 36 | wipe_Melt, 37 | 38 | wipe_NUMWIPES 39 | }; 40 | 41 | int 42 | wipe_StartScreen 43 | ( int x, 44 | int y, 45 | int width, 46 | int height ); 47 | 48 | 49 | int 50 | wipe_EndScreen 51 | ( int x, 52 | int y, 53 | int width, 54 | int height ); 55 | 56 | 57 | int 58 | wipe_ScreenWipe 59 | ( int wipeno, 60 | int x, 61 | int y, 62 | int width, 63 | int height, 64 | int ticks ); 65 | 66 | #endif 67 | //----------------------------------------------------------------------------- 68 | // 69 | // $Log:$ 70 | // 71 | //----------------------------------------------------------------------------- 72 | -------------------------------------------------------------------------------- /sdldoom/g_game.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Duh. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __G_GAME__ 24 | #define __G_GAME__ 25 | 26 | #include "doomdef.h" 27 | #include "d_event.h" 28 | 29 | 30 | 31 | // 32 | // GAME 33 | // 34 | void G_DeathMatchSpawnPlayer (int playernum); 35 | 36 | void G_InitNew (skill_t skill, int episode, int map); 37 | 38 | // Can be called by the startup code or M_Responder. 39 | // A normal game starts at map 1, 40 | // but a warp test can start elsewhere 41 | void G_DeferedInitNew (skill_t skill, int episode, int map); 42 | 43 | void G_DeferedPlayDemo (char* demo); 44 | 45 | // Can be called by the startup code or M_Responder, 46 | // calls P_SetupLevel or W_EnterWorld. 47 | void G_LoadGame (char* name); 48 | 49 | void G_DoLoadGame (void); 50 | 51 | // Called by M_Responder. 52 | void G_SaveGame (int slot, char* description); 53 | 54 | // Only called by startup code. 55 | void G_RecordDemo (char* name); 56 | 57 | void G_BeginRecording (void); 58 | 59 | void G_PlayDemo (char* name); 60 | void G_TimeDemo (char* name); 61 | boolean G_CheckDemoStatus (void); 62 | 63 | void G_ExitLevel (void); 64 | void G_SecretExitLevel (void); 65 | 66 | void G_WorldDone (void); 67 | 68 | void G_Ticker (void); 69 | boolean G_Responder (event_t* ev); 70 | 71 | void G_ScreenShot (void); 72 | 73 | 74 | #endif 75 | //----------------------------------------------------------------------------- 76 | // 77 | // $Log:$ 78 | // 79 | //----------------------------------------------------------------------------- 80 | -------------------------------------------------------------------------------- /sdldoom/hu_lib.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: none 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __HULIB__ 22 | #define __HULIB__ 23 | 24 | // We are referring to patches. 25 | #include "r_defs.h" 26 | 27 | 28 | // background and foreground screen numbers 29 | // different from other modules. 30 | #define BG 1 31 | #define FG 0 32 | 33 | // font stuff 34 | #define HU_CHARERASE KEY_BACKSPACE 35 | 36 | #define HU_MAXLINES 4 37 | #define HU_MAXLINELENGTH 80 38 | 39 | // 40 | // Typedefs of widgets 41 | // 42 | 43 | // Text Line widget 44 | // (parent of Scrolling Text and Input Text widgets) 45 | typedef struct 46 | { 47 | // left-justified position of scrolling text window 48 | int x; 49 | int y; 50 | 51 | patch_t** f; // font 52 | int sc; // start character 53 | char l[HU_MAXLINELENGTH+1]; // line of text 54 | int len; // current line length 55 | 56 | // whether this line needs to be udpated 57 | int needsupdate; 58 | 59 | } hu_textline_t; 60 | 61 | 62 | 63 | // Scrolling Text window widget 64 | // (child of Text Line widget) 65 | typedef struct 66 | { 67 | hu_textline_t l[HU_MAXLINES]; // text lines to draw 68 | int h; // height in lines 69 | int cl; // current line number 70 | 71 | // pointer to boolean stating whether to update window 72 | boolean* on; 73 | boolean laston; // last value of *->on. 74 | 75 | } hu_stext_t; 76 | 77 | 78 | 79 | // Input Text Line widget 80 | // (child of Text Line widget) 81 | typedef struct 82 | { 83 | hu_textline_t l; // text line to input on 84 | 85 | // left margin past which I am not to delete characters 86 | int lm; 87 | 88 | // pointer to boolean stating whether to update window 89 | boolean* on; 90 | boolean laston; // last value of *->on; 91 | 92 | } hu_itext_t; 93 | 94 | 95 | // 96 | // Widget creation, access, and update routines 97 | // 98 | 99 | // initializes heads-up widget library 100 | void HUlib_init(void); 101 | 102 | // 103 | // textline code 104 | // 105 | 106 | // clear a line of text 107 | void HUlib_clearTextLine(hu_textline_t *t); 108 | 109 | void HUlib_initTextLine(hu_textline_t *t, int x, int y, patch_t **f, int sc); 110 | 111 | // returns success 112 | boolean HUlib_addCharToTextLine(hu_textline_t *t, char ch); 113 | 114 | // returns success 115 | boolean HUlib_delCharFromTextLine(hu_textline_t *t); 116 | 117 | // draws tline 118 | void HUlib_drawTextLine(hu_textline_t *l, boolean drawcursor); 119 | 120 | // erases text line 121 | void HUlib_eraseTextLine(hu_textline_t *l); 122 | 123 | 124 | // 125 | // Scrolling Text window widget routines 126 | // 127 | 128 | // ? 129 | void 130 | HUlib_initSText 131 | ( hu_stext_t* s, 132 | int x, 133 | int y, 134 | int h, 135 | patch_t** font, 136 | int startchar, 137 | boolean* on ); 138 | 139 | // add a new line 140 | void HUlib_addLineToSText(hu_stext_t* s); 141 | 142 | // ? 143 | void 144 | HUlib_addMessageToSText 145 | ( hu_stext_t* s, 146 | char* prefix, 147 | char* msg ); 148 | 149 | // draws stext 150 | void HUlib_drawSText(hu_stext_t* s); 151 | 152 | // erases all stext lines 153 | void HUlib_eraseSText(hu_stext_t* s); 154 | 155 | // Input Text Line widget routines 156 | void 157 | HUlib_initIText 158 | ( hu_itext_t* it, 159 | int x, 160 | int y, 161 | patch_t** font, 162 | int startchar, 163 | boolean* on ); 164 | 165 | // enforces left margin 166 | void HUlib_delCharFromIText(hu_itext_t* it); 167 | 168 | // enforces left margin 169 | void HUlib_eraseLineFromIText(hu_itext_t* it); 170 | 171 | // resets line and left margin 172 | void HUlib_resetIText(hu_itext_t* it); 173 | 174 | // left of left-margin 175 | void 176 | HUlib_addPrefixToIText 177 | ( hu_itext_t* it, 178 | char* str ); 179 | 180 | // whether eaten 181 | boolean 182 | HUlib_keyInIText 183 | ( hu_itext_t* it, 184 | unsigned char ch ); 185 | 186 | void HUlib_drawIText(hu_itext_t* it); 187 | 188 | // erases all itext lines 189 | void HUlib_eraseIText(hu_itext_t* it); 190 | 191 | #endif 192 | //----------------------------------------------------------------------------- 193 | // 194 | // $Log:$ 195 | // 196 | //----------------------------------------------------------------------------- 197 | -------------------------------------------------------------------------------- /sdldoom/hu_stuff.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: Head up display 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __HU_STUFF_H__ 22 | #define __HU_STUFF_H__ 23 | 24 | #include "d_event.h" 25 | 26 | 27 | // 28 | // Globally visible constants. 29 | // 30 | #define HU_FONTSTART '!' // the first font characters 31 | #define HU_FONTEND '_' // the last font characters 32 | 33 | // Calculate # of glyphs in font. 34 | #define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) 35 | 36 | #define HU_BROADCAST 5 37 | 38 | #define HU_MSGREFRESH KEY_ENTER 39 | #define HU_MSGX 0 40 | #define HU_MSGY 0 41 | #define HU_MSGWIDTH 64 // in characters 42 | #define HU_MSGHEIGHT 1 // in lines 43 | 44 | #define HU_MSGTIMEOUT (4*TICRATE) 45 | 46 | // 47 | // HEADS UP TEXT 48 | // 49 | 50 | void HU_Init(void); 51 | void HU_Start(void); 52 | 53 | boolean HU_Responder(event_t* ev); 54 | 55 | void HU_Ticker(void); 56 | void HU_Drawer(void); 57 | char HU_dequeueChatChar(void); 58 | void HU_Erase(void); 59 | 60 | 61 | #endif 62 | //----------------------------------------------------------------------------- 63 | // 64 | // $Log:$ 65 | // 66 | //----------------------------------------------------------------------------- 67 | -------------------------------------------------------------------------------- /sdldoom/i_main.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Main program, simply calls D_DoomMain high level loop. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | static const char 25 | rcsid[] = "$Id: i_main.c,v 1.4 1997/02/03 22:45:10 b1 Exp $"; 26 | 27 | #include "doomdef.h" 28 | 29 | #include "m_argv.h" 30 | #include "d_main.h" 31 | 32 | int 33 | main 34 | ( int argc, 35 | char** argv ) 36 | { 37 | myargc = argc; 38 | myargv = argv; 39 | 40 | D_DoomMain (); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /sdldoom/i_net.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // System specific network interface stuff. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __I_NET__ 24 | #define __I_NET__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | 33 | // Called by D_DoomMain. 34 | 35 | 36 | void I_InitNetwork (void); 37 | void I_NetCmd (void); 38 | 39 | 40 | #endif 41 | //----------------------------------------------------------------------------- 42 | // 43 | // $Log:$ 44 | // 45 | //----------------------------------------------------------------------------- 46 | -------------------------------------------------------------------------------- /sdldoom/i_sound.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // 18 | // DESCRIPTION: 19 | // System interface, sound. 20 | // 21 | //----------------------------------------------------------------------------- 22 | 23 | #ifndef __I_SOUND__ 24 | #define __I_SOUND__ 25 | 26 | #include "doomdef.h" 27 | 28 | #include "doomstat.h" 29 | #include "sounds.h" 30 | 31 | 32 | 33 | // Init at program start... 34 | void I_InitSound(); 35 | 36 | // ... shut down and relase at program termination. 37 | void I_ShutdownSound(void); 38 | 39 | 40 | // 41 | // SFX I/O 42 | // 43 | 44 | // Initialize channels? 45 | void I_SetChannels(); 46 | 47 | // Get raw data lump index for sound descriptor. 48 | int I_GetSfxLumpNum (sfxinfo_t* sfxinfo ); 49 | 50 | 51 | // Starts a sound in a particular sound channel. 52 | int 53 | I_StartSound 54 | ( int id, 55 | int vol, 56 | int sep, 57 | int pitch, 58 | int priority ); 59 | 60 | 61 | // Stops a sound channel. 62 | void I_StopSound(int handle); 63 | 64 | // Called by S_*() functions 65 | // to see if a channel is still playing. 66 | // Returns 0 if no longer playing, 1 if playing. 67 | int I_SoundIsPlaying(int handle); 68 | 69 | // Updates the volume, separation, 70 | // and pitch of a sound channel. 71 | void 72 | I_UpdateSoundParams 73 | ( int handle, 74 | int vol, 75 | int sep, 76 | int pitch ); 77 | 78 | 79 | // 80 | // MUSIC I/O 81 | // 82 | void I_InitMusic(void); 83 | void I_ShutdownMusic(void); 84 | // Volume. 85 | void I_SetMusicVolume(int volume); 86 | // PAUSE game handling. 87 | void I_PauseSong(int handle); 88 | void I_ResumeSong(int handle); 89 | // Registers a song handle to song data. 90 | int I_RegisterSong(void *data); 91 | // Called by anything that wishes to start music. 92 | // plays a song, and when the song is done, 93 | // starts playing it again in an endless loop. 94 | // Horrible thing to do, considering. 95 | void 96 | I_PlaySong 97 | ( int handle, 98 | int looping ); 99 | // Stops a song over 3 seconds. 100 | void I_StopSong(int handle); 101 | // See above (register), then think backwards 102 | void I_UnRegisterSong(int handle); 103 | 104 | 105 | 106 | #endif 107 | //----------------------------------------------------------------------------- 108 | // 109 | // $Log:$ 110 | // 111 | //----------------------------------------------------------------------------- 112 | -------------------------------------------------------------------------------- /sdldoom/i_system.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // 21 | //----------------------------------------------------------------------------- 22 | 23 | static const char 24 | rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; 25 | 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "doomdef.h" 32 | #include "m_misc.h" 33 | #include "i_video.h" 34 | #include "i_sound.h" 35 | 36 | #include "d_net.h" 37 | #include "g_game.h" 38 | 39 | #ifdef __GNUG__ 40 | #pragma implementation "i_system.h" 41 | #endif 42 | #include "i_system.h" 43 | 44 | #include "rv_av_api.h" 45 | 46 | 47 | 48 | int mb_used = 6; 49 | 50 | 51 | int I_strncasecmp(char *str1, char *str2, int len) 52 | { 53 | char c1, c2; 54 | 55 | while ( *str1 && *str2 && len-- ) { 56 | c1 = *str1++; 57 | c2 = *str2++; 58 | if ( toupper(c1) != toupper(c2) ) 59 | return(1); 60 | } 61 | return(0); 62 | } 63 | 64 | void 65 | I_Tactile 66 | ( int on, 67 | int off, 68 | int total ) 69 | { 70 | // UNUSED. 71 | on = off = total = 0; 72 | } 73 | 74 | ticcmd_t emptycmd; 75 | ticcmd_t* I_BaseTiccmd(void) 76 | { 77 | return &emptycmd; 78 | } 79 | 80 | 81 | int I_GetHeapSize (void) 82 | { 83 | return mb_used*1024*1024; 84 | } 85 | 86 | byte* I_ZoneBase (int* size) 87 | { 88 | *size = mb_used*1024*1024; 89 | return (byte *) malloc (*size); 90 | } 91 | 92 | 93 | 94 | // 95 | // I_GetTime 96 | // returns time in 1/35 second tics 97 | // 98 | int I_GetTime (void) 99 | { 100 | return (av_get_ticks()*TICRATE)/1000; 101 | } 102 | 103 | 104 | 105 | // 106 | // I_Init 107 | // 108 | void I_Init (void) 109 | { 110 | if (av_init(SCREENWIDTH, SCREENHEIGHT) < 0) 111 | I_Error("Could not initialize rv_av"); 112 | I_InitSound(); 113 | // I_InitGraphics(); 114 | } 115 | 116 | // 117 | // I_Quit 118 | // 119 | void I_Quit (void) 120 | { 121 | D_QuitNetGame (); 122 | I_ShutdownSound(); 123 | I_ShutdownMusic(); 124 | M_SaveDefaults (); 125 | I_ShutdownGraphics(); 126 | exit(0); 127 | } 128 | 129 | void I_WaitVBL(int count) 130 | { 131 | av_delay((count*1000)/70); 132 | } 133 | 134 | void I_BeginRead(void) 135 | { 136 | } 137 | 138 | void I_EndRead(void) 139 | { 140 | } 141 | 142 | byte* I_AllocLow(int length) 143 | { 144 | byte* mem; 145 | 146 | mem = (byte *)malloc (length); 147 | memset (mem,0,length); 148 | return mem; 149 | } 150 | 151 | 152 | // 153 | // I_Error 154 | // 155 | extern boolean demorecording; 156 | 157 | void I_Error (char *error, ...) 158 | { 159 | va_list argptr; 160 | 161 | // Message first. 162 | va_start (argptr,error); 163 | fprintf (stderr, "Error: "); 164 | vfprintf (stderr,error,argptr); 165 | fprintf (stderr, "\n"); 166 | va_end (argptr); 167 | 168 | fflush( stderr ); 169 | 170 | // Shutdown. Here might be other errors. 171 | if (demorecording) 172 | G_CheckDemoStatus(); 173 | 174 | D_QuitNetGame (); 175 | I_ShutdownGraphics(); 176 | 177 | exit(-1); 178 | } 179 | -------------------------------------------------------------------------------- /sdldoom/i_system.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // System specific interface stuff. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __I_SYSTEM__ 24 | #define __I_SYSTEM__ 25 | 26 | #include "d_ticcmd.h" 27 | #include "d_event.h" 28 | 29 | #ifdef __GNUG__ 30 | #pragma interface 31 | #endif 32 | 33 | 34 | // Called by DoomMain. 35 | void I_Init (void); 36 | 37 | // Called by startup code 38 | // to get the ammount of memory to malloc 39 | // for the zone management. 40 | byte* I_ZoneBase (int *size); 41 | 42 | 43 | // Called by D_DoomLoop, 44 | // returns current time in tics. 45 | int I_GetTime (void); 46 | 47 | 48 | // 49 | // Called by D_DoomLoop, 50 | // called before processing any tics in a frame 51 | // (just after displaying a frame). 52 | // Time consuming syncronous operations 53 | // are performed here (joystick reading). 54 | // Can call D_PostEvent. 55 | // 56 | void I_StartFrame (void); 57 | 58 | 59 | // 60 | // Called by D_DoomLoop, 61 | // called before processing each tic in a frame. 62 | // Quick syncronous operations are performed here. 63 | // Can call D_PostEvent. 64 | void I_StartTic (void); 65 | 66 | // Asynchronous interrupt functions should maintain private queues 67 | // that are read by the synchronous functions 68 | // to be converted into events. 69 | 70 | // Either returns a null ticcmd, 71 | // or calls a loadable driver to build it. 72 | // This ticcmd will then be modified by the gameloop 73 | // for normal input. 74 | ticcmd_t* I_BaseTiccmd (void); 75 | 76 | 77 | // Called by M_Responder when quit is selected. 78 | // Clean exit, displays sell blurb. 79 | void I_Quit (void); 80 | 81 | 82 | // Allocates from low memory under dos, 83 | // just mallocs under unix 84 | byte* I_AllocLow (int length); 85 | 86 | void I_Tactile (int on, int off, int total); 87 | 88 | 89 | void I_Error (char *error, ...); 90 | 91 | // fixes bug under Win32 (mingwin32) 92 | int I_strncasecmp(char *str1, char *str2, int len); 93 | 94 | #endif 95 | //----------------------------------------------------------------------------- 96 | // 97 | // $Log:$ 98 | // 99 | //----------------------------------------------------------------------------- 100 | -------------------------------------------------------------------------------- /sdldoom/i_video.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // System specific interface stuff. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __I_VIDEO__ 24 | #define __I_VIDEO__ 25 | 26 | 27 | #include "doomtype.h" 28 | 29 | #ifdef __GNUG__ 30 | #pragma interface 31 | #endif 32 | 33 | 34 | // Called by D_DoomMain, 35 | // determines the hardware configuration 36 | // and sets up the video mode 37 | void I_InitGraphics (void); 38 | 39 | 40 | void I_ShutdownGraphics(void); 41 | 42 | // Takes full 8 bit values. 43 | void I_SetPalette (byte* palette); 44 | 45 | void I_UpdateNoBlit (void); 46 | void I_FinishUpdate (void); 47 | 48 | // Wait for vertical retrace or pause a bit. 49 | void I_WaitVBL(int count); 50 | 51 | void I_ReadScreen (byte* scr); 52 | 53 | void I_BeginRead (void); 54 | void I_EndRead (void); 55 | 56 | 57 | 58 | #endif 59 | //----------------------------------------------------------------------------- 60 | // 61 | // $Log:$ 62 | // 63 | //----------------------------------------------------------------------------- 64 | -------------------------------------------------------------------------------- /sdldoom/m_argv.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // 21 | //----------------------------------------------------------------------------- 22 | 23 | static const char 24 | rcsid[] = "$Id: m_argv.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; 25 | 26 | 27 | #include 28 | 29 | #include "i_system.h" 30 | 31 | int myargc; 32 | char** myargv; 33 | 34 | 35 | 36 | 37 | // 38 | // M_CheckParm 39 | // Checks for the given parameter 40 | // in the program's command line arguments. 41 | // Returns the argument number (1 to argc-1) 42 | // or 0 if not present 43 | int M_CheckParm (char *check) 44 | { 45 | int i; 46 | 47 | for (i = 1;ibox[BOXRIGHT]) 54 | box[BOXRIGHT] = x; 55 | if (ybox[BOXTOP]) 58 | box[BOXTOP] = y; 59 | } 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /sdldoom/m_bbox.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Nil. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __M_BBOX__ 24 | #define __M_BBOX__ 25 | 26 | #include "doomtype.h" 27 | 28 | #include "m_fixed.h" 29 | 30 | 31 | // Bounding box coordinate storage. 32 | enum 33 | { 34 | BOXTOP, 35 | BOXBOTTOM, 36 | BOXLEFT, 37 | BOXRIGHT 38 | }; // bbox coordinates 39 | 40 | // Bounding box functions. 41 | void M_ClearBox (fixed_t* box); 42 | 43 | void 44 | M_AddToBox 45 | ( fixed_t* box, 46 | fixed_t x, 47 | fixed_t y ); 48 | 49 | 50 | #endif 51 | //----------------------------------------------------------------------------- 52 | // 53 | // $Log:$ 54 | // 55 | //----------------------------------------------------------------------------- 56 | -------------------------------------------------------------------------------- /sdldoom/m_cheat.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Cheat sequence checking. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | 25 | static const char 26 | rcsid[] = "$Id: m_cheat.c,v 1.1 1997/02/03 21:24:34 b1 Exp $"; 27 | 28 | #include "m_cheat.h" 29 | 30 | // 31 | // CHEAT SEQUENCE PACKAGE 32 | // 33 | 34 | static int firsttime = 1; 35 | static unsigned char cheat_xlate_table[256]; 36 | 37 | 38 | // 39 | // Called in st_stuff module, which handles the input. 40 | // Returns a 1 if the cheat was successful, 0 if failed. 41 | // 42 | int 43 | cht_CheckCheat 44 | ( cheatseq_t* cht, 45 | char key ) 46 | { 47 | int i; 48 | int rc = 0; 49 | 50 | if (firsttime) 51 | { 52 | firsttime = 0; 53 | for (i=0;i<256;i++) cheat_xlate_table[i] = SCRAMBLE(i); 54 | } 55 | 56 | if (!cht->p) 57 | cht->p = cht->sequence; // initialize if first time 58 | 59 | if (*cht->p == 0) 60 | *(cht->p++) = key; 61 | else if 62 | (cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++; 63 | else 64 | cht->p = cht->sequence; 65 | 66 | if (*cht->p == 1) 67 | cht->p++; 68 | else if (*cht->p == 0xff) // end of sequence character 69 | { 70 | cht->p = cht->sequence; 71 | rc = 1; 72 | } 73 | 74 | return rc; 75 | } 76 | 77 | void 78 | cht_GetParam 79 | ( cheatseq_t* cht, 80 | char* buffer ) 81 | { 82 | 83 | unsigned char *p, c; 84 | 85 | p = cht->sequence; 86 | while (*(p++) != 1); 87 | 88 | do 89 | { 90 | c = *p; 91 | *(buffer++) = c; 92 | *(p++) = 0; 93 | } 94 | while (c && *p!=0xff ); 95 | 96 | if (*p==0xff) 97 | *buffer = 0; 98 | 99 | } 100 | 101 | 102 | -------------------------------------------------------------------------------- /sdldoom/m_cheat.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Cheat code checking. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __M_CHEAT__ 24 | #define __M_CHEAT__ 25 | 26 | // 27 | // CHEAT SEQUENCE PACKAGE 28 | // 29 | 30 | #define SCRAMBLE(a) \ 31 | ((((a)&1)<<7) + (((a)&2)<<5) + ((a)&4) + (((a)&8)<<1) \ 32 | + (((a)&16)>>1) + ((a)&32) + (((a)&64)>>5) + (((a)&128)>>7)) 33 | 34 | typedef struct 35 | { 36 | unsigned char* sequence; 37 | unsigned char* p; 38 | 39 | } cheatseq_t; 40 | 41 | int 42 | cht_CheckCheat 43 | ( cheatseq_t* cht, 44 | char key ); 45 | 46 | 47 | void 48 | cht_GetParam 49 | ( cheatseq_t* cht, 50 | char* buffer ); 51 | 52 | 53 | #endif 54 | //----------------------------------------------------------------------------- 55 | // 56 | // $Log:$ 57 | // 58 | //----------------------------------------------------------------------------- 59 | -------------------------------------------------------------------------------- /sdldoom/m_fixed.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Fixed point implementation. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | 25 | static const char 26 | rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $"; 27 | 28 | #include "stdlib.h" 29 | 30 | #include "doomtype.h" 31 | #include "i_system.h" 32 | 33 | #ifdef __GNUG__ 34 | #pragma implementation "m_fixed.h" 35 | #endif 36 | #include "m_fixed.h" 37 | 38 | 39 | 40 | 41 | // Fixme. __USE_C_FIXED__ or something. 42 | 43 | fixed_t 44 | FixedMul 45 | ( fixed_t a, 46 | fixed_t b ) 47 | { 48 | return ((long long) a * (long long) b) >> FRACBITS; 49 | } 50 | 51 | 52 | 53 | // 54 | // FixedDiv, C version. 55 | // 56 | 57 | fixed_t 58 | FixedDiv 59 | ( fixed_t a, 60 | fixed_t b ) 61 | { 62 | if ( (abs(a)>>14) >= abs(b)) 63 | return (a^b)<0 ? MININT : MAXINT; 64 | return FixedDiv2 (a,b); 65 | } 66 | 67 | 68 | 69 | fixed_t 70 | FixedDiv2 71 | ( fixed_t a, 72 | fixed_t b ) 73 | { 74 | 75 | long long c; 76 | c = ((long long)a<<16) / ((long long)b); 77 | return (fixed_t) c; 78 | /* 79 | double c; 80 | 81 | c = ((double)a) / ((double)b) * FRACUNIT; 82 | 83 | if (c >= 2147483648.0 || c < -2147483648.0) 84 | I_Error("FixedDiv: divide by zero"); 85 | return (fixed_t) c;*/ 86 | } 87 | -------------------------------------------------------------------------------- /sdldoom/m_fixed.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Fixed point arithemtics, implementation. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __M_FIXED__ 24 | #define __M_FIXED__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | // 33 | // Fixed point, 32bit as 16.16. 34 | // 35 | #define FRACBITS 16 36 | #define FRACUNIT (1<>8) | (x<<8); 39 | } 40 | 41 | // Swapping 32bit. 42 | unsigned long SwapLONG( unsigned long x) 43 | { 44 | return 45 | (x>>24) 46 | | ((x>>8) & 0xff00) 47 | | ((x<<8) & 0xff0000) 48 | | (x<<24); 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /sdldoom/m_swap.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Endianess handling, swapping 16bit and 32bit. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __M_SWAP__ 24 | #define __M_SWAP__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | // Endianess handling. 33 | // WAD files are stored little endian. 34 | #ifdef sparc 35 | #define __BIG_ENDIAN__ 36 | #endif 37 | #ifdef __BEOS__ 38 | #include 39 | #if B_HOST_IS_BENDIAN 40 | #define __BIG_ENDIAN__ 41 | #endif 42 | #endif 43 | #ifdef __BIG_ENDIAN__ 44 | #define SHORT(x) ((short)SwapSHORT((unsigned short) (x))) 45 | #define LONG(x) ((long)SwapLONG((unsigned long) (x))) 46 | #else 47 | #define SHORT(x) (x) 48 | #define LONG(x) (x) 49 | #endif 50 | 51 | 52 | 53 | 54 | #endif 55 | //----------------------------------------------------------------------------- 56 | // 57 | // $Log:$ 58 | // 59 | //----------------------------------------------------------------------------- 60 | -------------------------------------------------------------------------------- /sdldoom/p_inter.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __P_INTER__ 24 | #define __P_INTER__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | boolean P_GivePower(player_t*, int); 33 | 34 | 35 | 36 | #endif 37 | //----------------------------------------------------------------------------- 38 | // 39 | // $Log:$ 40 | // 41 | //----------------------------------------------------------------------------- 42 | -------------------------------------------------------------------------------- /sdldoom/p_pspr.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Sprite animation. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __P_PSPR__ 24 | #define __P_PSPR__ 25 | 26 | // Basic data types. 27 | // Needs fixed point, and BAM angles. 28 | #include "m_fixed.h" 29 | #include "tables.h" 30 | 31 | 32 | // 33 | // Needs to include the precompiled 34 | // sprite animation tables. 35 | // Header generated by multigen utility. 36 | // This includes all the data for thing animation, 37 | // i.e. the Thing Atrributes table 38 | // and the Frame Sequence table. 39 | #include "info.h" 40 | 41 | #ifdef __GNUG__ 42 | #pragma interface 43 | #endif 44 | 45 | 46 | // 47 | // Frame flags: 48 | // handles maximum brightness (torches, muzzle flare, light sources) 49 | // 50 | #define FF_FULLBRIGHT 0x8000 // flag in thing->frame 51 | #define FF_FRAMEMASK 0x7fff 52 | 53 | 54 | 55 | // 56 | // Overlay psprites are scaled shapes 57 | // drawn directly on the view screen, 58 | // coordinates are given for a 320*200 view screen. 59 | // 60 | typedef enum 61 | { 62 | ps_weapon, 63 | ps_flash, 64 | NUMPSPRITES 65 | 66 | } psprnum_t; 67 | 68 | typedef struct 69 | { 70 | state_t* state; // a NULL state means not active 71 | int tics; 72 | fixed_t sx; 73 | fixed_t sy; 74 | 75 | } pspdef_t; 76 | 77 | #endif 78 | //----------------------------------------------------------------------------- 79 | // 80 | // $Log:$ 81 | // 82 | //----------------------------------------------------------------------------- 83 | -------------------------------------------------------------------------------- /sdldoom/p_saveg.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Savegame I/O, archiving, persistence. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __P_SAVEG__ 24 | #define __P_SAVEG__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | // Persistent storage/archiving. 33 | // These are the load / save game routines. 34 | void P_ArchivePlayers (void); 35 | void P_UnArchivePlayers (void); 36 | void P_ArchiveWorld (void); 37 | void P_UnArchiveWorld (void); 38 | void P_ArchiveThinkers (void); 39 | void P_UnArchiveThinkers (void); 40 | void P_ArchiveSpecials (void); 41 | void P_UnArchiveSpecials (void); 42 | 43 | extern byte* save_p; 44 | 45 | 46 | #endif 47 | //----------------------------------------------------------------------------- 48 | // 49 | // $Log:$ 50 | // 51 | //----------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /sdldoom/p_setup.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Setup a game, startup stuff. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __P_SETUP__ 24 | #define __P_SETUP__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | // NOT called by W_Ticker. Fixme. 33 | void 34 | P_SetupLevel 35 | ( int episode, 36 | int map, 37 | int playermask, 38 | skill_t skill); 39 | 40 | // Called by startup code. 41 | void P_Init (void); 42 | 43 | #endif 44 | //----------------------------------------------------------------------------- 45 | // 46 | // $Log:$ 47 | // 48 | //----------------------------------------------------------------------------- 49 | -------------------------------------------------------------------------------- /sdldoom/p_telept.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Teleportation. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | static const char 25 | rcsid[] = "$Id: p_telept.c,v 1.3 1997/01/28 22:08:29 b1 Exp $"; 26 | 27 | 28 | 29 | #include "doomdef.h" 30 | 31 | #include "s_sound.h" 32 | 33 | #include "p_local.h" 34 | 35 | 36 | // Data. 37 | #include "sounds.h" 38 | 39 | // State. 40 | #include "r_state.h" 41 | 42 | 43 | 44 | // 45 | // TELEPORTATION 46 | // 47 | int 48 | EV_Teleport 49 | ( line_t* line, 50 | int side, 51 | mobj_t* thing ) 52 | { 53 | int i; 54 | int tag; 55 | mobj_t* m; 56 | mobj_t* fog; 57 | unsigned an; 58 | thinker_t* thinker; 59 | sector_t* sector; 60 | fixed_t oldx; 61 | fixed_t oldy; 62 | fixed_t oldz; 63 | 64 | // don't teleport missiles 65 | if (thing->flags & MF_MISSILE) 66 | return 0; 67 | 68 | // Don't teleport if hit back of line, 69 | // so you can get out of teleporter. 70 | if (side == 1) 71 | return 0; 72 | 73 | 74 | tag = line->tag; 75 | for (i = 0; i < numsectors; i++) 76 | { 77 | if (sectors[ i ].tag == tag ) 78 | { 79 | thinker = thinkercap.next; 80 | for (thinker = thinkercap.next; 81 | thinker != &thinkercap; 82 | thinker = thinker->next) 83 | { 84 | // not a mobj 85 | if (thinker->function.acp1 != (actionf_p1)P_MobjThinker) 86 | continue; 87 | 88 | m = (mobj_t *)thinker; 89 | 90 | // not a teleportman 91 | if (m->type != MT_TELEPORTMAN ) 92 | continue; 93 | 94 | sector = m->subsector->sector; 95 | // wrong sector 96 | if (sector-sectors != i ) 97 | continue; 98 | 99 | oldx = thing->x; 100 | oldy = thing->y; 101 | oldz = thing->z; 102 | 103 | if (!P_TeleportMove (thing, m->x, m->y)) 104 | return 0; 105 | 106 | thing->z = thing->floorz; //fixme: not needed? 107 | if (thing->player) 108 | thing->player->viewz = thing->z+thing->player->viewheight; 109 | 110 | // spawn teleport fog at source and destination 111 | fog = P_SpawnMobj (oldx, oldy, oldz, MT_TFOG); 112 | S_StartSound (fog, sfx_telept); 113 | an = m->angle >> ANGLETOFINESHIFT; 114 | fog = P_SpawnMobj (m->x+20*finecosine[an], m->y+20*finesine[an] 115 | , thing->z, MT_TFOG); 116 | 117 | // emit sound, where? 118 | S_StartSound (fog, sfx_telept); 119 | 120 | // don't move for a bit 121 | if (thing->player) 122 | thing->reactiontime = 18; 123 | 124 | thing->angle = m->angle; 125 | thing->momx = thing->momy = thing->momz = 0; 126 | return 1; 127 | } 128 | } 129 | } 130 | return 0; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /sdldoom/p_tick.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // Archiving: SaveGame I/O. 21 | // Thinker, Ticker. 22 | // 23 | //----------------------------------------------------------------------------- 24 | 25 | static const char 26 | rcsid[] = "$Id: p_tick.c,v 1.4 1997/02/03 16:47:55 b1 Exp $"; 27 | 28 | #include "z_zone.h" 29 | #include "p_local.h" 30 | 31 | #include "doomstat.h" 32 | 33 | 34 | int leveltime; 35 | 36 | // 37 | // THINKERS 38 | // All thinkers should be allocated by Z_Malloc 39 | // so they can be operated on uniformly. 40 | // The actual structures will vary in size, 41 | // but the first element must be thinker_t. 42 | // 43 | 44 | 45 | 46 | // Both the head and tail of the thinker list. 47 | thinker_t thinkercap; 48 | 49 | 50 | // 51 | // P_InitThinkers 52 | // 53 | void P_InitThinkers (void) 54 | { 55 | thinkercap.prev = thinkercap.next = &thinkercap; 56 | } 57 | 58 | 59 | 60 | 61 | // 62 | // P_AddThinker 63 | // Adds a new thinker at the end of the list. 64 | // 65 | void P_AddThinker (thinker_t* thinker) 66 | { 67 | thinkercap.prev->next = thinker; 68 | thinker->next = &thinkercap; 69 | thinker->prev = thinkercap.prev; 70 | thinkercap.prev = thinker; 71 | } 72 | 73 | 74 | 75 | // 76 | // P_RemoveThinker 77 | // Deallocation is lazy -- it will not actually be freed 78 | // until its thinking turn comes up. 79 | // 80 | void P_RemoveThinker (thinker_t* thinker) 81 | { 82 | // FIXME: NOP. 83 | thinker->function.acv = (actionf_v)(-1); 84 | } 85 | 86 | 87 | 88 | // 89 | // P_AllocateThinker 90 | // Allocates memory and adds a new thinker at the end of the list. 91 | // 92 | void P_AllocateThinker (thinker_t* thinker) 93 | { 94 | } 95 | 96 | 97 | 98 | // 99 | // P_RunThinkers 100 | // 101 | void P_RunThinkers (void) 102 | { 103 | thinker_t* currentthinker; 104 | 105 | currentthinker = thinkercap.next; 106 | while (currentthinker != &thinkercap) 107 | { 108 | if ( currentthinker->function.acv == (actionf_v)(-1) ) 109 | { 110 | // time to remove it 111 | currentthinker->next->prev = currentthinker->prev; 112 | currentthinker->prev->next = currentthinker->next; 113 | Z_Free (currentthinker); 114 | } 115 | else 116 | { 117 | if (currentthinker->function.acp1) 118 | currentthinker->function.acp1 (currentthinker); 119 | } 120 | currentthinker = currentthinker->next; 121 | } 122 | } 123 | 124 | 125 | 126 | // 127 | // P_Ticker 128 | // 129 | 130 | void P_Ticker (void) 131 | { 132 | int i; 133 | 134 | // run the tic 135 | if (paused) 136 | return; 137 | 138 | // pause if in menu and at least one tic has been run 139 | if ( !netgame 140 | && menuactive 141 | && !demoplayback 142 | && players[consoleplayer].viewz != 1) 143 | { 144 | return; 145 | } 146 | 147 | 148 | for (i=0 ; i 2 | #include 3 | #include "rv_av_api.h" 4 | 5 | static inline long 6 | __syscall_error(long a0) 7 | { 8 | errno = -a0; 9 | return -1; 10 | } 11 | 12 | static inline long 13 | __internal_syscall(long n, long _a0, long _a1, long _a2, long _a3, long _a4, long _a5) 14 | { 15 | register long a0 asm("a0") = _a0; 16 | register long a1 asm("a1") = _a1; 17 | register long a2 asm("a2") = _a2; 18 | register long a3 asm("a3") = _a3; 19 | register long a4 asm("a4") = _a4; 20 | register long a5 asm("a5") = _a5; 21 | 22 | #ifdef __riscv_32e 23 | register long syscall_id asm("t0") = n; 24 | #else 25 | register long syscall_id asm("a7") = n; 26 | #endif 27 | 28 | asm volatile ("scall" 29 | : "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(syscall_id)); 30 | 31 | if (a0 < 0) 32 | return __syscall_error (a0); 33 | else 34 | return a0; 35 | } 36 | 37 | #define syscall_errno(n, a, b, c, d, e, f) \ 38 | __internal_syscall(n, (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f)) 39 | 40 | int av_init(int width, int height) 41 | { 42 | return syscall_errno(SYS_av_init, width, height, 0, 0, 0, 0); 43 | } 44 | 45 | int av_set_framebuffer(uint8_t *pixels) 46 | { 47 | return syscall_errno(SYS_av_set_framebuffer, pixels, 0, 0, 0, 0, 0); 48 | } 49 | 50 | void av_delay(uint32_t ms) 51 | { 52 | syscall_errno(SYS_av_delay, ms, 0, 0, 0, 0, 0); 53 | } 54 | 55 | int av_update() 56 | { 57 | return syscall_errno(SYS_av_update, 0, 0, 0, 0, 0, 0); 58 | } 59 | 60 | int av_set_palette(struct av_color *palette, int ncolors) 61 | { 62 | return syscall_errno(SYS_av_set_palette, palette, ncolors, 0, 0, 0, 0); 63 | } 64 | 65 | int av_poll_event(struct av_event *evt) 66 | { 67 | return syscall_errno(SYS_av_poll_event, evt, 0, 0, 0, 0, 0); 68 | } 69 | 70 | uint32_t av_get_ticks() 71 | { 72 | return syscall_errno(SYS_av_get_ticks, 0, 0, 0, 0, 0, 0); 73 | } 74 | 75 | uint32_t av_get_mouse_state(int *x, int *y) 76 | { 77 | return syscall_errno(SYS_av_get_mouse_state, x, y, 0, 0, 0, 0); 78 | } 79 | 80 | int av_warp_mouse(int x, int y) 81 | { 82 | return syscall_errno(SYS_av_warp_mouse, x, y, 0, 0, 0, 0); 83 | } 84 | 85 | void av_shutdown() 86 | { 87 | syscall_errno(SYS_av_shutdown, 0, 0, 0, 0, 0, 0); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /sdldoom/rv_av_api.h: -------------------------------------------------------------------------------- 1 | #ifndef RV_AV_API_H 2 | #define RV_AV_API_H 3 | 4 | #include "../rv_av.h" 5 | 6 | int av_init(int width, int height); 7 | int av_set_framebuffer(uint8_t *pixels); 8 | void av_delay(uint32_t ms); 9 | int av_update(); 10 | int av_poll_event(struct av_event *evt); 11 | int av_set_palette(struct av_color *palette, int ncolors); 12 | uint32_t av_get_ticks(); 13 | uint32_t av_get_mouse_state(int *x, int *y); 14 | int av_warp_mouse(int x, int y); 15 | void av_shutdown(); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /sdldoom/s_sound.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // The not so system specific sound interface. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __S_SOUND__ 24 | #define __S_SOUND__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | 33 | // 34 | // Initializes sound stuff, including volume 35 | // Sets channels, SFX and music volume, 36 | // allocates channel buffer, sets S_sfx lookup. 37 | // 38 | void 39 | S_Init 40 | ( int sfxVolume, 41 | int musicVolume ); 42 | 43 | 44 | 45 | 46 | // 47 | // Per level startup code. 48 | // Kills playing sounds at start of level, 49 | // determines music if any, changes music. 50 | // 51 | void S_Start(void); 52 | 53 | 54 | // 55 | // Start sound for thing at 56 | // using from sounds.h 57 | // 58 | void 59 | S_StartSound 60 | ( void* origin, 61 | int sound_id ); 62 | 63 | 64 | 65 | // Will start a sound at a given volume. 66 | void 67 | S_StartSoundAtVolume 68 | ( void* origin, 69 | int sound_id, 70 | int volume ); 71 | 72 | 73 | // Stop sound for thing at 74 | void S_StopSound(void* origin); 75 | 76 | 77 | // Start music using from sounds.h 78 | void S_StartMusic(int music_id); 79 | 80 | // Start music using from sounds.h, 81 | // and set whether looping 82 | void 83 | S_ChangeMusic 84 | ( int music_id, 85 | int looping ); 86 | 87 | // Stops the music fer sure. 88 | void S_StopMusic(void); 89 | 90 | // Stop and resume music, during game PAUSE. 91 | void S_PauseSound(void); 92 | void S_ResumeSound(void); 93 | 94 | 95 | // 96 | // Updates music & sounds 97 | // 98 | void S_UpdateSounds(void* listener); 99 | 100 | void S_SetMusicVolume(int volume); 101 | void S_SetSfxVolume(int volume); 102 | 103 | 104 | #endif 105 | //----------------------------------------------------------------------------- 106 | // 107 | // $Log:$ 108 | // 109 | //----------------------------------------------------------------------------- 110 | -------------------------------------------------------------------------------- /sdldoom/st_lib.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // $Log:$ 18 | // 19 | // DESCRIPTION: 20 | // The status bar widget code. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | 25 | static const char 26 | rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $"; 27 | 28 | #include 29 | 30 | #include "m_swap.h" 31 | 32 | #include "doomdef.h" 33 | 34 | #include "z_zone.h" 35 | #include "v_video.h" 36 | 37 | #include "i_system.h" 38 | 39 | #include "w_wad.h" 40 | 41 | #include "st_stuff.h" 42 | #include "st_lib.h" 43 | #include "r_local.h" 44 | 45 | 46 | // in AM_map.c 47 | extern boolean automapactive; 48 | 49 | 50 | 51 | 52 | // 53 | // Hack display negative frags. 54 | // Loads and store the stminus lump. 55 | // 56 | patch_t* sttminus; 57 | 58 | void STlib_init(void) 59 | { 60 | sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC); 61 | } 62 | 63 | 64 | // ? 65 | void 66 | STlib_initNum 67 | ( st_number_t* n, 68 | int x, 69 | int y, 70 | patch_t** pl, 71 | int* num, 72 | boolean* on, 73 | int width ) 74 | { 75 | n->x = x; 76 | n->y = y; 77 | n->oldnum = 0; 78 | n->width = width; 79 | n->num = num; 80 | n->on = on; 81 | n->p = pl; 82 | } 83 | 84 | 85 | // 86 | // A fairly efficient way to draw a number 87 | // based on differences from the old number. 88 | // Note: worth the trouble? 89 | // 90 | void 91 | STlib_drawNum 92 | ( st_number_t* n, 93 | boolean refresh ) 94 | { 95 | 96 | int numdigits = n->width; 97 | int num = *n->num; 98 | 99 | int w = SHORT(n->p[0]->width); 100 | int h = SHORT(n->p[0]->height); 101 | int x = n->x; 102 | 103 | int neg; 104 | 105 | n->oldnum = *n->num; 106 | 107 | neg = num < 0; 108 | 109 | if (neg) 110 | { 111 | if (numdigits == 2 && num < -9) 112 | num = -9; 113 | else if (numdigits == 3 && num < -99) 114 | num = -99; 115 | 116 | num = -num; 117 | } 118 | 119 | // clear the area 120 | x = n->x - numdigits*w; 121 | 122 | if (n->y - ST_Y < 0) 123 | I_Error("drawNum: n->y - ST_Y < 0"); 124 | 125 | V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG); 126 | 127 | // if non-number, do not draw it 128 | if (num == 1994) 129 | return; 130 | 131 | x = n->x; 132 | 133 | // in the special case of 0, you draw 0 134 | if (!num) 135 | V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]); 136 | 137 | // draw the new number 138 | while (num && numdigits--) 139 | { 140 | x -= w; 141 | V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]); 142 | num /= 10; 143 | } 144 | 145 | // draw a minus sign if necessary 146 | if (neg) 147 | V_DrawPatch(x - 8, n->y, FG, sttminus); 148 | } 149 | 150 | 151 | // 152 | void 153 | STlib_updateNum 154 | ( st_number_t* n, 155 | boolean refresh ) 156 | { 157 | if (*n->on) STlib_drawNum(n, refresh); 158 | } 159 | 160 | 161 | // 162 | void 163 | STlib_initPercent 164 | ( st_percent_t* p, 165 | int x, 166 | int y, 167 | patch_t** pl, 168 | int* num, 169 | boolean* on, 170 | patch_t* percent ) 171 | { 172 | STlib_initNum(&p->n, x, y, pl, num, on, 3); 173 | p->p = percent; 174 | } 175 | 176 | 177 | 178 | 179 | void 180 | STlib_updatePercent 181 | ( st_percent_t* per, 182 | int refresh ) 183 | { 184 | if (refresh && *per->n.on) 185 | V_DrawPatch(per->n.x, per->n.y, FG, per->p); 186 | 187 | STlib_updateNum(&per->n, refresh); 188 | } 189 | 190 | 191 | 192 | void 193 | STlib_initMultIcon 194 | ( st_multicon_t* i, 195 | int x, 196 | int y, 197 | patch_t** il, 198 | int* inum, 199 | boolean* on ) 200 | { 201 | i->x = x; 202 | i->y = y; 203 | i->oldinum = -1; 204 | i->inum = inum; 205 | i->on = on; 206 | i->p = il; 207 | } 208 | 209 | 210 | 211 | void 212 | STlib_updateMultIcon 213 | ( st_multicon_t* mi, 214 | boolean refresh ) 215 | { 216 | int w; 217 | int h; 218 | int x; 219 | int y; 220 | 221 | if (*mi->on 222 | && (mi->oldinum != *mi->inum || refresh) 223 | && (*mi->inum!=-1)) 224 | { 225 | if (mi->oldinum != -1) 226 | { 227 | x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset); 228 | y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset); 229 | w = SHORT(mi->p[mi->oldinum]->width); 230 | h = SHORT(mi->p[mi->oldinum]->height); 231 | 232 | if (y - ST_Y < 0) 233 | I_Error("updateMultIcon: y - ST_Y < 0"); 234 | 235 | V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG); 236 | } 237 | V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]); 238 | mi->oldinum = *mi->inum; 239 | } 240 | } 241 | 242 | 243 | 244 | void 245 | STlib_initBinIcon 246 | ( st_binicon_t* b, 247 | int x, 248 | int y, 249 | patch_t* i, 250 | boolean* val, 251 | boolean* on ) 252 | { 253 | b->x = x; 254 | b->y = y; 255 | b->oldval = 0; 256 | b->val = val; 257 | b->on = on; 258 | b->p = i; 259 | } 260 | 261 | 262 | 263 | void 264 | STlib_updateBinIcon 265 | ( st_binicon_t* bi, 266 | boolean refresh ) 267 | { 268 | int x; 269 | int y; 270 | int w; 271 | int h; 272 | 273 | if (*bi->on 274 | && (bi->oldval != *bi->val || refresh)) 275 | { 276 | x = bi->x - SHORT(bi->p->leftoffset); 277 | y = bi->y - SHORT(bi->p->topoffset); 278 | w = SHORT(bi->p->width); 279 | h = SHORT(bi->p->height); 280 | 281 | if (y - ST_Y < 0) 282 | I_Error("updateBinIcon: y - ST_Y < 0"); 283 | 284 | if (*bi->val) 285 | V_DrawPatch(bi->x, bi->y, FG, bi->p); 286 | else 287 | V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG); 288 | 289 | bi->oldval = *bi->val; 290 | } 291 | 292 | } 293 | 294 | -------------------------------------------------------------------------------- /sdldoom/st_lib.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // The status bar widget code. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | #ifndef __STLIB__ 23 | #define __STLIB__ 24 | 25 | 26 | // We are referring to patches. 27 | #include "r_defs.h" 28 | 29 | 30 | // 31 | // Background and foreground screen numbers 32 | // 33 | #define BG 4 34 | #define FG 0 35 | 36 | 37 | 38 | // 39 | // Typedefs of widgets 40 | // 41 | 42 | // Number widget 43 | 44 | typedef struct 45 | { 46 | // upper right-hand corner 47 | // of the number (right-justified) 48 | int x; 49 | int y; 50 | 51 | // max # of digits in number 52 | int width; 53 | 54 | // last number value 55 | int oldnum; 56 | 57 | // pointer to current value 58 | int* num; 59 | 60 | // pointer to boolean stating 61 | // whether to update number 62 | boolean* on; 63 | 64 | // list of patches for 0-9 65 | patch_t** p; 66 | 67 | // user data 68 | int data; 69 | 70 | } st_number_t; 71 | 72 | 73 | 74 | // Percent widget ("child" of number widget, 75 | // or, more precisely, contains a number widget.) 76 | typedef struct 77 | { 78 | // number information 79 | st_number_t n; 80 | 81 | // percent sign graphic 82 | patch_t* p; 83 | 84 | } st_percent_t; 85 | 86 | 87 | 88 | // Multiple Icon widget 89 | typedef struct 90 | { 91 | // center-justified location of icons 92 | int x; 93 | int y; 94 | 95 | // last icon number 96 | int oldinum; 97 | 98 | // pointer to current icon 99 | int* inum; 100 | 101 | // pointer to boolean stating 102 | // whether to update icon 103 | boolean* on; 104 | 105 | // list of icons 106 | patch_t** p; 107 | 108 | // user data 109 | int data; 110 | 111 | } st_multicon_t; 112 | 113 | 114 | 115 | 116 | // Binary Icon widget 117 | 118 | typedef struct 119 | { 120 | // center-justified location of icon 121 | int x; 122 | int y; 123 | 124 | // last icon value 125 | int oldval; 126 | 127 | // pointer to current icon status 128 | boolean* val; 129 | 130 | // pointer to boolean 131 | // stating whether to update icon 132 | boolean* on; 133 | 134 | 135 | patch_t* p; // icon 136 | int data; // user data 137 | 138 | } st_binicon_t; 139 | 140 | 141 | 142 | // 143 | // Widget creation, access, and update routines 144 | // 145 | 146 | // Initializes widget library. 147 | // More precisely, initialize STMINUS, 148 | // everything else is done somewhere else. 149 | // 150 | void STlib_init(void); 151 | 152 | 153 | 154 | // Number widget routines 155 | void 156 | STlib_initNum 157 | ( st_number_t* n, 158 | int x, 159 | int y, 160 | patch_t** pl, 161 | int* num, 162 | boolean* on, 163 | int width ); 164 | 165 | void 166 | STlib_updateNum 167 | ( st_number_t* n, 168 | boolean refresh ); 169 | 170 | 171 | // Percent widget routines 172 | void 173 | STlib_initPercent 174 | ( st_percent_t* p, 175 | int x, 176 | int y, 177 | patch_t** pl, 178 | int* num, 179 | boolean* on, 180 | patch_t* percent ); 181 | 182 | 183 | void 184 | STlib_updatePercent 185 | ( st_percent_t* per, 186 | int refresh ); 187 | 188 | 189 | // Multiple Icon widget routines 190 | void 191 | STlib_initMultIcon 192 | ( st_multicon_t* mi, 193 | int x, 194 | int y, 195 | patch_t** il, 196 | int* inum, 197 | boolean* on ); 198 | 199 | 200 | void 201 | STlib_updateMultIcon 202 | ( st_multicon_t* mi, 203 | boolean refresh ); 204 | 205 | // Binary Icon widget routines 206 | 207 | void 208 | STlib_initBinIcon 209 | ( st_binicon_t* b, 210 | int x, 211 | int y, 212 | patch_t* i, 213 | boolean* val, 214 | boolean* on ); 215 | 216 | void 217 | STlib_updateBinIcon 218 | ( st_binicon_t* bi, 219 | boolean refresh ); 220 | 221 | #endif 222 | //----------------------------------------------------------------------------- 223 | // 224 | // $Log:$ 225 | // 226 | //----------------------------------------------------------------------------- 227 | -------------------------------------------------------------------------------- /sdldoom/st_stuff.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Status bar code. 19 | // Does the face/direction indicator animatin. 20 | // Does palette indicators as well (red pain/berserk, bright pickup) 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | #ifndef __STSTUFF_H__ 25 | #define __STSTUFF_H__ 26 | 27 | #include "doomtype.h" 28 | #include "d_event.h" 29 | 30 | // Size of statusbar. 31 | // Now sensitive for scaling. 32 | #define ST_HEIGHT 32*SCREEN_MUL 33 | #define ST_WIDTH SCREENWIDTH 34 | #define ST_Y (SCREENHEIGHT - ST_HEIGHT) 35 | 36 | 37 | // 38 | // STATUS BAR 39 | // 40 | 41 | // Called by main loop. 42 | boolean ST_Responder (event_t* ev); 43 | 44 | // Called by main loop. 45 | void ST_Ticker (void); 46 | 47 | // Called by main loop. 48 | void ST_Drawer (boolean fullscreen, boolean refresh); 49 | 50 | // Called when the console player is spawned on each level. 51 | void ST_Start (void); 52 | 53 | // Called by startup code. 54 | void ST_Init (void); 55 | 56 | 57 | 58 | // States for status bar code. 59 | typedef enum 60 | { 61 | AutomapState, 62 | FirstPersonState 63 | 64 | } st_stateenum_t; 65 | 66 | 67 | // States for the chat code. 68 | typedef enum 69 | { 70 | StartChatState, 71 | WaitDestState, 72 | GetChatState 73 | 74 | } st_chatstateenum_t; 75 | 76 | 77 | boolean ST_Responder(event_t* ev); 78 | 79 | 80 | 81 | #endif 82 | //----------------------------------------------------------------------------- 83 | // 84 | // $Log:$ 85 | // 86 | //----------------------------------------------------------------------------- 87 | -------------------------------------------------------------------------------- /sdldoom/tables.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Lookup tables. 19 | // Do not try to look them up :-). 20 | // In the order of appearance: 21 | // 22 | // int finetangent[4096] - Tangens LUT. 23 | // Should work with BAM fairly well (12 of 16bit, 24 | // effectively, by shifting). 25 | // 26 | // int finesine[10240] - Sine lookup. 27 | // Guess what, serves as cosine, too. 28 | // Remarkable thing is, how to use BAMs with this? 29 | // 30 | // int tantoangle[2049] - ArcTan LUT, 31 | // maps tan(angle) to angle fast. Gotta search. 32 | // 33 | //----------------------------------------------------------------------------- 34 | 35 | 36 | #ifndef __TABLES__ 37 | #define __TABLES__ 38 | 39 | 40 | 41 | #ifndef PI 42 | #define PI 3.141592657 43 | #endif 44 | 45 | 46 | #include "m_fixed.h" 47 | 48 | #define FINEANGLES 8192 49 | #define FINEMASK (FINEANGLES-1) 50 | 51 | 52 | // 0x100000000 to 0x2000 53 | #define ANGLETOFINESHIFT 19 54 | 55 | // Effective size is 10240. 56 | extern fixed_t finesine[5*FINEANGLES/4]; 57 | 58 | // Re-use data, is just PI/2 pahse shift. 59 | extern fixed_t* finecosine; 60 | 61 | 62 | // Effective size is 4096. 63 | extern fixed_t finetangent[FINEANGLES/2]; 64 | 65 | // Binary Angle Measument, BAM. 66 | #define ANG45 0x20000000 67 | #define ANG90 0x40000000 68 | #define ANG180 0x80000000 69 | #define ANG270 0xc0000000 70 | 71 | 72 | #define SLOPERANGE 2048 73 | #define SLOPEBITS 11 74 | #define DBITS (FRACBITS-SLOPEBITS) 75 | 76 | typedef unsigned angle_t; 77 | 78 | 79 | // Effective size is 2049; 80 | // The +1 size is to handle the case when x==y 81 | // without additional checking. 82 | extern angle_t tantoangle[SLOPERANGE+1]; 83 | 84 | 85 | // Utility function, 86 | // called by R_PointToAngle. 87 | int 88 | SlopeDiv 89 | ( unsigned num, 90 | unsigned den); 91 | 92 | 93 | #endif 94 | //----------------------------------------------------------------------------- 95 | // 96 | // $Log:$ 97 | // 98 | //----------------------------------------------------------------------------- 99 | -------------------------------------------------------------------------------- /sdldoom/v_video.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Gamma correction LUT. 19 | // Functions to draw patches (by post) directly to screen. 20 | // Functions to blit a block to the screen. 21 | // 22 | //----------------------------------------------------------------------------- 23 | 24 | 25 | #ifndef __V_VIDEO__ 26 | #define __V_VIDEO__ 27 | 28 | #include "doomtype.h" 29 | 30 | #include "doomdef.h" 31 | 32 | // Needed because we are refering to patches. 33 | #include "r_data.h" 34 | 35 | // 36 | // VIDEO 37 | // 38 | 39 | #define CENTERY (SCREENHEIGHT/2) 40 | 41 | 42 | // Screen 0 is the screen updated by I_Update screen. 43 | // Screen 1 is an extra buffer. 44 | 45 | 46 | 47 | extern byte* screens[5]; 48 | 49 | extern int dirtybox[4]; 50 | 51 | extern byte gammatable[5][256]; 52 | extern int usegamma; 53 | 54 | 55 | 56 | // Allocates buffer screens, call before R_Init. 57 | void V_Init (void); 58 | 59 | 60 | void 61 | V_CopyRect 62 | ( int srcx, 63 | int srcy, 64 | int srcscrn, 65 | int width, 66 | int height, 67 | int destx, 68 | int desty, 69 | int destscrn ); 70 | 71 | void 72 | V_DrawPatch 73 | ( int x, 74 | int y, 75 | int scrn, 76 | patch_t* patch); 77 | 78 | void 79 | V_DrawPatchDirect 80 | ( int x, 81 | int y, 82 | int scrn, 83 | patch_t* patch ); 84 | 85 | 86 | // Draw a linear block of pixels into the view buffer. 87 | void 88 | V_DrawBlock 89 | ( int x, 90 | int y, 91 | int scrn, 92 | int width, 93 | int height, 94 | byte* src ); 95 | 96 | // Reads a linear block of pixels into the view buffer. 97 | void 98 | V_GetBlock 99 | ( int x, 100 | int y, 101 | int scrn, 102 | int width, 103 | int height, 104 | byte* dest ); 105 | 106 | 107 | void 108 | V_MarkRect 109 | ( int x, 110 | int y, 111 | int width, 112 | int height ); 113 | 114 | #endif 115 | //----------------------------------------------------------------------------- 116 | // 117 | // $Log:$ 118 | // 119 | //----------------------------------------------------------------------------- 120 | -------------------------------------------------------------------------------- /sdldoom/w_wad.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // WAD I/O functions. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | 23 | #ifndef __W_WAD__ 24 | #define __W_WAD__ 25 | 26 | 27 | #ifdef __GNUG__ 28 | #pragma interface 29 | #endif 30 | 31 | 32 | // 33 | // TYPES 34 | // 35 | typedef struct 36 | { 37 | // Should be "IWAD" or "PWAD". 38 | char identification[4]; 39 | int numlumps; 40 | int infotableofs; 41 | 42 | } wadinfo_t; 43 | 44 | 45 | typedef struct 46 | { 47 | int filepos; 48 | int size; 49 | char name[8]; 50 | 51 | } filelump_t; 52 | 53 | // 54 | // WADFILE I/O related stuff. 55 | // 56 | typedef struct 57 | { 58 | char name[8]; 59 | int handle; 60 | int position; 61 | int size; 62 | } lumpinfo_t; 63 | 64 | 65 | extern void** lumpcache; 66 | extern lumpinfo_t* lumpinfo; 67 | extern int numlumps; 68 | 69 | void W_InitMultipleFiles (char** filenames); 70 | void W_Reload (void); 71 | 72 | int W_CheckNumForName (char* name); 73 | int W_GetNumForName (char* name); 74 | 75 | int W_LumpLength (int lump); 76 | void W_ReadLump (int lump, void *dest); 77 | 78 | void* W_CacheLumpNum (int lump, int tag); 79 | void* W_CacheLumpName (char* name, int tag); 80 | 81 | 82 | 83 | 84 | #endif 85 | //----------------------------------------------------------------------------- 86 | // 87 | // $Log:$ 88 | // 89 | //----------------------------------------------------------------------------- 90 | -------------------------------------------------------------------------------- /sdldoom/wi_stuff.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Intermission. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | #ifndef __WI_STUFF__ 23 | #define __WI_STUFF__ 24 | 25 | //#include "v_video.h" 26 | 27 | #include "doomdef.h" 28 | 29 | // States for the intermission 30 | 31 | typedef enum 32 | { 33 | NoState = -1, 34 | StatCount, 35 | ShowNextLoc 36 | 37 | } stateenum_t; 38 | 39 | // Called by main loop, animate the intermission. 40 | void WI_Ticker (void); 41 | 42 | // Called by main loop, 43 | // draws the intermission directly into the screen buffer. 44 | void WI_Drawer (void); 45 | 46 | // Setup for an intermission screen. 47 | void WI_Start(wbstartstruct_t* wbstartstruct); 48 | 49 | #endif 50 | //----------------------------------------------------------------------------- 51 | // 52 | // $Log:$ 53 | // 54 | //----------------------------------------------------------------------------- 55 | -------------------------------------------------------------------------------- /sdldoom/z_zone.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // $Id:$ 5 | // 6 | // Copyright (C) 1993-1996 by id Software, Inc. 7 | // 8 | // This source is available for distribution and/or modification 9 | // only under the terms of the DOOM Source Code License as 10 | // published by id Software. All rights reserved. 11 | // 12 | // The source is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 15 | // for more details. 16 | // 17 | // DESCRIPTION: 18 | // Zone Memory Allocation, perhaps NeXT ObjectiveC inspired. 19 | // Remark: this was the only stuff that, according 20 | // to John Carmack, might have been useful for 21 | // Quake. 22 | // 23 | //--------------------------------------------------------------------- 24 | 25 | 26 | 27 | #ifndef __Z_ZONE__ 28 | #define __Z_ZONE__ 29 | 30 | #include 31 | 32 | // 33 | // ZONE MEMORY 34 | // PU - purge tags. 35 | // Tags < 100 are not overwritten until freed. 36 | #define PU_STATIC 1 // static entire execution time 37 | #define PU_SOUND 2 // static while playing 38 | #define PU_MUSIC 3 // static while playing 39 | #define PU_DAVE 4 // anything else Dave wants static 40 | #define PU_LEVEL 50 // static until level exited 41 | #define PU_LEVSPEC 51 // a special thinker in a level 42 | // Tags >= 100 are purgable whenever needed. 43 | #define PU_PURGELEVEL 100 44 | #define PU_CACHE 101 45 | 46 | 47 | void Z_Init (void); 48 | void* Z_Malloc (int size, int tag, void *ptr); 49 | void Z_Free (void *ptr); 50 | void Z_FreeTags (int lowtag, int hightag); 51 | void Z_DumpHeap (int lowtag, int hightag); 52 | void Z_FileDumpHeap (FILE *f); 53 | void Z_CheckHeap (void); 54 | void Z_ChangeTag2 (void *ptr, int tag); 55 | int Z_FreeMemory (void); 56 | 57 | 58 | typedef struct memblock_s 59 | { 60 | int size; // including the header and possibly tiny fragments 61 | void** user; // NULL if a free block 62 | int tag; // purgelevel 63 | int id; // should be ZONEID 64 | struct memblock_s* next; 65 | struct memblock_s* prev; 66 | } memblock_t; 67 | 68 | // 69 | // This is used to get the local FILE:LINE info from CPP 70 | // prior to really call the function in question. 71 | // 72 | #define Z_ChangeTag(p,t) \ 73 | { \ 74 | if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \ 75 | I_Error("Z_CT at "__FILE__":%i",__LINE__); \ 76 | Z_ChangeTag2(p,t); \ 77 | }; 78 | 79 | 80 | 81 | #endif 82 | //----------------------------------------------------------------------------- 83 | // 84 | // $Log:$ 85 | // 86 | //----------------------------------------------------------------------------- 87 | --------------------------------------------------------------------------------