summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2007-06-03 22:03:36 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2007-06-03 22:03:36 +0000
commitaec5814d436f6307dc3e6a1a09aa1ffec5709c27 (patch)
tree9d553317483ec7ef53dca7db931bd9f99ca7a5b8
parent7428b79de328dca03274ccfe08d59636eb6f8d51 (diff)
downloadrockbox-aec5814d436f6307dc3e6a1a09aa1ffec5709c27.tar.gz
rockbox-aec5814d436f6307dc3e6a1a09aa1ffec5709c27.zip
Some fixes to doom dehacked loading - make embedded dehacked files actually load, fix end of file detection in the string loader, fix ammo changes, fix bex code pointers. Also added the * flag to sscanf - still only tested against rockdoom sscanf calls.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13547 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/doom/d_deh.c9
-rw-r--r--apps/plugins/doom/d_main.c4
-rw-r--r--apps/plugins/doom/rockdoom.c2
-rw-r--r--firmware/common/sscanf.c74
4 files changed, 63 insertions, 26 deletions
diff --git a/apps/plugins/doom/d_deh.c b/apps/plugins/doom/d_deh.c
index c1e136f467..d3f7496885 100644
--- a/apps/plugins/doom/d_deh.c
+++ b/apps/plugins/doom/d_deh.c
@@ -85,7 +85,7 @@ char *dehfgets(char *buf, size_t n, DEHFILE *fp)
85 85
86 p = buf; 86 p = buf;
87 87
88 while (--n > 0) 88 while (n-- > 0)
89 { 89 {
90 unsigned char c = *fp->inp++; 90 unsigned char c = *fp->inp++;
91 fp->size--; 91 fp->size--;
@@ -111,7 +111,7 @@ int dehfeof(DEHFILE *fp)
111 return (size <= 0 || offset < 0 || offset >= size) ? 1 : 0; 111 return (size <= 0 || offset < 0 || offset >= size) ? 1 : 0;
112 } 112 }
113 113
114 return (fp->size == 0 || *fp->inp == '\0') ? 1 : 0; 114 return (fp->size <= 0 || *fp->inp == '\0') ? 1 : 0;
115} 115}
116 116
117int dehfgetc(DEHFILE *fp) 117int dehfgetc(DEHFILE *fp)
@@ -1509,6 +1509,7 @@ void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum)
1509 int size = W_LumpLength(lumpnum); 1509 int size = W_LumpLength(lumpnum);
1510 infile.size = (size < 0) ? 0 : (ssize_t)size; 1510 infile.size = (size < 0) ? 0 : (ssize_t)size;
1511 infile.inp = W_CacheLumpNum(lumpnum); 1511 infile.inp = W_CacheLumpNum(lumpnum);
1512 infile.fd=-1;
1512 filename = "(WAD)"; 1513 filename = "(WAD)";
1513 } 1514 }
1514 1515
@@ -1983,7 +1984,7 @@ void deh_procPointer(DEHFILE *fpin, int fpout, char *line) // done
1983 // NOTE: different format from normal 1984 // NOTE: different format from normal
1984 1985
1985 // killough 8/98: allow hex numbers in input, fix error case: 1986 // killough 8/98: allow hex numbers in input, fix error case:
1986 if (sscanf(inbuffer,"%*s %*i (%s %i)",key, &indexnum) != 2) 1987 if (sscanf(inbuffer,"%*s %*d (%s %d)",key, &indexnum) != 2)
1987 { 1988 {
1988 if (fpout) fdprintf(fpout,"Bad data pair in '%s'\n",inbuffer); 1989 if (fpout) fdprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
1989 return; 1990 return;
@@ -2122,7 +2123,7 @@ void deh_procAmmo(DEHFILE *fpin, int fpout, char *line)
2122 strncpy(inbuffer,line,DEH_BUFFERMAX); 2123 strncpy(inbuffer,line,DEH_BUFFERMAX);
2123 2124
2124 // killough 8/98: allow hex numbers in input: 2125 // killough 8/98: allow hex numbers in input:
2125 sscanf(inbuffer,"%s %i",key, &indexnum); 2126 sscanf(inbuffer,"%s %d",key, &indexnum);
2126 if (fpout) fdprintf(fpout,"Processing Ammo at index %d: %s\n", 2127 if (fpout) fdprintf(fpout,"Processing Ammo at index %d: %s\n",
2127 indexnum, key); 2128 indexnum, key);
2128 if (indexnum < 0 || indexnum >= NUMAMMO) 2129 if (indexnum < 0 || indexnum >= NUMAMMO)
diff --git a/apps/plugins/doom/d_main.c b/apps/plugins/doom/d_main.c
index 3dc64875fd..32e3809dee 100644
--- a/apps/plugins/doom/d_main.c
+++ b/apps/plugins/doom/d_main.c
@@ -82,7 +82,7 @@ boolean clfastparm; // checkparm of -fast
82boolean nomonsters; // working -nomonsters 82boolean nomonsters; // working -nomonsters
83boolean respawnparm; // working -respawn 83boolean respawnparm; // working -respawn
84boolean fastparm; // working -fast 84boolean fastparm; // working -fast
85boolean dehout=false; 85boolean dehout=true;
86 86
87boolean singletics = false; // debug flag to cancel adaptiveness 87boolean singletics = false; // debug flag to cancel adaptiveness
88 88
@@ -731,7 +731,7 @@ void D_DoomMainSetup(void)
731 W_Init(); 731 W_Init();
732 732
733 if ((p = W_CheckNumForName("DEHACKED")) != -1) // cph - add dehacked-in-a-wad support 733 if ((p = W_CheckNumForName("DEHACKED")) != -1) // cph - add dehacked-in-a-wad support
734 ProcessDehFile(NULL, dehout ? NULL : "/dehlog.txt", p); 734 ProcessDehFile(NULL, dehout ? "/dehlog.txt" : NULL, p);
735 735
736 V_InitColorTranslation(); //jff 4/24/98 load color translation lumps 736 V_InitColorTranslation(); //jff 4/24/98 load color translation lumps
737 737
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c
index 82daadb24e..90c446b9eb 100644
--- a/apps/plugins/doom/rockdoom.c
+++ b/apps/plugins/doom/rockdoom.c
@@ -103,6 +103,7 @@ struct plugin_api* rb;
103 103
104bool noprintf=0; // Variable disables printf lcd updates to protect grayscale lib/direct lcd updates 104bool noprintf=0; // Variable disables printf lcd updates to protect grayscale lib/direct lcd updates
105 105
106#ifndef SIMULATOR
106// Here is a hacked up printf command to get the output from the game. 107// Here is a hacked up printf command to get the output from the game.
107int printf(const char *fmt, ...) 108int printf(const char *fmt, ...)
108{ 109{
@@ -129,6 +130,7 @@ int printf(const char *fmt, ...)
129 } 130 }
130 return 1; 131 return 1;
131} 132}
133#endif
132 134
133char *my_strtok( char * s, const char * delim ) 135char *my_strtok( char * s, const char * delim )
134{ 136{
diff --git a/firmware/common/sscanf.c b/firmware/common/sscanf.c
index 66bf0dd354..5fbe81f3e0 100644
--- a/firmware/common/sscanf.c
+++ b/firmware/common/sscanf.c
@@ -27,7 +27,7 @@ static int parse_dec(int (*peek)(void *userp),
27 int n = 0; 27 int n = 0;
28 int minus = 0; 28 int minus = 0;
29 char ch; 29 char ch;
30 30
31 if ((*peek)(userp) == '-') 31 if ((*peek)(userp) == '-')
32 { 32 {
33 (*pop)(userp); 33 (*pop)(userp);
@@ -54,19 +54,24 @@ static int parse_dec(int (*peek)(void *userp),
54static int parse_chars(int (*peek)(void *userp), 54static int parse_chars(int (*peek)(void *userp),
55 void (*pop)(void *userp), 55 void (*pop)(void *userp),
56 void *userp, 56 void *userp,
57 char *vp) 57 char *vp,
58 bool fake)
58{ 59{
59 int n = 0; 60 int n = 0;
61
60 char *pt=vp; 62 char *pt=vp;
61 63
62 while (!isspace((*peek)(userp))) 64 while (!isspace((*peek)(userp)))
63 { 65 {
64 *(pt++) = (*peek)(userp); 66 if(fake==false)
67 *(pt++) = (*peek)(userp);
68
65 n++; 69 n++;
66 (*pop)(userp); 70 (*pop)(userp);
67 } 71 }
68 72
69 (*pt)='\0'; 73 if(fake==false)
74 (*pt)='\0';
70 75
71 return n; 76 return n;
72} 77}
@@ -125,24 +130,38 @@ static int scan(int (*peek)(void *userp),
125 int n_chars = 0; 130 int n_chars = 0;
126 int r; 131 int r;
127 long lval; 132 long lval;
133 bool skip=false;
128 unsigned long ulval; 134 unsigned long ulval;
129 135
130 while ((ch = *fmt++) != '\0') 136 while ((ch = *fmt++) != '\0')
131 { 137 {
132 bool literal = false; 138 bool literal = false;
133 139
134 if (ch == '%') 140 if (ch == '%')
135 { 141 {
136 ch = *fmt++; 142 ch = *fmt++;
137 143
144 if(ch== '*') /* We should process this, but not store it in an arguement */
145 {
146 ch=*fmt++;
147 skip=true;
148 }
149 else
150 {
151 skip=false;
152 }
153
138 switch (ch) 154 switch (ch)
139 { 155 {
140 case 'x': 156 case 'x':
141 n_chars += skip_spaces(peek, pop, userp); 157 n_chars += skip_spaces(peek, pop, userp);
142 if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) 158 if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0)
143 { 159 {
144 *(va_arg(ap, unsigned int *)) = ulval; 160 if(skip==false)
145 n++; 161 {
162 *(va_arg(ap, unsigned int *)) = ulval;
163 n++;
164 }
146 n_chars += r; 165 n_chars += r;
147 } 166 }
148 else 167 else
@@ -152,16 +171,22 @@ static int scan(int (*peek)(void *userp),
152 n_chars += skip_spaces(peek, pop, userp); 171 n_chars += skip_spaces(peek, pop, userp);
153 if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) 172 if ((r = parse_dec(peek, pop, userp, &lval)) >= 0)
154 { 173 {
155 *(va_arg(ap, int *)) = lval; 174 if(skip==false)
156 n++; 175 {
176 *(va_arg(ap, int *)) = lval;
177 n++;
178 }
157 n_chars += r; 179 n_chars += r;
158 } 180 }
159 else 181 else
160 return n; 182 return n;
161 break; 183 break;
162 case 'n': 184 case 'n':
163 *(va_arg(ap, int *)) = n_chars; 185 if(skip==false)
164 n++; 186 {
187 *(va_arg(ap, int *)) = n_chars;
188 n++;
189 }
165 break; 190 break;
166 case 'l': 191 case 'l':
167 n_chars += skip_spaces(peek, pop, userp); 192 n_chars += skip_spaces(peek, pop, userp);
@@ -171,8 +196,11 @@ static int scan(int (*peek)(void *userp),
171 case 'x': 196 case 'x':
172 if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) 197 if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0)
173 { 198 {
174 *(va_arg(ap, unsigned long *)) = ulval; 199 if(skip==false)
175 n++; 200 {
201 *(va_arg(ap, unsigned long *)) = ulval;
202 n++;
203 }
176 n_chars += r; 204 n_chars += r;
177 } 205 }
178 else 206 else
@@ -181,8 +209,11 @@ static int scan(int (*peek)(void *userp),
181 case 'd': 209 case 'd':
182 if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) 210 if ((r = parse_dec(peek, pop, userp, &lval)) >= 0)
183 { 211 {
184 *(va_arg(ap, long *)) = lval; 212 if(skip==false)
185 n++; 213 {
214 *(va_arg(ap, long *)) = lval;
215 n++;
216 }
186 n_chars += r; 217 n_chars += r;
187 } 218 }
188 else 219 else
@@ -195,10 +226,13 @@ static int scan(int (*peek)(void *userp),
195 break; 226 break;
196 } 227 }
197 break; 228 break;
198 case 's': 229 case 's':
199 n_chars += skip_spaces(peek, pop, userp); 230 n_chars += skip_spaces(peek, pop, userp);
200 n_chars += parse_chars(peek,pop, userp,va_arg(ap, char *) ); 231 n_chars += parse_chars(peek,pop, userp,skip?0:va_arg(ap, char *), skip );
201 n++; 232 if(skip==false)
233 {
234 n++;
235 }
202 break; 236 break;
203 case '\0': 237 case '\0':
204 return n; 238 return n;
@@ -239,7 +273,7 @@ int sscanf(const char *s, const char *fmt, ...)
239 int r; 273 int r;
240 va_list ap; 274 va_list ap;
241 const char *p; 275 const char *p;
242 276
243 p = s; 277 p = s;
244 va_start(ap, fmt); 278 va_start(ap, fmt);
245 r = scan(sspeek, sspop, &p, fmt, ap); 279 r = scan(sspeek, sspop, &p, fmt, ap);