diff --git a/include/programs.h b/include/programs.h index d4e75941..09c49c3c 100644 --- a/include/programs.h +++ b/include/programs.h @@ -82,10 +82,12 @@ public: bool GetEnvNum(Bitu num,std::string & result); Bitu GetEnvCount(void); bool SetEnv(const char * entry,const char * new_string); - void WriteOut(const char * format,...); /* Write to standard output */ - void WriteOut_NoParsing(const char * format); /* Write to standard output, no parsing */ + void WriteOut(const char *format, ...); // printf to DOS stdout + void WriteOut_NoParsing(const char *str); // write string to DOS stdout + void InjectMissingNewline(); void ChangeToLongCmd(); + static void ResetLastWrittenChar(char c); }; typedef void (PROGRAMS_Main)(Program * * make); diff --git a/src/dos/dos_execute.cpp b/src/dos/dos_execute.cpp index 82e9924f..01459505 100644 --- a/src/dos/dos_execute.cpp +++ b/src/dos/dos_execute.cpp @@ -26,6 +26,7 @@ #include "callback.h" #include "debug.h" #include "cpu.h" +#include "programs.h" const char * RunningProgram="DOSBOX"; @@ -422,6 +423,8 @@ bool DOS_Execute(char * name,PhysPt block_pt,Bit8u flags) { csip=RealMake(loadseg+head.initCS,head.initIP); sssp=RealMake(loadseg+head.initSS,head.initSP); if (head.initSP<4) LOG(LOG_EXEC,LOG_ERROR)("stack underflow/wrap at EXEC"); + + Program::ResetLastWrittenChar('\0'); // triggers newline injection after DOS programs } if ((flags==LOAD) || (flags==LOADNGO)) { diff --git a/src/misc/programs.cpp b/src/misc/programs.cpp index 34de946a..d47fb9fc 100644 --- a/src/misc/programs.cpp +++ b/src/misc/programs.cpp @@ -174,6 +174,23 @@ void Program::WriteOut_NoParsing(const char * format) { // DOS_WriteFile(STDOUT,(Bit8u *)format,&size); } +void Program::ResetLastWrittenChar(char c) +{ + last_written_character = c; +} + +void Program::InjectMissingNewline() +{ + if (last_written_character == '\n') + return; + + uint16_t n = 2; + uint8_t dos_nl[] = "\r\n"; + dos.internal_output = true; + DOS_WriteFile(STDOUT, dos_nl, &n); + dos.internal_output = false; + last_written_character = '\n'; +} bool Program::GetEnvStr(const char * entry,std::string & result) { /* Walk through the internal environment and see for a match */ diff --git a/src/shell/shell_misc.cpp b/src/shell/shell_misc.cpp index e0b2e85f..2be97db6 100644 --- a/src/shell/shell_misc.cpp +++ b/src/shell/shell_misc.cpp @@ -33,7 +33,9 @@ void DOS_Shell::ShowPrompt(void) { char dir[DOS_PATHLENGTH]; dir[0] = 0; //DOS_GetCurrentDir doesn't always return something. (if drive is messed up) DOS_GetCurrentDir(0,dir); - WriteOut("%c:\\%s>",drive,dir); + InjectMissingNewline(); + WriteOut("%c:\\%s>", drive, dir); + ResetLastWrittenChar('\n'); // prevents excessive newline if cmd prints nothing } static void outc(Bit8u c) {