summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/wad.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-02-11 15:34:30 -0500
committerFranklin Wei <git@fwei.tk>2019-07-19 22:37:40 -0400
commit5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4 (patch)
tree84406e21639529a185556a33e5de7f43cffc277b /apps/plugins/sdl/progs/quake/wad.c
parentb70fecf21ddc21877ec1ae7888d9c18a979e37ad (diff)
downloadrockbox-5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4.tar.gz
rockbox-5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4.zip
Quake!
This ports id Software's Quake to run on the SDL plugin runtime. The source code originated from id under the GPLv2 license. I used https://github.com/ahefner/sdlquake as the base of my port. Performance is, unsurprisingly, not on par with what you're probably used to on PC. I average about 10FPS on ipod6g, but it's still playable. Sound works well enough, but in-game music is not supported. I've written ARM assembly routines for the inner sound loop. Make sure you turn the "brightness" all the way down, or colors will look funky. To run, extract Quake's data files to /.rockbox/quake. Have fun! Change-Id: I4285036e967d7f0722802d43cf2096c808ca5799
Diffstat (limited to 'apps/plugins/sdl/progs/quake/wad.c')
-rw-r--r--apps/plugins/sdl/progs/quake/wad.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/quake/wad.c b/apps/plugins/sdl/progs/quake/wad.c
new file mode 100644
index 0000000000..c84f72c6d5
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/wad.c
@@ -0,0 +1,158 @@
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// wad.c
21
22#include "quakedef.h"
23
24int wad_numlumps;
25lumpinfo_t *wad_lumps;
26byte *wad_base;
27
28void SwapPic (qpic_t *pic);
29
30/*
31==================
32W_CleanupName
33
34Lowercases name and pads with spaces and a terminating 0 to the length of
35lumpinfo_t->name.
36Used so lumpname lookups can proceed rapidly by comparing 4 chars at a time
37Space padding is so names can be printed nicely in tables.
38Can safely be performed in place.
39==================
40*/
41void W_CleanupName (char *in, char *out)
42{
43 int i;
44 int c;
45
46 for (i=0 ; i<16 ; i++ )
47 {
48 c = in[i];
49 if (!c)
50 break;
51
52 if (c >= 'A' && c <= 'Z')
53 c += ('a' - 'A');
54 out[i] = c;
55 }
56
57 for ( ; i< 16 ; i++ )
58 out[i] = 0;
59}
60
61
62
63/*
64====================
65W_LoadWadFile
66====================
67*/
68void W_LoadWadFile (char *filename)
69{
70 lumpinfo_t *lump_p;
71 wadinfo_t *header;
72 unsigned i;
73 int infotableofs;
74
75 wad_base = COM_LoadHunkFile (filename);
76 if (!wad_base)
77 Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
78
79 header = (wadinfo_t *)wad_base;
80
81 if (header->identification[0] != 'W'
82 || header->identification[1] != 'A'
83 || header->identification[2] != 'D'
84 || header->identification[3] != '2')
85 Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
86
87 wad_numlumps = LittleLong(header->numlumps);
88 infotableofs = LittleLong(header->infotableofs);
89 wad_lumps = (lumpinfo_t *)(wad_base + infotableofs);
90
91 for (i=0, lump_p = wad_lumps ; i<wad_numlumps ; i++,lump_p++)
92 {
93 lump_p->filepos = LittleLong(lump_p->filepos);
94 lump_p->size = LittleLong(lump_p->size);
95 W_CleanupName (lump_p->name, lump_p->name);
96 if (lump_p->type == TYP_QPIC)
97 SwapPic ( (qpic_t *)(wad_base + lump_p->filepos));
98 }
99}
100
101
102/*
103=============
104W_GetLumpinfo
105=============
106*/
107lumpinfo_t *W_GetLumpinfo (char *name)
108{
109 int i;
110 lumpinfo_t *lump_p;
111 char clean[16];
112
113 W_CleanupName (name, clean);
114
115 for (lump_p=wad_lumps, i=0 ; i<wad_numlumps ; i++,lump_p++)
116 {
117 if (!strcmp(clean, lump_p->name))
118 return lump_p;
119 }
120
121 Sys_Error ("W_GetLumpinfo: %s not found", name);
122 return NULL;
123}
124
125void *W_GetLumpName (char *name)
126{
127 lumpinfo_t *lump;
128
129 lump = W_GetLumpinfo (name);
130
131 return (void *)(wad_base + lump->filepos);
132}
133
134void *W_GetLumpNum (int num)
135{
136 lumpinfo_t *lump;
137
138 if (num < 0 || num > wad_numlumps)
139 Sys_Error ("W_GetLumpNum: bad number: %i", num);
140
141 lump = wad_lumps + num;
142
143 return (void *)(wad_base + lump->filepos);
144}
145
146/*
147=============================================================================
148
149automatic byte swapping
150
151=============================================================================
152*/
153
154void SwapPic (qpic_t *pic)
155{
156 pic->width = LittleLong(pic->width);
157 pic->height = LittleLong(pic->height);
158}