[NTVDM]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Tue, 23 Jul 2013 21:43:57 +0000 (21:43 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Tue, 23 Jul 2013 21:43:57 +0000 (21:43 +0000)
Modify the flags on the stack instead of the flags register directly.
The flags register is restored during IRET so changing it directly does nothing.

svn path=/branches/ntvdm/; revision=59566

subsystems/ntvdm/bios.c
subsystems/ntvdm/bios.h
subsystems/ntvdm/dos.c
subsystems/ntvdm/dos.h
subsystems/ntvdm/emulator.c
subsystems/ntvdm/emulator.h

index 3b9c99b..c5a27b5 100644 (file)
@@ -57,7 +57,7 @@ static VIDEO_MODE VideoModes[] =
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
-static DWORD BiosGetVideoPageSize()
+static DWORD BiosGetVideoPageSize(VOID)
 {
     INT i;
     DWORD BufferSize = VideoModes[CurrentVideoMode].Width
@@ -135,7 +135,7 @@ static BOOLEAN BiosKbdBufferTop(LPWORD Data)
     return TRUE;
 }
 
-static BOOLEAN BiosKbdBufferPop()
+static BOOLEAN BiosKbdBufferPop(VOID)
 {
     /* If it's empty, fail */
     if (Bda->KeybdBufferHead == Bda->KeybdBufferTail) return FALSE;
@@ -214,7 +214,7 @@ static BOOLEAN BiosCreateGraphicsBuffer(BYTE ModeNumber)
     return TRUE;
 }
 
-static VOID BiosDestroyGraphicsBuffer()
+static VOID BiosDestroyGraphicsBuffer(VOID)
 {
     CloseHandle(ConsoleMutex);
     CloseHandle(BiosGraphicsOutput);
@@ -222,7 +222,7 @@ static VOID BiosDestroyGraphicsBuffer()
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
-BYTE BiosGetVideoMode()
+BYTE BiosGetVideoMode(VOID)
 {
     return CurrentVideoMode;
 }
@@ -335,12 +335,12 @@ BOOLEAN BiosSetVideoPage(BYTE PageNumber)
     return TRUE;
 }
 
-inline DWORD BiosGetVideoMemoryStart()
+inline DWORD BiosGetVideoMemoryStart(VOID)
 {
     return (VideoModes[CurrentVideoMode].Segment << 4);
 }
 
-inline VOID BiosVerticalRefresh()
+inline VOID BiosVerticalRefresh(VOID)
 {
     /* Ignore if we're in text mode */
     if (VideoModes[CurrentVideoMode].Text) return;
@@ -355,7 +355,7 @@ inline VOID BiosVerticalRefresh()
     VideoNeedsUpdate = FALSE;
 }
 
-BOOLEAN BiosInitialize()
+BOOLEAN BiosInitialize(VOID)
 {
     INT i;
     WORD Offset = 0;
@@ -458,7 +458,7 @@ BOOLEAN BiosInitialize()
     return TRUE;
 }
 
-VOID BiosCleanup()
+VOID BiosCleanup(VOID)
 {
     /* Restore the old screen buffer */
     SetConsoleActiveScreenBuffer(BiosConsoleOutput);
@@ -611,7 +611,7 @@ VOID BiosUpdateVideoMemory(ULONG StartAddress, ULONG EndAddress)
     }
 }
 
-WORD BiosPeekCharacter()
+WORD BiosPeekCharacter(VOID)
 {
     WORD CharacterData;
     
@@ -624,7 +624,7 @@ WORD BiosPeekCharacter()
     return CharacterData;
 }
 
-WORD BiosGetCharacter()
+WORD BiosGetCharacter(VOID)
 {
     WORD CharacterData;
     INPUT_RECORD InputRecord;
@@ -660,7 +660,7 @@ WORD BiosGetCharacter()
     return CharacterData;
 }
 
-VOID BiosVideoService()
+VOID BiosVideoService(LPWORD Stack)
 {
     INT i, CursorHeight;
     BOOLEAN Invisible = FALSE;
@@ -811,7 +811,8 @@ VOID BiosVideoService()
                                 *((LPWORD)((ULONG_PTR)BaseAddress + Address)));
 
             break;
-        }
+        }                EmulatorSetFlag(EMULATOR_FLAG_ZF);
+
 
         /* Write Character And Attribute At Cursor Position */
         case 0x09:
@@ -927,7 +928,7 @@ VOID BiosVideoService()
     }
 }
 
-VOID BiosKeyboardService()
+VOID BiosKeyboardService(LPWORD Stack)
 {
     DWORD Eax = EmulatorGetRegister(EMULATOR_REG_AX);
 
@@ -949,12 +950,12 @@ VOID BiosKeyboardService()
             {
                 /* There is a character, clear ZF and return it */
                 EmulatorSetRegister(EMULATOR_REG_AX, Data);
-                EmulatorClearFlag(EMULATOR_FLAG_ZF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_ZF;
             }
             else
             {
                 /* No character, set ZF */
-                EmulatorSetFlag(EMULATOR_FLAG_ZF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_ZF;
             }
 
             break;
@@ -968,7 +969,7 @@ VOID BiosKeyboardService()
     }
 }
 
-VOID BiosTimeService()
+VOID BiosTimeService(LPWORD Stack)
 {
     DWORD Eax = EmulatorGetRegister(EMULATOR_REG_AX);
     DWORD Ecx = EmulatorGetRegister(EMULATOR_REG_CX);
@@ -1012,19 +1013,19 @@ VOID BiosTimeService()
     }
 }
 
-VOID BiosSystemTimerInterrupt()
+VOID BiosSystemTimerInterrupt(LPWORD Stack)
 {
     /* Increase the system tick count */
     Bda->TickCounter++;
 }
 
-VOID BiosEquipmentService()
+VOID BiosEquipmentService(LPWORD Stack)
 {
     /* Return the equipment list */
     EmulatorSetRegister(EMULATOR_REG_AX, Bda->EquipmentList);
 }
 
-VOID BiosHandleIrq(BYTE IrqNumber)
+VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack)
 {
     switch (IrqNumber)
     {
index 5c6508f..3644f3b 100644 (file)
@@ -97,19 +97,19 @@ typedef struct
 
 /* FUNCTIONS ******************************************************************/
 
-BOOLEAN BiosInitialize();
-VOID BiosCleanup();
+BOOLEAN BiosInitialize(VOID);
+VOID BiosCleanup(VOID);
 VOID BiosUpdateConsole(ULONG StartAddress, ULONG EndAddress);
 VOID BiosUpdateVideoMemory(ULONG StartAddress, ULONG EndAddress);
-inline DWORD BiosGetVideoMemoryStart();
-inline VOID BiosVerticalRefresh();
-WORD BiosPeekCharacter();
-WORD BiosGetCharacter();
-VOID BiosVideoService();
-VOID BiosEquipmentService();
-VOID BiosKeyboardService();
-VOID BiosTimeService();
-VOID BiosHandleIrq(BYTE IrqNumber);
-VOID BiosSystemTimerInterrupt();
+inline DWORD BiosGetVideoMemoryStart(VOID);
+inline VOID BiosVerticalRefresh(VOID);
+WORD BiosPeekCharacter(VOID);
+WORD BiosGetCharacter(VOID);
+VOID BiosVideoService(LPWORD Stack);
+VOID BiosEquipmentService(LPWORD Stack);
+VOID BiosKeyboardService(LPWORD Stack);
+VOID BiosTimeService(LPWORD Stack);
+VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack);
+VOID BiosSystemTimerInterrupt(LPWORD Stack);
 
 #endif
index a999421..c3f4afd 100644 (file)
@@ -1161,15 +1161,15 @@ VOID DosPrintCharacter(CHAR Character)
     DosWriteFile(DOS_OUTPUT_HANDLE, &Character, sizeof(CHAR), &BytesWritten);
 }
 
-VOID DosHandleIoctl(BYTE ControlCode, WORD FileHandle)
+BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle)
 {
     HANDLE Handle = DosGetRealHandle(FileHandle);
 
     if (Handle == INVALID_HANDLE_VALUE)
     {
         /* Doesn't exist */
-        EmulatorSetFlag(EMULATOR_FLAG_CF);
-        EmulatorSetRegister(EMULATOR_REG_AX, ERROR_FILE_NOT_FOUND);
+        DosLastError = ERROR_FILE_NOT_FOUND;
+        return FALSE;
     }
 
     switch (ControlCode)
@@ -1194,10 +1194,9 @@ VOID DosHandleIoctl(BYTE ControlCode, WORD FileHandle)
             InfoWord |= 1 << 7;
 
             /* Return the device information word */
-            EmulatorClearFlag(EMULATOR_FLAG_CF);
             EmulatorSetRegister(EMULATOR_REG_DX, InfoWord);
 
-            break;
+            return TRUE;
         }
 
         /* Unsupported control code */
@@ -1205,19 +1204,19 @@ VOID DosHandleIoctl(BYTE ControlCode, WORD FileHandle)
         {
             DPRINT1("Unsupported IOCTL: 0x%02X\n", ControlCode);
 
-            EmulatorSetFlag(EMULATOR_FLAG_CF);
-            EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_PARAMETER);
+            DosLastError = ERROR_INVALID_PARAMETER;
+            return FALSE;
         }
     }
 }
 
-VOID DosInt20h(WORD CodeSegment)
+VOID DosInt20h(LPWORD Stack)
 {
     /* This is the exit interrupt */
-    DosTerminateProcess(CodeSegment, 0);
+    DosTerminateProcess(Stack[STACK_CS], 0);
 }
 
-VOID DosInt21h(WORD CodeSegment)
+VOID DosInt21h(LPWORD Stack)
 {
     INT i;
     CHAR Character;
@@ -1237,7 +1236,7 @@ VOID DosInt21h(WORD CodeSegment)
         /* Terminate Program */
         case 0x00:
         {
-            DosTerminateProcess(CodeSegment, 0);
+            DosTerminateProcess(Stack[STACK_CS], 0);
             break;
         }
 
@@ -1432,11 +1431,11 @@ VOID DosInt21h(WORD CodeSegment)
 
             if (CreateDirectoryA(String, NULL))
             {
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX,
                                     (Eax & 0xFFFF0000) | LOWORD(GetLastError()));
             }
@@ -1452,11 +1451,11 @@ VOID DosInt21h(WORD CodeSegment)
 
             if (RemoveDirectoryA(String))
             {
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX,
                                     (Eax & 0xFFFF0000) | LOWORD(GetLastError()));
             }
@@ -1473,11 +1472,11 @@ VOID DosInt21h(WORD CodeSegment)
 
             if (SetCurrentDirectoryA(String))
             {
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX,
                                     (Eax & 0xFFFF0000) | LOWORD(GetLastError()));
             }
@@ -1497,7 +1496,7 @@ VOID DosInt21h(WORD CodeSegment)
             if (ErrorCode == 0)
             {
                 /* Clear CF */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
 
                 /* Return the handle in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1506,7 +1505,7 @@ VOID DosInt21h(WORD CodeSegment)
             else
             {
                 /* Set CF */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
 
                 /* Return the error code in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1528,7 +1527,7 @@ VOID DosInt21h(WORD CodeSegment)
             if (ErrorCode == 0)
             {
                 /* Clear CF */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
 
                 /* Return the handle in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1537,7 +1536,7 @@ VOID DosInt21h(WORD CodeSegment)
             else
             {
                 /* Set CF */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
 
                 /* Return the error code in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1553,12 +1552,12 @@ VOID DosInt21h(WORD CodeSegment)
             if (DosCloseHandle(LOWORD(Ebx)))
             {
                 /* Clear CF */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
                 /* Set CF */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
 
                 /* Return the error code in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1581,7 +1580,7 @@ VOID DosInt21h(WORD CodeSegment)
             if (ErrorCode == 0)
             {
                 /* Clear CF */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
 
                 /* Return the number of bytes read in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1590,7 +1589,7 @@ VOID DosInt21h(WORD CodeSegment)
             else
             {
                 /* Set CF */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
 
                 /* Return the error code in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1612,7 +1611,7 @@ VOID DosInt21h(WORD CodeSegment)
             if (ErrorCode == 0)
             {
                 /* Clear CF */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
 
                 /* Return the number of bytes written in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1621,7 +1620,7 @@ VOID DosInt21h(WORD CodeSegment)
             else
             {
                 /* Set CF */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
 
                 /* Return the error code in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1637,10 +1636,10 @@ VOID DosInt21h(WORD CodeSegment)
             LPSTR FileName = (LPSTR)((ULONG_PTR)BaseAddress + TO_LINEAR(DataSegment, Edx));
 
             /* Call the API function */
-            if (DeleteFileA(FileName)) EmulatorClearFlag(EMULATOR_FLAG_CF);
+            if (DeleteFileA(FileName)) Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             else
             {
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX, GetLastError());
             }
 
@@ -1659,7 +1658,7 @@ VOID DosInt21h(WORD CodeSegment)
             if (ErrorCode == 0)
             {
                 /* Clear CF */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
 
                 /* Return the new offset in DX:AX */
                 EmulatorSetRegister(EMULATOR_REG_DX,
@@ -1670,7 +1669,7 @@ VOID DosInt21h(WORD CodeSegment)
             else
             {
                 /* Set CF */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
 
                 /* Return the error code in AX */
                 EmulatorSetRegister(EMULATOR_REG_AX,
@@ -1694,14 +1693,14 @@ VOID DosInt21h(WORD CodeSegment)
                 /* Check if it failed */
                 if (Attributes == INVALID_FILE_ATTRIBUTES)
                 {
-                    EmulatorSetFlag(EMULATOR_FLAG_CF);
+                    Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                     EmulatorSetRegister(EMULATOR_REG_AX, GetLastError());
 
                     break;
                 }
 
                 /* Return the attributes that DOS can understand */
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_CX,
                                     (Ecx & 0xFFFFFF00) | LOBYTE(Attributes));
             }
@@ -1710,17 +1709,17 @@ VOID DosInt21h(WORD CodeSegment)
                 /* Try to set the attributes */
                 if (SetFileAttributesA(FileName, LOBYTE(Ecx)))
                 {
-                    EmulatorClearFlag(EMULATOR_FLAG_CF);
+                    Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
                 }
                 else
                 {
-                    EmulatorSetFlag(EMULATOR_FLAG_CF);
+                    Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                     EmulatorSetRegister(EMULATOR_REG_AX, GetLastError());
                 }
             }
             else
             {
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_FUNCTION);
             }
 
@@ -1730,7 +1729,15 @@ VOID DosInt21h(WORD CodeSegment)
         /* IOCTL */
         case 0x44:
         {
-            DosHandleIoctl(LOBYTE(Eax), LOWORD(Ebx));
+            if (DosHandleIoctl(LOBYTE(Eax), LOWORD(Ebx)))
+            {
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
+            }
+            else
+            {
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
+                EmulatorSetRegister(EMULATOR_REG_AX, DosLastError);
+            }
 
             break;
         }
@@ -1744,7 +1751,7 @@ VOID DosInt21h(WORD CodeSegment)
             if (Handle != INVALID_HANDLE_VALUE)
             {
                 /* The handle is invalid */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_HANDLE);
 
                 break;
@@ -1756,14 +1763,14 @@ VOID DosInt21h(WORD CodeSegment)
             if (NewHandle == INVALID_DOS_HANDLE)
             {
                 /* Too many files open */
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX, ERROR_TOO_MANY_OPEN_FILES);
 
                 break;
             }
 
             /* Return the result */
-            EmulatorClearFlag(EMULATOR_FLAG_CF);
+            Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             EmulatorSetRegister(EMULATOR_REG_AX, NewHandle);
 
             break;
@@ -1774,11 +1781,11 @@ VOID DosInt21h(WORD CodeSegment)
         {
             if (DosDuplicateHandle(LOWORD(Ebx), LOWORD(Ecx)))
             {
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_HANDLE);
             }
 
@@ -1794,13 +1801,13 @@ VOID DosInt21h(WORD CodeSegment)
             if (Segment != 0)
             {
                 EmulatorSetRegister(EMULATOR_REG_AX, Segment);
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
                 EmulatorSetRegister(EMULATOR_REG_AX, DosLastError);
                 EmulatorSetRegister(EMULATOR_REG_BX, MaxAvailable);
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
             }
 
             break;
@@ -1811,12 +1818,12 @@ VOID DosInt21h(WORD CodeSegment)
         {
             if (DosFreeMemory(ExtSegment))
             {
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
                 EmulatorSetRegister(EMULATOR_REG_AX, ERROR_ARENA_TRASHED);
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
             }
 
             break;
@@ -1829,12 +1836,12 @@ VOID DosInt21h(WORD CodeSegment)
 
             if (DosResizeMemory(ExtSegment, LOWORD(Ebx), &Size))
             {
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
                 EmulatorSetRegister(EMULATOR_REG_AX, DosLastError);
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_BX, Size);
             }
 
@@ -1864,7 +1871,7 @@ VOID DosInt21h(WORD CodeSegment)
                 /* Get allocation strategy */
 
                 EmulatorSetRegister(EMULATOR_REG_AX, DosAllocStrategy);
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else if (LOBYTE(Eax) == 0x01)
             {
@@ -1875,7 +1882,7 @@ VOID DosInt21h(WORD CodeSegment)
                 {
                     /* Can't set both */
                     EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_PARAMETER);
-                    EmulatorSetFlag(EMULATOR_FLAG_CF);
+                    Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                     break;
                 }
 
@@ -1883,12 +1890,12 @@ VOID DosInt21h(WORD CodeSegment)
                 {
                     /* Invalid allocation strategy */
                     EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_PARAMETER);
-                    EmulatorSetFlag(EMULATOR_FLAG_CF);
+                    Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                     break;
                 }
 
                 DosAllocStrategy = LOBYTE(Ebx);
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else if (LOBYTE(Eax) == 0x02)
             {
@@ -1897,7 +1904,7 @@ VOID DosInt21h(WORD CodeSegment)
                 Eax &= 0xFFFFFF00;
                 if (DosUmbLinked) Eax |= 1;
                 EmulatorSetRegister(EMULATOR_REG_AX, Eax);
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else if (LOBYTE(Eax) == 0x03)
             {
@@ -1905,13 +1912,13 @@ VOID DosInt21h(WORD CodeSegment)
 
                 if (Ebx) DosLinkUmb();
                 else DosUnlinkUmb();
-                EmulatorClearFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
             }
             else
             {
                 /* Invalid or unsupported function */
 
-                EmulatorSetFlag(EMULATOR_FLAG_CF);
+                Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
                 EmulatorSetRegister(EMULATOR_REG_AX, ERROR_INVALID_FUNCTION);
             }
 
@@ -1922,12 +1929,12 @@ VOID DosInt21h(WORD CodeSegment)
         default:
         {
             DPRINT1("DOS Function INT 0x21, AH = 0x%02X NOT IMPLEMENTED!\n", HIBYTE(Eax));
-            EmulatorSetFlag(EMULATOR_FLAG_CF);
+            Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
         }
     }
 }
 
-VOID DosBreakInterrupt(VOID)
+VOID DosBreakInterrupt(LPWORD Stack)
 {
     VdmRunning = FALSE;
 }
index 5e9d331..67cf885 100644 (file)
@@ -117,9 +117,10 @@ BOOLEAN DosCreateProcess(LPCSTR CommandLine, WORD EnvBlock);
 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode);
 CHAR DosReadCharacter(VOID);
 VOID DosPrintCharacter(CHAR Character);
-VOID DosInt20h(WORD CodeSegment);
-VOID DosInt21h(WORD CodeSegment);
-VOID DosBreakInterrupt(VOID);
+BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
+VOID DosInt20h(LPWORD Stack);
+VOID DosInt21h(LPWORD Stack);
+VOID DosBreakInterrupt(LPWORD Stack);
 BOOLEAN DosInitialize(VOID);
 
 #endif
index 6a2a0ca..abb8684 100644 (file)
@@ -114,6 +114,11 @@ static VOID EmulatorReadIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size)
             *Buffer = KeyboardReadData();
             break;
         }
+
+        default:
+        {
+            DPRINT1("Read from unknown port: 0x%X\n", Address);
+        }
     }
 }
 
@@ -162,6 +167,11 @@ static VOID EmulatorWriteIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size
             KeyboardWriteData(Byte);
             break;
         }
+
+        default:
+        {
+            DPRINT1("Write to unknown port: 0x%X\n", Address);
+        }
     }
 }
 
@@ -186,11 +196,11 @@ static VOID EmulatorBop(WORD Code)
     if (Code == EMULATOR_INT_BOP)
     {
         /* Get the interrupt number */
-        IntNum = LOBYTE(Stack[0]);
+        IntNum = LOBYTE(Stack[STACK_INT_NUM]);
 
         /* Get the CS:IP */
-        InstructionPointer = Stack[1];
-        CodeSegment = Stack[2];
+        InstructionPointer = Stack[STACK_IP];
+        CodeSegment = Stack[STACK_CS];
 
         /* Check if this was an exception */
         if (IntNum < 8)
@@ -210,13 +220,13 @@ static VOID EmulatorBop(WORD Code)
         if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8)
         {
             /* It was an IRQ from the master PIC */
-            BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT);
+            BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack);
             return;
         }
         else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8)
         {
             /* It was an IRQ from the slave PIC */
-            BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8);
+            BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack);
             return;
         }
 
@@ -225,46 +235,46 @@ static VOID EmulatorBop(WORD Code)
             case BIOS_VIDEO_INTERRUPT:
             {
                 /* This is the video BIOS interrupt, call the BIOS */
-                BiosVideoService();
+                BiosVideoService(Stack);
                 break;
             }
             case BIOS_EQUIPMENT_INTERRUPT:
             {
                 /* This is the BIOS "get equipment" command, call the BIOS */
-                BiosEquipmentService();
+                BiosEquipmentService(Stack);
                 break;
             }
             case BIOS_KBD_INTERRUPT:
             {
                 /* This is the keyboard BIOS interrupt, call the BIOS */
-                BiosKeyboardService();
+                BiosKeyboardService(Stack);
                 break;
             }
             case BIOS_TIME_INTERRUPT:
             {
                 /* This is the time BIOS interrupt, call the BIOS */
-                BiosTimeService();
+                BiosTimeService(Stack);
                 break;
             }
             case BIOS_SYS_TIMER_INTERRUPT:
             {
                 /* BIOS timer update */
-                BiosSystemTimerInterrupt();
+                BiosSystemTimerInterrupt(Stack);
                 break;
             }
             case 0x20:
             {
-                DosInt20h(CodeSegment);
+                DosInt20h(Stack);
                 break;
             }
             case 0x21:
             {
-                DosInt21h(CodeSegment);
+                DosInt21h(Stack);
                 break;
             }
             case 0x23:
             {
-                DosBreakInterrupt();
+                DosBreakInterrupt(Stack);
                 break;
             }
             default:
@@ -273,13 +283,6 @@ static VOID EmulatorBop(WORD Code)
                 break;
             }
         }
-
-        /* Update the flags on the stack */
-#ifndef NEW_EMULATOR
-        Stack[3] = EmulatorContext.state->reg_flags.val;
-#else
-        Stack[3] = EmulatorContext.Flags.LowWord;
-#endif
     }
 }
 
index f1a6256..536da70 100644 (file)
 #define MAX_GDT_ENTRIES 8192
 #define EMULATOR_BOP 0xC4C4
 #define EMULATOR_INT_BOP 0xBEEF
+#define STACK_INT_NUM 0
+#define STACK_IP 1
+#define STACK_CS 2
+#define STACK_FLAGS 3
 
 enum
 {