1
0
Fork 0

First CVS upload.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@80
This commit is contained in:
Sjoerd van der Berg 2002-07-27 13:08:48 +00:00
parent 7d1ca9bdd4
commit 42e5d0b779
158 changed files with 42940 additions and 0 deletions

4
src/misc/Makefile.am Normal file
View file

@ -0,0 +1,4 @@
AM_CPPFLAGS = -I$(top_srcdir)/include
noinst_LIBRARIES = libmisc.a
libmisc_a_SOURCES = plugins.cpp programs.cpp messages.cpp support.cpp setup.cpp

107
src/misc/messages.cpp Normal file
View file

@ -0,0 +1,107 @@
/*
* Copyright (C) 2002 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dosbox.h"
#include "cross.h"
#include "support.h"
#include "setup.h"
#define LINE_IN_MAXLEN 1024
struct MessageBlock
{
char * name;
char * string;
MessageBlock * next;
};
static MessageBlock * first_message;
static void LoadMessageFile(char * fname) {
FILE * mfile=fopen(fname,"rb");
/* This should never happen and since other modules depend on this use a normal printf */
if (!mfile) {
E_Exit("MSG:Can't load messages",fname);
}
char linein[LINE_IN_MAXLEN];
char name[LINE_IN_MAXLEN];
char string[LINE_IN_MAXLEN*10];
/* Start out with empty strings */
name[0]=0;string[0]=0;
while(fgets(linein, LINE_IN_MAXLEN, mfile)!=0) {
/* Parse the read line */
/* First remove characters 10 and 13 from the line */
char * parser=linein;
char * writer=linein;
while (*parser) {
if (*parser!=10 && *parser!=13) {
*writer++=*parser;
}
*parser++;
}
*writer=0;
/* New string name */
if (linein[0]==':') {
string[0]=0;
strcpy(name,linein+1);
/* End of string marker */
} else if (linein[0]=='.') {
/* Save the string internally */
size_t total=sizeof(MessageBlock)+strlen(name)+1+strlen(string)+1;
MessageBlock * newblock=(MessageBlock *)malloc(total);
newblock->name=((char *)newblock)+sizeof(MessageBlock);
newblock->string=newblock->name+strlen(name)+1;
strcpy(newblock->name,name);
strcpy(newblock->string,string);
newblock->next=first_message;
first_message=newblock;
} else {
/* Normal string to be added */
strcat(string,linein);
strcat(string,"\n");
}
}
fclose(mfile);
}
char * MSG_Get(char * msg) {
MessageBlock * index=first_message;
while (index) {
if (!strcmp(msg,index->name)) return index->string;
index=index->next;
}
return "Message not found";
}
void MSG_Init(void) {
/* Load the messages from "dosbox.lang file" */
first_message=0;
char filein[CROSS_LEN];
strcpy(filein,dosbox_basedir);
strcat(filein,"dosbox.lang");
LoadMessageFile(filein);
}

159
src/misc/plugins.cpp Normal file
View file

@ -0,0 +1,159 @@
/*
* Copyright (C) 2002 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include <stdlib.h>
#ifdef WIN32
#include <windows.h>
#endif
#include "dosbox.h"
#include "regs.h"
#include "mem.h"
#include "inout.h"
#include "pic.h"
#include "modules.h"
#include "programs.h"
#include "timer.h"
#include "dma.h"
#include "mixer.h"
struct PLUGIN_Function {
char * name;
void * function;
};
struct PLUGIN_Module {
#ifdef WIN32
HINSTANCE handle;
#endif
PLUGIN_Module * next;
};
static PLUGIN_Function functions[]={
"IO_RegisterReadHandler", (void *)IO_RegisterReadHandler,
"IO_RegisterWriteHandler", (void *)IO_RegisterWriteHandler,
"IO_FreeReadHandler", (void *)IO_FreeReadHandler,
"IO_FreeWriteHandler", (void *)IO_FreeWriteHandler,
"IRQ_RegisterEOIHandler", (void *)PIC_RegisterIRQ,
"IRQ_FreeEOIHandler", (void *)PIC_FreeIRQ,
"IRQ_Activate", (void *)PIC_ActivateIRQ,
"IRQ_Deactivate", (void *)PIC_DeActivateIRQ,
"TIMER_RegisterMicroHandler", (void *)TIMER_RegisterMicroHandler,
"TIMER_RegisterTickHandler", (void *)TIMER_RegisterTickHandler,
"DMA_8_Read", (void *)DMA_8_Read,
"DMA_16_Read", (void *)DMA_16_Read,
"DMA_8_Write", (void *)DMA_8_Write,
"DMA_16_Write", (void *)DMA_16_Write,
"MIXER_AddChannel", (void *)MIXER_AddChannel,
"MIXER_SetVolume", (void *)MIXER_SetVolume,
"MIXER_SetFreq", (void *)MIXER_SetFreq,
"MIXER_SetMode", (void *)MIXER_SetMode,
"MIXER_Enable", (void *)MIXER_Enable,
0,0
};
class PLUGIN : public Program {
public:
PLUGIN(PROGRAM_Info * program_info);
void Run(void);
};
PLUGIN::PLUGIN(PROGRAM_Info * info):Program(info) {
}
void PLUGIN::Run(void) {
}
static void PLUGIN_ProgramStart(PROGRAM_Info * info) {
PLUGIN * tempPLUGIN=new PLUGIN(info);
tempPLUGIN->Run();
delete tempPLUGIN;
}
bool PLUGIN_FindFunction(char * name,void * * function) {
/* Run through table and hope to find a match */
Bitu index=0;
while (functions[index].name) {
if (strcmp(functions[index].name,name)==0) {
*function=functions[index].function;
return true;
};
index++;
}
return false;
}
bool PLUGIN_LoadModule(char * name) {
MODULE_StartHandler starter;
#ifdef WIN32
HMODULE module;
module=LoadLibrary(name);
if (!module) return false;
/* Look for the module start functions */
FARPROC address;
address=GetProcAddress(module,MODULE_START_PROC);
starter=(MODULE_StartHandler)address;
#else
//TODO LINUX
#endif
starter(PLUGIN_FindFunction);
return false;
}
void PLUGIN_Init(void) {
PROGRAMS_MakeFile("PLUGIN.COM",PLUGIN_ProgramStart);
// PLUGIN_LoadModule("c:\\dosbox\\testmod.dll");
};

174
src/misc/programs.cpp Normal file
View file

@ -0,0 +1,174 @@
/*
* Copyright (C) 2002 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "programs.h"
#include "callback.h"
#include "regs.h"
#include "support.h"
#include "cross.h"
Bitu call_program;
/* This registers a file on the virtual drive and creates the correct structure for it*/
static Bit8u exe_block[]={
0xbc,0x00,0x03, //MOV SP,0x300 decrease stack size
0xbb,0x30,0x00, //MOV BX,0x030 for memory resize
0xb4,0x4a, //MOV AH,0x4A Resize memory block
0xcd,0x21, //INT 0x21
//pos 12 is callback number
0xFE,0x38,0x00,0x00, //CALLBack number
0xb8,0x00,0x4c, //Mov ax,4c00
0xcd,0x21, //INT 0x21
};
#define CB_POS 12
void PROGRAMS_MakeFile(char * name,PROGRAMS_Main * main) {
Bit8u * comdata=(Bit8u *)malloc(128);
memcpy(comdata,&exe_block,sizeof(exe_block));
comdata[CB_POS]=call_program&0xff;
comdata[CB_POS+1]=(call_program>>8)&0xff;
/* Copy the pointer this should preserve endianes */
memcpy(&comdata[sizeof(exe_block)],&main,sizeof(main));
Bit32u size=sizeof(exe_block)+sizeof(main);
VFILE_Register(name,comdata,size);
}
static Bitu PROGRAMS_Handler(void) {
/* This sets up everything for a program start up call */
/* First get the current psp */
PROGRAM_Info * info=new PROGRAM_Info;
info->psp_seg=dos.psp;
MEM_BlockRead(real_phys(dos.psp,0),&info->psp_copy,sizeof(PSP));
/* Get the file name cmd_line 0 */
PhysPt envblock=real_phys(info->psp_copy.environment,0);
do {} while (mem_readw(envblock++));
envblock+=3;
MEM_StrCopy(envblock,info->full_name,32);
info->psp_copy.cmdtail.buffer[info->psp_copy.cmdtail.count]=0;
info->cmd_line=info->psp_copy.cmdtail.buffer;
/* Find the program handler somewhere reference in the file */
Bit16u handle;
DOS_OpenFile(info->full_name,0,&handle);
Bit32u pos=sizeof(PROGRAMS_Main *);
DOS_SeekFile(handle,&pos,DOS_SEEK_END);
PROGRAMS_Main * handler;
Bit16u size=sizeof(PROGRAMS_Main *);
DOS_ReadFile(handle,(Bit8u *)&handler,&size);
DOS_CloseFile(handle);
(*handler)(info);
free(info);
return CBRET_NONE;
};
/* Main functions used in all program */
Program::Program(PROGRAM_Info * program_info) {
prog_info=program_info;
}
void Program::WriteOut(char * format,...) {
char buf[1024];
va_list msg;
va_start(msg,format);
vsprintf(buf,format,msg);
va_end(msg);
Bit16u size=strlen(buf);
DOS_WriteFile(STDOUT,(Bit8u *)buf,&size);
}
char * Program::GetEnvStr(char * env_str) {
/* Walk through the internal environment and see for a match */
/* Taking some short cuts here to not fuck around with memory structure */
char * envstart=(char *)real_host(prog_info->psp_copy.environment,0);
size_t len=strlen(env_str);
while (*envstart) {
if (strncasecmp(env_str,envstart,len)==0 && envstart[len]=='=') {
return envstart;
}
envstart+=strlen(envstart)+1;
}
return 0;
};
char * Program::GetEnvNum(Bit32u num) {
char * envstart=(char *)real_host(prog_info->psp_copy.environment,0);
while (*envstart) {
if (!num) return envstart;
envstart+=strlen(envstart)+1;
num--;
}
return 0;
}
Bit32u Program::GetEnvCount(void) {
char * envstart=(char *)real_host(prog_info->psp_copy.environment,0);
Bit32u num=0;
while (*envstart) {
envstart+=strlen(envstart)+1;
num++;
}
return num;
}
bool Program::SetEnv(char * env_entry,char * new_string) {
MCB * env_mcb=(MCB *)real_host(prog_info->psp_copy.environment-1,0);
upcase(env_entry);
Bit32u env_size=env_mcb->size*16;
if (!env_size) E_Exit("SHELL:Illegal environment size");
/* First try to find the old entry */
size_t len=strlen(env_entry);
char * envstart=(char *)real_host(prog_info->psp_copy.environment,0);
while (*envstart) {
if (strncasecmp(env_entry,envstart,len)==0 && envstart[len]=='=') {
/* Now remove this entry */
memmove(envstart,envstart+strlen(envstart)+1,env_size);
} else {
envstart+=strlen(envstart)+1;
env_size-=(strlen(envstart)+1);
}
}
/* Now add the string if there is space available */
if (env_size<(strlen(env_entry)+strlen(new_string)+2)) return false;
if (!*new_string) return true;
sprintf(envstart,"%s=%s",env_entry,new_string);
envstart+=strlen(envstart)+1;
*envstart++=0;*envstart++=0;*envstart++=0;
return true;
}
//TODO Hash table :)
void PROGRAMS_Init(void) {
/* Setup a special callback to start virtual programs */
call_program=CALLBACK_Allocate();
CALLBACK_Setup(call_program,&PROGRAMS_Handler,CB_RETF);
}

29
src/misc/setup.cpp Normal file
View file

@ -0,0 +1,29 @@
/*
* Copyright (C) 2002 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "dosbox.h"
#include "cross.h"
#include "setup.h"
void SETUP_AddBoolHandler() {
};

224
src/misc/support.cpp Normal file
View file

@ -0,0 +1,224 @@
/*
* Copyright (C) 2002 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dosbox.h"
#include "support.h"
/*
Ripped some source from freedos for this one.
*/
/*
* replaces all instances of character o with character c
*/
void strreplace(char * str,char o,char n) {
while (*str) {
if (*str==o) *str=n;
str++;
}
}
/*
* Name: ltrim() - left trims a string by removing leading spaces
* Input: str - a pointer to a string
* Output: returns a trimmed copy of str
*/
char *ltrim(char *str) {
char c;
assert(str);
while ((c = *str++) != '\0' && isspace(c));
return str - 1;
}
/*
* Name: rtrim() - right trims a string by removing trailing spaces
* Input: str - a pointer to a string
* Output: str will have all spaces removed from the right.
*/
void rtrim(char * const str) {
char *p;
assert(str);
p = strchr(str, '\0');
while (--p >= str && isspace(*p));
p[1] = '\0';
}
/*
* Combines ltrim() & rtrim()
*/
char *trim(char *str) {
assert(str);
rtrim(str);
return ltrim(str);
}
bool wildcmp(char *wild, char *string) {
char *cp, *mp;
while ((*string) && (*wild != '*')) {
if ((*wild != *string) && (*wild != '?')) {
return false;
}
wild++;
string++;
}
while (*string) {
if (*wild == '*') {
if (!*++wild) {
return true;
}
mp = wild;
cp = string+1;
} else if ((*wild == *string) || (*wild == '?')) {
wild++;
string++;
} else {
wild = mp;
string = cp++;
}
}
while (*wild == '*') {
wild++;
}
return !*wild;
}
bool ScanCMDBool(char * cmd,char * check) {
char * scan=cmd;size_t c_len=strlen(check);
while (scan=strchr(scan,'/')) {
/* found a / now see behind it */
scan++;
if (strncasecmp(scan,check,c_len)==0 && (scan[c_len]==' ' || scan[c_len]==0)) {
/* Found a math now remove it from the string */
memmove(scan-1,scan+c_len,strlen(scan+c_len)+1);
trim(scan-1);
return true;
}
}
return false;
}
bool ScanCMDHex(char * cmd,char * check,Bits * result) {
char * scan=cmd;size_t c_len=strlen(check);
while (scan=strchr(scan,'/')) {
/* found a / now see behind it */
scan++;
if (strncasecmp(scan,check,c_len)==0 && (scan[c_len]==' ' || scan[c_len]==0)) {
/* Found a match now find the number and remove it from the string */
char * begin=scan-1;
scan=ltrim(scan+c_len);
bool res=true;
*result=-1;
if (!sscanf(scan,"%X",result)) res=false;
scan=strrchr(scan,'/');
if (scan) memmove(begin,scan,strlen(scan)+1);
else *begin=0;
trim(begin);
return res;
}
}
return false;
}
/* This scans the command line for a remaining switch and reports it else returns 0*/
char * ScanCMDRemain(char * cmd) {
char * scan,*found;;
if (scan=found=strchr(cmd,'/')) {
while (*scan!=' ' && *scan!=0) scan++;
*scan=0;
return found;
} else return 0;
}
char * StripWord(char * cmd) {
bool quoted=false;
char * begin=cmd;
if (*cmd=='"') {
quoted=true;
cmd++;
}
char * end;
if (quoted) {
end=strchr(cmd,'"');
} else {
end=strchr(cmd,' ');
}
if (!end) {
return cmd+strlen(cmd);
}
*end=0;
if (quoted) {
memmove(begin,cmd,end-begin+1);
}
return trim(cmd+strlen(begin)+1);
}
void GFX_ShowMsg(char * msg);
void DEBUG_ShowMsg(char * msg);
void S_Warn(char * format,...) {
char buf[1024];
va_list msg;
va_start(msg,format);
vsprintf(buf,format,msg);
va_end(msg);
#ifdef C_DEBUG
DEBUG_ShowMsg(buf);
#else
GFX_ShowMsg(buf);
#endif
}
void E_Exit(char * format,...) {
char buf[1024];
// SysShutDown();
va_list msg;
strcpy(buf,"EXIT:");
va_start(msg,format);
vsprintf(buf+strlen(buf),format,msg);
va_end(msg);
strcat(buf,"\n");
printf(buf);
printf("Press ENTER to stop\n");
fgetc(stdin);
exit(2);
};