From 1c410c147e9783e2bb74d812891ecefe636601e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Sun, 4 Oct 2009 14:28:07 +0000 Subject: [PATCH] use calling application's code segment rather than psp value for some old-style (dos 1.0) terminate functions (ripsaw, fixes fortune teller) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3476 --- include/dos_inc.h | 4 ++-- src/dos/dos.cpp | 27 ++++++++++----------------- src/dos/dos_execute.cpp | 18 ++++++++---------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/include/dos_inc.h b/include/dos_inc.h index 97deee81..a51085cb 100644 --- a/include/dos_inc.h +++ b/include/dos_inc.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_inc.h,v 1.81 2009-07-09 20:06:56 c2woody Exp $ */ +/* $Id: dos_inc.h,v 1.82 2009-10-04 14:28:06 c2woody Exp $ */ #ifndef DOSBOX_DOS_INC_H #define DOSBOX_DOS_INC_H @@ -154,7 +154,7 @@ void DOS_SetupDevices(void); bool DOS_NewPSP(Bit16u pspseg,Bit16u size); bool DOS_ChildPSP(Bit16u pspseg,Bit16u size); bool DOS_Execute(char * name,PhysPt block,Bit8u flags); -bool DOS_Terminate(bool tsr,Bit8u exitcode); +void DOS_Terminate(Bit16u pspseg,bool tsr,Bit8u exitcode); /* Memory Handling Routines */ void DOS_SetupMemory(void); diff --git a/src/dos/dos.cpp b/src/dos/dos.cpp index 2c5ed763..ce723fac 100644 --- a/src/dos/dos.cpp +++ b/src/dos/dos.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos.cpp,v 1.119 2009-07-31 16:41:37 qbix79 Exp $ */ +/* $Id: dos.cpp,v 1.120 2009-10-04 14:28:07 c2woody Exp $ */ #include #include @@ -70,6 +70,9 @@ static Bitu DOS_21Handler(void) { char name1[DOSNAMEBUF+2+DOS_NAMELENGTH_ASCII]; char name2[DOSNAMEBUF+2+DOS_NAMELENGTH_ASCII]; switch (reg_ah) { + case 0x00: /* Terminate Program */ + DOS_Terminate(mem_readw(SegPhys(ss)+reg_sp+2),false,0); + break; case 0x01: /* Read character from STDIN, with echo */ { Bit8u c;Bit16u n=1; @@ -390,11 +393,9 @@ static Bitu DOS_21Handler(void) { reg_cx=0x0000; break; case 0x31: /* Terminate and stay resident */ - //TODO First get normal files executing // Important: This service does not set the carry flag! DOS_ResizeMemory(dos.psp(),®_dx); - DOS_Terminate(true,reg_al); - dos.return_mode=RETURN_TSR; + DOS_Terminate(dos.psp(),true,reg_al); break; case 0x1f: /* Get drive parameter block for default drive */ case 0x32: /* Get drive parameter block for specific drive */ @@ -708,18 +709,9 @@ static Bitu DOS_21Handler(void) { } break; //TODO Check for use of execution state AL=5 - case 0x00: - reg_ax=0x4c00; /* Terminate Program */ case 0x4c: /* EXIT Terminate with return code */ - { - if (DOS_Terminate(false,reg_al)) { - /* This can't ever return false normally */ - } else { - reg_ax=dos.errorcode; - CALLBACK_SCF(true); - } - break; - } + DOS_Terminate(dos.psp(),false,reg_al); + break; case 0x4d: /* Get Return code */ reg_al=dos.return_code;/* Officially read from SDA and clear when read */ reg_ah=dos.return_mode; @@ -1051,7 +1043,7 @@ static Bitu DOS_21Handler(void) { static Bitu DOS_20Handler(void) { - reg_ax=0x4c00; + reg_ah=0x00; DOS_21Handler(); return CBRET_NONE; } @@ -1059,7 +1051,8 @@ static Bitu DOS_20Handler(void) { static Bitu DOS_27Handler(void) { // Terminate & stay resident Bit16u para = (reg_dx/16)+((reg_dx % 16)>0); - if (DOS_ResizeMemory(dos.psp(),¶)) DOS_Terminate(true,0); + Bit16u psp = mem_readw(SegPhys(ss)+reg_sp+2); + if (DOS_ResizeMemory(psp,¶)) DOS_Terminate(psp,true,0); return CBRET_NONE; } diff --git a/src/dos/dos_execute.cpp b/src/dos/dos_execute.cpp index 80436386..bf81479a 100644 --- a/src/dos/dos_execute.cpp +++ b/src/dos/dos_execute.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_execute.cpp,v 1.67 2009-05-27 09:15:41 qbix79 Exp $ */ +/* $Id: dos_execute.cpp,v 1.68 2009-10-04 14:28:07 c2woody Exp $ */ #include #include @@ -104,15 +104,13 @@ void DOS_UpdatePSPName(void) { GFX_SetTitle(-1,-1,false); } -bool DOS_Terminate(bool tsr,Bit8u exitcode) { +void DOS_Terminate(Bit16u pspseg,bool tsr,Bit8u exitcode) { dos.return_code=exitcode; - dos.return_mode=RETURN_EXIT; + dos.return_mode=(tsr)?RETURN_TSR:RETURN_EXIT; - Bit16u mempsp = dos.psp(); - - DOS_PSP curpsp(mempsp); - if (mempsp==curpsp.GetParent()) return true; + DOS_PSP curpsp(pspseg); + if (pspseg==curpsp.GetParent()) return; /* Free Files owned by process */ if (!tsr) curpsp.CloseFiles(); @@ -136,10 +134,10 @@ bool DOS_Terminate(bool tsr,Bit8u exitcode) { interrupts enabled, test flags cleared */ mem_writew(SegPhys(ss)+reg_sp+4,0x7202); // Free memory owned by process - if (!tsr) DOS_FreeProcessMemory(mempsp); + if (!tsr) DOS_FreeProcessMemory(pspseg); DOS_UpdatePSPName(); - if ((!(CPU_AutoDetermineMode>>CPU_AUTODETERMINE_SHIFT)) || (cpu.pmode)) return true; + if ((!(CPU_AutoDetermineMode>>CPU_AUTODETERMINE_SHIFT)) || (cpu.pmode)) return; CPU_AutoDetermineMode>>=CPU_AUTODETERMINE_SHIFT; if (CPU_AutoDetermineMode&CPU_AUTODETERMINE_CYCLES) { @@ -159,7 +157,7 @@ bool DOS_Terminate(bool tsr,Bit8u exitcode) { } #endif - return true; + return; } static bool MakeEnv(char * name,Bit16u * segment) {