Update Shell to use the new program class.
Also use a new way to start up the shell and setting up the environment segment. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@313
This commit is contained in:
parent
43a846dc11
commit
851ecbe172
4 changed files with 53 additions and 45 deletions
|
@ -28,10 +28,8 @@ static Bitu shellstop_handler(void) {
|
|||
return CBRET_STOP;
|
||||
}
|
||||
|
||||
static void SHELL_ProgramStart(PROGRAM_Info * info) {
|
||||
DOS_Shell * tempshell=new DOS_Shell(info);
|
||||
tempshell->Run();
|
||||
delete tempshell;
|
||||
static void SHELL_ProgramStart(Program * * make) {
|
||||
*make=new DOS_Shell;
|
||||
}
|
||||
|
||||
#define AUTOEXEC_SIZE 4096
|
||||
|
@ -53,7 +51,7 @@ void SHELL_AddAutoexec(char * line,...) {
|
|||
}
|
||||
|
||||
|
||||
DOS_Shell::DOS_Shell(PROGRAM_Info * info):Program(info) {
|
||||
DOS_Shell::DOS_Shell():Program(){
|
||||
input_handle=STDIN;
|
||||
echo=true;
|
||||
exit=false;
|
||||
|
@ -96,16 +94,19 @@ void DOS_Shell::ParseLine(char * line) {
|
|||
|
||||
|
||||
void DOS_Shell::Run(void) {
|
||||
/* Check for a direct Command */
|
||||
if (strncasecmp(prog_info->cmd_line,"/C ",3)==0) {
|
||||
ParseLine(prog_info->cmd_line+3);
|
||||
char input_line[CMD_MAXLINE];
|
||||
std::string line;
|
||||
if (cmd->FindString("/C",line,true)) {
|
||||
strcpy(input_line,line.c_str());
|
||||
line.erase();
|
||||
return;
|
||||
}
|
||||
/* Start a normal shell and check for a first command init */
|
||||
WriteOut(MSG_Get("SHELL_STARTUP"));
|
||||
char input_line[CMD_MAXLINE];
|
||||
if (strncasecmp(prog_info->cmd_line,"/INIT ",6)==0) {
|
||||
ParseLine(prog_info->cmd_line+6);
|
||||
if (cmd->FindString("/INIT",line,true)) {
|
||||
strcpy(input_line,line.c_str());
|
||||
line.erase();
|
||||
ParseLine(input_line);
|
||||
}
|
||||
do {
|
||||
if (bf && bf->ReadLine(input_line)) {
|
||||
|
@ -136,8 +137,6 @@ void AUTOEXEC_Init(Section * sec) {
|
|||
/* Register a virtual AUOEXEC.BAT file */
|
||||
|
||||
Section_line * section=static_cast<Section_line *>(sec);
|
||||
SHELL_AddAutoexec("SET PATH=Z:\\");
|
||||
SHELL_AddAutoexec("SET COMSPEC=Z:\\COMMAND.COM");
|
||||
char * extra=(char *)section->data.c_str();
|
||||
if (extra) SHELL_AddAutoexec(extra);
|
||||
/* Check to see for extra command line options to be added */
|
||||
|
@ -147,7 +146,7 @@ void AUTOEXEC_Init(Section * sec) {
|
|||
}
|
||||
/* Check for first command being a directory or file */
|
||||
char buffer[CROSS_LEN];
|
||||
if (control->cmdline->FindFirst(line)) {
|
||||
if (control->cmdline->FindCommand(1,line)) {
|
||||
struct stat test;
|
||||
strcpy(buffer,line.c_str());
|
||||
if (stat(buffer,&test)) {
|
||||
|
@ -172,23 +171,39 @@ nomount:
|
|||
VFILE_Register("AUTOEXEC.BAT",(Bit8u *)autoexec_data,strlen(autoexec_data));
|
||||
}
|
||||
|
||||
static char * path_string="PATH=Z:\\";
|
||||
static char * comspec_string="COMSPEC=Z:\\COMMAND.COM";
|
||||
static char * full_name="Z:\\COMMAND.COM";
|
||||
static char * init_line="/INIT AUTOEXEC.BAT";
|
||||
|
||||
void SHELL_Init() {
|
||||
|
||||
call_shellstop=CALLBACK_Allocate();
|
||||
CALLBACK_Setup(call_shellstop,shellstop_handler,CB_IRET);
|
||||
PROGRAMS_MakeFile("COMMAND.COM",SHELL_ProgramStart);
|
||||
|
||||
/* Now call up the shell for the first time */
|
||||
Bit16u psp_seg=DOS_GetMemory(16);
|
||||
Bit16u env_seg=DOS_GetMemory(1+(4096/16));
|
||||
Bit16u psp_seg=DOS_GetMemory(16+1)+1;
|
||||
Bit16u env_seg=DOS_GetMemory(1+(4096/16))+1;
|
||||
Bit16u stack_seg=DOS_GetMemory(2048/16);
|
||||
SegSet16(ss,stack_seg);
|
||||
reg_sp=2046;
|
||||
/* Setup a fake MCB for the environment */
|
||||
MCB * env_mcb=(MCB *)HostMake(env_seg,0);
|
||||
/* Setup MCB and the environment */
|
||||
MCB * env_mcb=(MCB *)HostMake(env_seg-1,0);
|
||||
env_mcb->psp_segment=psp_seg;
|
||||
env_mcb->size=4096/16;
|
||||
real_writed(env_seg+1,0,0);
|
||||
PhysPt env_write=PhysMake(env_seg,0);
|
||||
MEM_BlockWrite(env_write,path_string,strlen(path_string)+1);
|
||||
env_write+=strlen(path_string)+1;
|
||||
MEM_BlockWrite(env_write,comspec_string,strlen(comspec_string)+1);
|
||||
env_write+=strlen(comspec_string)+1;
|
||||
mem_writeb(env_write++,0);
|
||||
mem_writew(env_write,1);
|
||||
env_write+=2;
|
||||
MEM_BlockWrite(env_write,full_name,strlen(full_name)+1);
|
||||
|
||||
DOS_PSP psp(psp_seg); psp.MakeNew(env_mcb->size);
|
||||
DOS_PSP psp(psp_seg);
|
||||
psp.MakeNew(0);
|
||||
psp.SetFileHandle(STDIN ,DOS_FindDevice("CON"));
|
||||
psp.SetFileHandle(STDOUT,DOS_FindDevice("CON"));
|
||||
psp.SetFileHandle(STDERR,DOS_FindDevice("CON"));
|
||||
|
@ -196,19 +211,19 @@ void SHELL_Init() {
|
|||
psp.SetFileHandle(STDNUL,DOS_FindDevice("CON"));
|
||||
psp.SetFileHandle(STDPRN,DOS_FindDevice("CON"));
|
||||
psp.SetParent(psp_seg);
|
||||
/* Set the environment and clear it */
|
||||
psp.SetEnvironment(env_seg+1);
|
||||
mem_writew(Real2Phys(RealMake(env_seg+1,0)),0);
|
||||
/* Set the environment */
|
||||
psp.SetEnvironment(env_seg);
|
||||
/* Set the command line for the shell start up */
|
||||
CommandTail tail;
|
||||
tail.count=strlen(init_line);
|
||||
strcpy(tail.buffer,init_line);
|
||||
MEM_BlockWrite(PhysMake(psp_seg,128),&tail,128);
|
||||
/* Setup internal DOS Variables */
|
||||
dos.dta=psp.GetDTA();
|
||||
dos.psp=psp_seg;
|
||||
PROGRAM_Info info;
|
||||
strcpy(info.full_name,"Z:\\COMMAND.COM");
|
||||
info.psp_seg=psp_seg;
|
||||
MEM_BlockRead(PhysMake(dos.psp,0),&info.psp_copy,sizeof(sPSP));
|
||||
char line[256];
|
||||
strcpy(line,"/INIT Z:\\AUTOEXEC.BAT");
|
||||
info.cmd_line=line;
|
||||
|
||||
SHELL_ProgramStart(&info);
|
||||
Program * new_program;
|
||||
SHELL_ProgramStart(&new_program);
|
||||
new_program->Run();
|
||||
delete new_program;
|
||||
}
|
||||
|
|
|
@ -65,9 +65,8 @@ void DOS_Shell::DoCommand(char * line) {
|
|||
Bit32u cmd_index=0;
|
||||
while (cmd_list[cmd_index].name) {
|
||||
if (strcasecmp(cmd_list[cmd_index].name,cmd)==0) {
|
||||
//TODO CHECK Flags
|
||||
(this->*(cmd_list[cmd_index].handler))(line);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
cmd_index++;
|
||||
}
|
||||
|
@ -202,16 +201,14 @@ void DOS_Shell::CMD_DIR(char * args) {
|
|||
WriteOut(MSG_Get("SHELL_CMD_FILE_NOT_FOUND"),args);
|
||||
return;
|
||||
}
|
||||
|
||||
while (ret) {
|
||||
|
||||
/* File name and extension */
|
||||
char * ext="";
|
||||
if (!optW && (*dta->name != '.')) {
|
||||
ext = strrchr(dta->name, '.');
|
||||
if (!ext) ext = "";
|
||||
else *ext++ = '\0';
|
||||
};
|
||||
}
|
||||
|
||||
Bit8u day = dta->date & 0x001f;
|
||||
Bit8u month = (dta->date >> 5) & 0x000f;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "regs.h"
|
||||
#include "support.h"
|
||||
#include "callback.h"
|
||||
#include "setup.h"
|
||||
|
||||
#define CMD_MAXLINE 4096
|
||||
#define CMD_MAXCMDS 20
|
||||
|
@ -52,7 +53,7 @@ public:
|
|||
|
||||
class DOS_Shell : public Program {
|
||||
public:
|
||||
DOS_Shell(PROGRAM_Info * program_info);
|
||||
DOS_Shell();
|
||||
void Run(void);
|
||||
/* A load of subfunctions */
|
||||
void ParseLine(char * line);
|
||||
|
|
|
@ -119,9 +119,6 @@ void DOS_Shell::InputCommand(char * line) {
|
|||
size_t first_len=strlen(old.buffer)+1;
|
||||
memmove(&old.buffer[first_len],&old.buffer[0],CMD_OLDSIZE-first_len);
|
||||
strcpy(old.buffer,line);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DOS_Shell::Execute(char * name,char * args) {
|
||||
|
@ -165,9 +162,9 @@ void DOS_Shell::Execute(char * name,char * args) {
|
|||
cmd.count=strlen(line);
|
||||
memcpy(cmd.buffer,line,strlen(line));
|
||||
cmd.buffer[strlen(line)]=0xd;
|
||||
MEM_BlockWrite(PhysMake(prog_info->psp_seg,128),&cmd,128);
|
||||
|
||||
block.InitExec(RealMake(prog_info->psp_seg,128));
|
||||
/* Copy command line in stack block too */
|
||||
MEM_BlockWrite(SegPhys(ss)+reg_sp+0x100,&cmd,128);
|
||||
block.InitExec(RealMakeSeg(ss,reg_sp+0x100));
|
||||
/* Save CS:IP to some point where i can return them from */
|
||||
RealPt newcsip;
|
||||
newcsip=CALLBACK_RealPointer(call_shellstop);
|
||||
|
@ -185,8 +182,6 @@ void DOS_Shell::Execute(char * name,char * args) {
|
|||
CALLBACK_RunRealInt(0x21);
|
||||
reg_sp+=0x200;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue