Skip to content

Commit ce5342b

Browse files
committed
Merge branch 'upstream' into vt
2 parents edb7ac1 + 174efc6 commit ce5342b

File tree

7 files changed

+149
-40
lines changed

7 files changed

+149
-40
lines changed

msdos.cpp

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,30 @@ inline const char *my_strstr(const char *str, const char *search)
190190
{
191191
return (const char *)_mbsstr((const unsigned char *)(str), (const unsigned char *)(search));
192192
}
193+
inline char *my_strcasestr(char *str, const char *search)
194+
{
195+
int len1 = (int)_mbstrlen(str);
196+
int len2 = (int)_mbstrlen(search);
197+
198+
for(int pos = 0; pos < len1 - len2 + 1; pos++) {
199+
if(_mbsnicmp((unsigned char *)str + pos, (const unsigned char *)search, len2) == 0) {
200+
return str + pos;
201+
}
202+
}
203+
return NULL;
204+
}
205+
inline const char *my_strcasestr(const char *str, const char *search)
206+
{
207+
int len1 = (int)_mbstrlen(str);
208+
int len2 = (int)_mbstrlen(search);
209+
210+
for(int pos = 0; pos < len1 - len2 + 1; pos++) {
211+
if(_mbsnicmp((const unsigned char *)str + pos, (const unsigned char *)search, len2) == 0) {
212+
return str + pos;
213+
}
214+
}
215+
return NULL;
216+
}
193217
inline char *my_strtok(char *tok, const char *del)
194218
{
195219
return (char *)_mbstok((unsigned char *)(tok), (const unsigned char *)(del));
@@ -210,6 +234,7 @@ inline char *my_strupr(char *str)
210234
#define my_strchr(str, chr) strchr((str), (chr))
211235
#define my_strrchr(str, chr) strrchr((str), (chr))
212236
#define my_strstr(str, search) strstr((str), (search))
237+
#define my_strcasestr(str, search) strcasestr((str), (search))
213238
#define my_strtok(tok, del) strtok((tok), (del))
214239
#define my_strtok_s(tok, del, context) strtok_s((tok), (del), (context))
215240
#define my_strupr(str) _strupr((str))
@@ -7811,7 +7836,6 @@ int msdos_hma_mem_get_free(int *available_offset)
78117836

78127837
void msdos_env_set_argv(int env_seg, const char *argv)
78137838
{
7814-
int env_size = ((mcb_t *)(mem + ((env_seg - 1) << 4)))->paragraphs * 16;
78157839
char *env = (char *)(mem + (env_seg << 4));
78167840
char *dst = env;
78177841

@@ -7870,7 +7894,6 @@ const char *msdos_env_get(int env_seg, const char *name)
78707894

78717895
void msdos_env_set(int env_seg, const char *name, const char *value)
78727896
{
7873-
int env_size = ((mcb_t *)(mem + ((env_seg - 1) << 4)))->paragraphs * 16;
78747897
char *buf = (char *)malloc(env_size + 1);
78757898
char *src = buf;
78767899
char *env = (char *)(mem + (env_seg << 4));
@@ -9188,28 +9211,24 @@ int msdos_process_exec(const char *cmd, param_block_t *param, UINT8 al, bool fir
91889211
}
91899212

91909213
// copy environment
9191-
int parent_env_seg, parent_env_size;
91929214
int umb_linked, env_seg, psp_seg;
91939215

9194-
if(param->env_seg == 0) {
9195-
parent_env_seg = parent_psp->env_seg;
9196-
} else {
9197-
parent_env_seg = param->env_seg;
9198-
}
9199-
parent_env_size = ((mcb_t *)(mem + ((parent_env_seg - 1) << 4)))->paragraphs * 16;
9200-
92019216
if((umb_linked = msdos_mem_get_umb_linked()) != 0) {
92029217
msdos_mem_unlink_umb();
92039218
}
9204-
if((env_seg = msdos_mem_alloc(first_mcb, parent_env_size >> 4)) == -1) {
9205-
if((env_seg = msdos_mem_alloc(UMB_TOP >> 4, parent_env_size >> 4)) == -1) {
9219+
if((env_seg = msdos_mem_alloc(first_mcb, env_size >> 4)) == -1) {
9220+
if((env_seg = msdos_mem_alloc(UMB_TOP >> 4, env_size >> 4)) == -1) {
92069221
if(umb_linked != 0) {
92079222
msdos_mem_link_umb();
92089223
}
92099224
return(-1);
92109225
}
92119226
}
9212-
memcpy(mem + (env_seg << 4), mem + (parent_env_seg << 4), parent_env_size);
9227+
if(param->env_seg == 0) {
9228+
memcpy(mem + (env_seg << 4), mem + (parent_psp->env_seg << 4), env_size);
9229+
} else {
9230+
memcpy(mem + (env_seg << 4), mem + (param->env_seg << 4), env_size);
9231+
}
92139232
msdos_env_set_argv(env_seg, msdos_short_full_path(path));
92149233

92159234
// check exe header
@@ -22395,6 +22414,16 @@ int msdos_init(int argc, char *argv[], char *envp[], int standard_env)
2239522414
const char *path, *short_path;
2239622415
wchar_t wc_path[ENV_SIZE];
2239722416

22417+
env_size = standard_env ? 2048 : 8192;
22418+
22419+
if(argc > 1 && (_stricmp(argv[0], "COMMAND.COM") == 0 || _stricmp(argv[0], "COMMAND") == 0)) {
22420+
for(int i = 1; i < argc; i++) {
22421+
if(_strnicmp(argv[i], "/E:", 3) == 0) {
22422+
env_size = ((atoi(&argv[i][3]) + 15) >> 4) << 4;
22423+
env_size = max(160, min(32768, env_size));
22424+
}
22425+
}
22426+
}
2239822427
env_append[0] = env_msdos_path[0] = env_path[0] = env_temp[0] = '\0';
2239922428

2240022429
if(GetEnvironmentVariableW(L"MSDOS_APPEND", wc_path, ENV_SIZE) != 0) {
@@ -22545,13 +22574,21 @@ int msdos_init(int argc, char *argv[], char *envp[], int standard_env)
2254522574
} else {
2254622575
sprintf((char *)(mem + (env_seg << 4) + ofs), "%s=%s", name, value);
2254722576
}
22548-
ofs += (int)strlen((char *)(mem + (env_seg << 4) + ofs)) + 1;
22577+
int len = (int)strlen((char *)(mem + (env_seg << 4) + ofs));
22578+
if(ofs + len + 1 + (2 + (8 + 1 + 3)) + 2 > env_size) {
22579+
fatalerror("too many environments\n");
22580+
}
22581+
ofs += len + 1;
2254922582
}
2255022583
}
2255122584
if(!append_added && env_append[0] != '\0') {
2255222585
#define SET_ENV(name, value) { \
2255322586
sprintf((char *)(mem + (env_seg << 4) + ofs), "%s=%s", name, value); \
22554-
ofs += (int)strlen((char *)(mem + (env_seg << 4) + ofs)) + 1; \
22587+
int len = (int)strlen((char *)(mem + (env_seg << 4) + ofs)); \
22588+
if(ofs + len + 1 + (2 + (8 + 1 + 3)) + 2 > env_size) { \
22589+
fatalerror("too many environments\n"); \
22590+
} \
22591+
ofs += len + 1; \
2255522592
}
2255622593
SET_ENV("APPEND", env_append);
2255722594
}
@@ -22632,16 +22669,6 @@ int msdos_init(int argc, char *argv[], char *envp[], int standard_env)
2263222669
}
2263322670
SET_ENV("TZ", tz_value);
2263422671
}
22635-
int env_size = (ofs + 1) + (2 + MAX_PATH + 1);
22636-
env_size = ((env_size + 15) >> 4) << 4;
22637-
if(env_size > 32768) {
22638-
fatalerror("too many environment variables (size:%d max:32768)\nspecify -e option to load minimum environment variables\n", env_size);
22639-
}
22640-
if(standard_env) {
22641-
env_size = max(env_size + 128, 1024);
22642-
} else {
22643-
env_size = min(env_size + 512, 32768);
22644-
}
2264522672
msdos_mcb_create(seg++, 'M', PSP_SYSTEM, env_size >> 4);
2264622673
seg += (env_size >> 4);
2264722674

msdos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ UINT32 XMS_TOP = 0;
768768
#define XMS_SIZE 0x1c0 /* 18 + 6 + 413 + 7 */
769769

770770
#define ENV_SIZE 0x8000
771+
int env_size = 0x2000;
771772
#define PSP_SIZE 0x100
772773
#define PSP_SYSTEM 0x0008
773774

msdos_np21.vcproj

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,46 @@
10121012
/>
10131013
</FileConfiguration>
10141014
</File>
1015+
<File
1016+
RelativePath="np21_i386c\ia32\instructions\fpu\fpemul_dosbox.cpp"
1017+
>
1018+
<FileConfiguration
1019+
Name="Debug|Win32"
1020+
>
1021+
<Tool
1022+
Name="VCCLCompilerTool"
1023+
PreprocessorDefinitions=""
1024+
/>
1025+
</FileConfiguration>
1026+
<FileConfiguration
1027+
Name="Release|Win32"
1028+
>
1029+
<Tool
1030+
Name="VCCLCompilerTool"
1031+
PreprocessorDefinitions=""
1032+
/>
1033+
</FileConfiguration>
1034+
</File>
1035+
<File
1036+
RelativePath="np21_i386c\ia32\instructions\fpu\fpemul_dosbox2.cpp"
1037+
>
1038+
<FileConfiguration
1039+
Name="Debug|Win32"
1040+
>
1041+
<Tool
1042+
Name="VCCLCompilerTool"
1043+
PreprocessorDefinitions=""
1044+
/>
1045+
</FileConfiguration>
1046+
<FileConfiguration
1047+
Name="Release|Win32"
1048+
>
1049+
<Tool
1050+
Name="VCCLCompilerTool"
1051+
PreprocessorDefinitions=""
1052+
/>
1053+
</FileConfiguration>
1054+
</File>
10151055
<File
10161056
RelativePath="np21_i386c\ia32\instructions\fpu\fpemul_softfloat.cpp"
10171057
>

msdos_np21.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@
306306
<ClCompile Include="np21_i386c\ia32\instructions\string_inst.cpp" />
307307
<ClCompile Include="np21_i386c\ia32\instructions\system_inst.cpp" />
308308
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpdummy.cpp" />
309+
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpemul_dosbox.cpp" />
310+
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpemul_dosbox2.cpp" />
309311
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpemul_softfloat.cpp" />
310312
<ClCompile Include="np21_i386c\ia32\instructions\fpu\softfloat\softfloat.cpp" />
311313
<ClCompile Include="np21_i386c\ia32\instructions\mmx\3dnow.cpp" />

msdos_np21.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@
173173
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpdummy.cpp">
174174
<Filter>Source Files\np21w i386c Source Files\ia32\instructions\fpu</Filter>
175175
</ClCompile>
176+
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpemul_dosbox.cpp">
177+
<Filter>Source Files\np21w i386c Source Files\ia32\instructions\fpu</Filter>
178+
</ClCompile>
179+
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpemul_dosbox2.cpp">
180+
<Filter>Source Files\np21w i386c Source Files\ia32\instructions\fpu</Filter>
181+
</ClCompile>
176182
<ClCompile Include="np21_i386c\ia32\instructions\fpu\fpemul_softfloat.cpp">
177183
<Filter>Source Files\np21w i386c Source Files\ia32\instructions\fpu</Filter>
178184
</ClCompile>

np21_i386c/ia32/instructions/fpu/fpemul_softfloat.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,58 @@ static void FPU_FST_F80(UINT32 addr) {
234234

235235
static void FPU_FST_I16(UINT32 addr) {
236236
float_exception_flags = (FPU_STATUSWORD & 0x3f);
237+
#if 1
238+
// from mame i386 core
239+
floatx80 fx80 = floatx80_round_to_int(FPU_STAT.reg[FPU_STAT_TOP].d);
240+
floatx80 lowerLim = int32_to_floatx80(-32768);
241+
floatx80 upperLim = int32_to_floatx80(32767);
242+
if (!floatx80_lt(fx80, lowerLim) && floatx80_le(fx80, upperLim)) {
243+
fpu_memorywrite_w(addr, (UINT16)((SINT16)floatx80_to_int32(fx80)));
244+
} else {
245+
fpu_memorywrite_w(addr, (UINT16)((SINT16)-32768));
246+
float_exception_flags = float_flag_invalid;
247+
}
248+
#else
237249
fpu_memorywrite_w(addr, (UINT16)((SINT16)floatx80_to_int32(FPU_STAT.reg[FPU_STAT_TOP].d)));
250+
#endif
238251
FPU_STATUSWORD |= float_exception_flags;
239252
}
240253

241254
static void FPU_FST_I32(UINT32 addr) {
242255
float_exception_flags = (FPU_STATUSWORD & 0x3f);
256+
#if 1
257+
// from mame i386 core
258+
floatx80 fx80 = floatx80_round_to_int(FPU_STAT.reg[FPU_STAT_TOP].d);
259+
floatx80 lowerLim = int32_to_floatx80(0x80000000);
260+
floatx80 upperLim = int32_to_floatx80(0x7fffffff);
261+
if (!floatx80_lt(fx80, lowerLim) && floatx80_le(fx80, upperLim)) {
262+
fpu_memorywrite_d(addr, (UINT32)floatx80_to_int32(fx80));
263+
} else {
264+
fpu_memorywrite_d(addr, (UINT32)0x80000000);
265+
float_exception_flags = float_flag_invalid;
266+
}
267+
#else
243268
fpu_memorywrite_d(addr, (UINT32)floatx80_to_int32(FPU_STAT.reg[FPU_STAT_TOP].d));
269+
#endif
244270
FPU_STATUSWORD |= float_exception_flags;
245271
}
246272

247273
static void FPU_FST_I64(UINT32 addr) {
248274
float_exception_flags = (FPU_STATUSWORD & 0x3f);
275+
#if 1
276+
// from mame i386 core
277+
floatx80 fx80 = floatx80_round_to_int(FPU_STAT.reg[FPU_STAT_TOP].d);
278+
floatx80 lowerLim = int64_to_floatx80((UINT64)0x8000000000000000);
279+
floatx80 upperLim = int64_to_floatx80((UINT64)0x7fffffffffffffff);
280+
if (!floatx80_lt(fx80, lowerLim) && floatx80_le(fx80, upperLim)) {
281+
fpu_memorywrite_q(addr, (UINT64)floatx80_to_int64(fx80));
282+
} else {
283+
fpu_memorywrite_q(addr, (UINT64)0x8000000000000000);
284+
float_exception_flags = float_flag_invalid;
285+
}
286+
#else
249287
fpu_memorywrite_q(addr, (UINT64)floatx80_to_int64(FPU_STAT.reg[FPU_STAT_TOP].d));
288+
#endif
250289
FPU_STATUSWORD |= float_exception_flags;
251290
}
252291

@@ -443,6 +482,7 @@ static void FPU_FMUL(UINT st, UINT other) {
443482
static void FPU_FSUB(UINT st, UINT other) {
444483
float_exception_flags = (FPU_STATUSWORD & 0x3f);
445484
FPU_STAT.reg[st].d = floatx80_sub(FPU_STAT.reg[st].d, FPU_STAT.reg[other].d);
485+
FPU_STATUSWORD |= float_exception_flags;
446486
return;
447487
}
448488
static void FPU_FSUBR(UINT st, UINT other) {

np21_i386c/ia32/interface.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,15 @@ ia32(void)
152152
exec_allstep();
153153
}else
154154
*/
155-
#ifdef USE_CLOCK
156155
if (!CPU_TRAP) {
157-
do {
156+
//do {
158157
exec_1step();
159158
#ifdef USE_DMA
160159
dmax86();
161160
#endif
162-
} while (CPU_REMCLOCK > 0);
161+
//} while (CPU_REMCLOCK > 0);
163162
}else{
164-
do {
165-
#endif
163+
//do {
166164
exec_1step();
167165
if (CPU_TRAP) {
168166
CPU_DR6 |= CPU_DR6_BS;
@@ -171,10 +169,8 @@ ia32(void)
171169
#ifdef USE_DMA
172170
dmax86();
173171
#endif
174-
#ifdef USE_CLOCK
175-
} while (CPU_REMCLOCK > 0);
172+
//} while (CPU_REMCLOCK > 0);
176173
}
177-
#endif
178174
#ifdef __cplusplus
179175
} catch (int e) {
180176
switch (e) {
@@ -221,11 +217,10 @@ ia32_step(void)
221217
break;
222218
}
223219
#endif
224-
#ifdef USE_CLOCK
225-
do {
226-
#endif
220+
//do {
221+
UINT8 old_TRAP = CPU_TRAP;
227222
exec_1step();
228-
if (CPU_TRAP) {
223+
if (CPU_TRAP && old_TRAP) {
229224
CPU_DR6 |= CPU_DR6_BS;
230225
INTERRUPT(1, INTR_TYPE_EXCEPTION);
231226
}
@@ -234,9 +229,7 @@ ia32_step(void)
234229
dmax86();
235230
//}
236231
#endif
237-
#ifdef USE_CLOCK
238-
} while (CPU_REMCLOCK > 0);
239-
#endif
232+
//} while (CPU_REMCLOCK > 0);
240233
#ifdef __cplusplus
241234
} catch (int e) {
242235
switch (e) {

0 commit comments

Comments
 (0)