2013-06-17 00:00:36 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Virtual DOS Machine
|
|
|
|
* FILE: emulator.c
|
|
|
|
* PURPOSE: Minimal x86 machine emulator for the VDM
|
|
|
|
* PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
2013-07-22 13:51:26 +00:00
|
|
|
#define NDEBUG
|
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
#include "emulator.h"
|
|
|
|
#include "bios.h"
|
|
|
|
#include "dos.h"
|
2013-08-05 23:20:25 +00:00
|
|
|
#include "vga.h"
|
2013-06-26 22:58:41 +00:00
|
|
|
#include "pic.h"
|
|
|
|
#include "ps2.h"
|
|
|
|
#include "timer.h"
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
/* PRIVATE VARIABLES **********************************************************/
|
|
|
|
|
2013-10-19 16:55:51 +00:00
|
|
|
FAST486_STATE EmulatorContext;
|
2013-07-07 20:53:23 +00:00
|
|
|
|
2013-06-26 17:15:45 +00:00
|
|
|
static BOOLEAN A20Line = FALSE;
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
2013-10-26 20:48:31 +00:00
|
|
|
static VOID WINAPI EmulatorReadMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT Size)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-08-07 19:56:28 +00:00
|
|
|
UNREFERENCED_PARAMETER(Context);
|
|
|
|
|
2013-06-26 17:15:45 +00:00
|
|
|
/* If the A20 line is disabled, mask bit 20 */
|
|
|
|
if (!A20Line) Address &= ~(1 << 20);
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
/* Make sure the requested address is valid */
|
|
|
|
if ((Address + Size) >= MAX_ADDRESS) return;
|
|
|
|
|
|
|
|
/* Read the data from the virtual address space and store it in the buffer */
|
|
|
|
RtlCopyMemory(Buffer, (LPVOID)((ULONG_PTR)BaseAddress + Address), Size);
|
2013-08-05 23:20:25 +00:00
|
|
|
|
|
|
|
/* Check if we modified the console video memory */
|
|
|
|
if (((Address + Size) >= VgaGetVideoBaseAddress())
|
|
|
|
&& (Address < VgaGetVideoLimitAddress()))
|
|
|
|
{
|
|
|
|
DWORD VgaAddress = max(Address, VgaGetVideoBaseAddress());
|
|
|
|
LPBYTE VgaBuffer = &Buffer[VgaAddress - Address];
|
|
|
|
|
|
|
|
/* Read from the VGA memory */
|
|
|
|
VgaReadMemory(VgaAddress, VgaBuffer, Size);
|
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-26 20:48:31 +00:00
|
|
|
static VOID WINAPI EmulatorWriteMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT Size)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-08-07 19:56:28 +00:00
|
|
|
UNREFERENCED_PARAMETER(Context);
|
|
|
|
|
2013-06-26 17:15:45 +00:00
|
|
|
/* If the A20 line is disabled, mask bit 20 */
|
|
|
|
if (!A20Line) Address &= ~(1 << 20);
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
/* Make sure the requested address is valid */
|
|
|
|
if ((Address + Size) >= MAX_ADDRESS) return;
|
|
|
|
|
|
|
|
/* Make sure we don't write to the ROM area */
|
|
|
|
if ((Address + Size) >= ROM_AREA_START && (Address < ROM_AREA_END)) return;
|
|
|
|
|
|
|
|
/* Read the data from the buffer and store it in the virtual address space */
|
|
|
|
RtlCopyMemory((LPVOID)((ULONG_PTR)BaseAddress + Address), Buffer, Size);
|
|
|
|
|
|
|
|
/* Check if we modified the console video memory */
|
2013-08-05 23:20:25 +00:00
|
|
|
if (((Address + Size) >= VgaGetVideoBaseAddress())
|
|
|
|
&& (Address < VgaGetVideoLimitAddress()))
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-08-05 23:20:25 +00:00
|
|
|
DWORD VgaAddress = max(Address, VgaGetVideoBaseAddress());
|
|
|
|
LPBYTE VgaBuffer = &Buffer[VgaAddress - Address];
|
|
|
|
|
|
|
|
/* Write to the VGA memory */
|
|
|
|
VgaWriteMemory(VgaAddress, VgaBuffer, Size);
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 20:48:31 +00:00
|
|
|
static VOID WINAPI EmulatorReadIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-08-07 19:56:28 +00:00
|
|
|
UNREFERENCED_PARAMETER(Context);
|
|
|
|
UNREFERENCED_PARAMETER(Size);
|
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
switch (Address)
|
|
|
|
{
|
|
|
|
case PIC_MASTER_CMD:
|
|
|
|
case PIC_SLAVE_CMD:
|
|
|
|
{
|
|
|
|
*Buffer = PicReadCommand(Address);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-23 00:11:45 +00:00
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
case PIC_MASTER_DATA:
|
|
|
|
case PIC_SLAVE_DATA:
|
|
|
|
{
|
|
|
|
*Buffer = PicReadData(Address);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-26 17:15:45 +00:00
|
|
|
|
|
|
|
case PIT_DATA_PORT(0):
|
|
|
|
case PIT_DATA_PORT(1):
|
|
|
|
case PIT_DATA_PORT(2):
|
|
|
|
{
|
|
|
|
*Buffer = PitReadData(Address - PIT_DATA_PORT(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PS2_CONTROL_PORT:
|
|
|
|
{
|
|
|
|
*Buffer = KeyboardReadStatus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PS2_DATA_PORT:
|
|
|
|
{
|
|
|
|
*Buffer = KeyboardReadData();
|
|
|
|
break;
|
|
|
|
}
|
2013-07-23 21:43:57 +00:00
|
|
|
|
2013-08-05 23:20:25 +00:00
|
|
|
case VGA_AC_WRITE:
|
|
|
|
case VGA_AC_READ:
|
|
|
|
case VGA_SEQ_INDEX:
|
|
|
|
case VGA_SEQ_DATA:
|
|
|
|
case VGA_DAC_READ_INDEX:
|
|
|
|
case VGA_DAC_WRITE_INDEX:
|
|
|
|
case VGA_DAC_DATA:
|
|
|
|
case VGA_MISC_READ:
|
|
|
|
case VGA_MISC_WRITE:
|
|
|
|
case VGA_CRTC_INDEX:
|
|
|
|
case VGA_CRTC_DATA:
|
|
|
|
case VGA_GC_INDEX:
|
|
|
|
case VGA_GC_DATA:
|
|
|
|
case VGA_STAT_MONO:
|
|
|
|
case VGA_STAT_COLOR:
|
|
|
|
{
|
|
|
|
*Buffer = VgaReadPort(Address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-23 21:43:57 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("Read from unknown port: 0x%X\n", Address);
|
|
|
|
}
|
2013-06-21 00:47:07 +00:00
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-26 20:48:31 +00:00
|
|
|
static VOID WINAPI EmulatorWriteIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-06-21 00:47:07 +00:00
|
|
|
BYTE Byte = *Buffer;
|
2013-06-23 00:11:45 +00:00
|
|
|
|
2013-08-07 19:56:28 +00:00
|
|
|
UNREFERENCED_PARAMETER(Context);
|
|
|
|
UNREFERENCED_PARAMETER(Size);
|
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
switch (Address)
|
|
|
|
{
|
|
|
|
case PIT_COMMAND_PORT:
|
|
|
|
{
|
|
|
|
PitWriteCommand(Byte);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-23 00:11:45 +00:00
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
case PIT_DATA_PORT(0):
|
|
|
|
case PIT_DATA_PORT(1):
|
|
|
|
case PIT_DATA_PORT(2):
|
|
|
|
{
|
|
|
|
PitWriteData(Address - PIT_DATA_PORT(0), Byte);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-23 00:11:45 +00:00
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
case PIC_MASTER_CMD:
|
|
|
|
case PIC_SLAVE_CMD:
|
|
|
|
{
|
|
|
|
PicWriteCommand(Address, Byte);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-23 00:11:45 +00:00
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
case PIC_MASTER_DATA:
|
|
|
|
case PIC_SLAVE_DATA:
|
|
|
|
{
|
|
|
|
PicWriteData(Address, Byte);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-26 17:15:45 +00:00
|
|
|
|
|
|
|
case PS2_CONTROL_PORT:
|
|
|
|
{
|
|
|
|
KeyboardWriteCommand(Byte);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PS2_DATA_PORT:
|
|
|
|
{
|
|
|
|
KeyboardWriteData(Byte);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-23 21:43:57 +00:00
|
|
|
|
2013-08-05 23:20:25 +00:00
|
|
|
case VGA_AC_WRITE:
|
|
|
|
case VGA_AC_READ:
|
|
|
|
case VGA_SEQ_INDEX:
|
|
|
|
case VGA_SEQ_DATA:
|
|
|
|
case VGA_DAC_READ_INDEX:
|
|
|
|
case VGA_DAC_WRITE_INDEX:
|
|
|
|
case VGA_DAC_DATA:
|
|
|
|
case VGA_MISC_READ:
|
|
|
|
case VGA_MISC_WRITE:
|
|
|
|
case VGA_CRTC_INDEX:
|
|
|
|
case VGA_CRTC_DATA:
|
|
|
|
case VGA_GC_INDEX:
|
|
|
|
case VGA_GC_DATA:
|
|
|
|
case VGA_STAT_MONO:
|
|
|
|
case VGA_STAT_COLOR:
|
|
|
|
{
|
|
|
|
VgaWritePort(Address, Byte);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-23 21:43:57 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("Write to unknown port: 0x%X\n", Address);
|
|
|
|
}
|
2013-06-21 00:47:07 +00:00
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-26 20:48:31 +00:00
|
|
|
static VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, WORD Code)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
|
|
|
WORD StackSegment, StackPointer, CodeSegment, InstructionPointer;
|
|
|
|
BYTE IntNum;
|
2013-07-23 19:31:00 +00:00
|
|
|
LPWORD Stack;
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-07-23 19:31:00 +00:00
|
|
|
/* Get the SS:SP */
|
2013-10-26 20:48:31 +00:00
|
|
|
StackSegment = State->SegmentRegs[FAST486_REG_SS].Selector;
|
|
|
|
StackPointer = State->GeneralRegs[FAST486_REG_ESP].LowWord;
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-07-23 19:31:00 +00:00
|
|
|
/* Get the stack */
|
|
|
|
Stack = (LPWORD)((ULONG_PTR)BaseAddress + TO_LINEAR(StackSegment, StackPointer));
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-07-23 19:31:00 +00:00
|
|
|
if (Code == EMULATOR_INT_BOP)
|
|
|
|
{
|
|
|
|
/* Get the interrupt number */
|
2013-07-23 21:43:57 +00:00
|
|
|
IntNum = LOBYTE(Stack[STACK_INT_NUM]);
|
2013-06-17 00:00:36 +00:00
|
|
|
|
|
|
|
/* Get the CS:IP */
|
2013-07-23 21:43:57 +00:00
|
|
|
InstructionPointer = Stack[STACK_IP];
|
|
|
|
CodeSegment = Stack[STACK_CS];
|
2013-06-17 00:00:36 +00:00
|
|
|
|
|
|
|
/* Check if this was an exception */
|
|
|
|
if (IntNum < 8)
|
|
|
|
{
|
|
|
|
/* Display a message to the user */
|
|
|
|
DisplayMessage(L"Exception: %s occured at %04X:%04X",
|
|
|
|
ExceptionName[IntNum],
|
|
|
|
CodeSegment,
|
|
|
|
InstructionPointer);
|
|
|
|
|
|
|
|
/* Stop the VDM */
|
|
|
|
VdmRunning = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-23 00:11:45 +00:00
|
|
|
|
2013-06-21 00:47:07 +00:00
|
|
|
/* Check if this was an PIC IRQ */
|
|
|
|
if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8)
|
|
|
|
{
|
|
|
|
/* It was an IRQ from the master PIC */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack);
|
2013-06-29 21:37:44 +00:00
|
|
|
return;
|
2013-06-21 00:47:07 +00:00
|
|
|
}
|
|
|
|
else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8)
|
|
|
|
{
|
|
|
|
/* It was an IRQ from the slave PIC */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack);
|
2013-06-29 21:37:44 +00:00
|
|
|
return;
|
2013-06-21 00:47:07 +00:00
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
|
|
|
|
switch (IntNum)
|
|
|
|
{
|
2013-06-29 21:37:44 +00:00
|
|
|
case BIOS_VIDEO_INTERRUPT:
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
|
|
|
/* This is the video BIOS interrupt, call the BIOS */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosVideoService(Stack);
|
2013-06-17 00:00:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-02 02:08:30 +00:00
|
|
|
case BIOS_EQUIPMENT_INTERRUPT:
|
|
|
|
{
|
|
|
|
/* This is the BIOS "get equipment" command, call the BIOS */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosEquipmentService(Stack);
|
2013-07-02 02:08:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-29 21:37:44 +00:00
|
|
|
case BIOS_KBD_INTERRUPT:
|
2013-06-28 20:52:40 +00:00
|
|
|
{
|
|
|
|
/* This is the keyboard BIOS interrupt, call the BIOS */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosKeyboardService(Stack);
|
2013-06-28 20:52:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-29 21:37:44 +00:00
|
|
|
case BIOS_TIME_INTERRUPT:
|
|
|
|
{
|
|
|
|
/* This is the time BIOS interrupt, call the BIOS */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosTimeService(Stack);
|
2013-06-29 21:37:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-05 01:31:50 +00:00
|
|
|
case BIOS_SYS_TIMER_INTERRUPT:
|
|
|
|
{
|
|
|
|
/* BIOS timer update */
|
2013-07-23 21:43:57 +00:00
|
|
|
BiosSystemTimerInterrupt(Stack);
|
2013-07-05 01:31:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
case 0x20:
|
|
|
|
{
|
2013-07-23 21:43:57 +00:00
|
|
|
DosInt20h(Stack);
|
2013-06-17 00:00:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x21:
|
|
|
|
{
|
2013-07-23 21:43:57 +00:00
|
|
|
DosInt21h(Stack);
|
2013-06-17 00:00:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x23:
|
|
|
|
{
|
2013-07-23 21:43:57 +00:00
|
|
|
DosBreakInterrupt(Stack);
|
2013-06-17 00:00:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-29 21:37:44 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
DPRINT1("Unhandled interrupt: 0x%02X\n", IntNum);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 00:37:01 +00:00
|
|
|
static BYTE WINAPI EmulatorIntAcknowledge(PFAST486_STATE State)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(State);
|
|
|
|
|
|
|
|
/* Get the interrupt number from the PIC */
|
|
|
|
return PicGetInterrupt();
|
|
|
|
}
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
BOOLEAN EmulatorInitialize()
|
|
|
|
{
|
|
|
|
/* Allocate memory for the 16-bit address space */
|
2013-07-02 02:08:30 +00:00
|
|
|
BaseAddress = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_ADDRESS);
|
2013-06-17 00:00:36 +00:00
|
|
|
if (BaseAddress == NULL) return FALSE;
|
|
|
|
|
2013-08-31 19:18:12 +00:00
|
|
|
/* Set the callbacks */
|
2013-10-19 16:55:51 +00:00
|
|
|
EmulatorContext.MemReadCallback = (FAST486_MEM_READ_PROC)EmulatorReadMemory;
|
|
|
|
EmulatorContext.MemWriteCallback = (FAST486_MEM_WRITE_PROC)EmulatorWriteMemory;
|
|
|
|
EmulatorContext.IoReadCallback = (FAST486_IO_READ_PROC)EmulatorReadIo;
|
|
|
|
EmulatorContext.IoWriteCallback = (FAST486_IO_WRITE_PROC)EmulatorWriteIo;
|
2013-10-27 00:37:01 +00:00
|
|
|
EmulatorContext.BopCallback = EmulatorBiosOperation;
|
|
|
|
EmulatorContext.IntAckCallback = EmulatorIntAcknowledge;
|
2013-08-31 19:18:12 +00:00
|
|
|
|
|
|
|
/* Reset the CPU */
|
2013-10-19 16:55:51 +00:00
|
|
|
Fast486Reset(&EmulatorContext);
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-06-26 17:15:45 +00:00
|
|
|
/* Enable interrupts */
|
|
|
|
EmulatorSetFlag(EMULATOR_FLAG_IF);
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-08-09 23:52:08 +00:00
|
|
|
VOID EmulatorSetStack(WORD Segment, DWORD Offset)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-10-19 16:55:51 +00:00
|
|
|
Fast486SetStack(&EmulatorContext, Segment, Offset);
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-08-31 19:18:12 +00:00
|
|
|
// FIXME: This function assumes 16-bit mode!!!
|
2013-06-17 00:00:36 +00:00
|
|
|
VOID EmulatorExecute(WORD Segment, WORD Offset)
|
|
|
|
{
|
2013-10-19 16:55:51 +00:00
|
|
|
/* Tell Fast486 to move the instruction pointer */
|
|
|
|
Fast486ExecuteAt(&EmulatorContext, Segment, Offset);
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID EmulatorInterrupt(BYTE Number)
|
|
|
|
{
|
2013-10-19 16:55:51 +00:00
|
|
|
/* Call the Fast486 API */
|
|
|
|
Fast486Interrupt(&EmulatorContext, Number);
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-27 00:37:01 +00:00
|
|
|
VOID EmulatorInterruptSignal(VOID)
|
2013-06-26 17:15:45 +00:00
|
|
|
{
|
2013-10-19 16:55:51 +00:00
|
|
|
/* Call the Fast486 API */
|
2013-10-27 00:37:01 +00:00
|
|
|
Fast486InterruptSignal(&EmulatorContext);
|
2013-06-26 17:15:45 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
ULONG EmulatorGetRegister(ULONG Register)
|
|
|
|
{
|
2013-08-16 19:33:04 +00:00
|
|
|
if (Register < EMULATOR_REG_ES)
|
|
|
|
{
|
|
|
|
return EmulatorContext.GeneralRegs[Register].Long;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return EmulatorContext.SegmentRegs[Register - EMULATOR_REG_ES].Selector;
|
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 23:52:08 +00:00
|
|
|
ULONG EmulatorGetProgramCounter(VOID)
|
|
|
|
{
|
2013-08-16 19:33:04 +00:00
|
|
|
return EmulatorContext.InstPtr.Long;
|
2013-08-09 23:52:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
VOID EmulatorSetRegister(ULONG Register, ULONG Value)
|
|
|
|
{
|
2013-10-09 21:48:52 +00:00
|
|
|
if (Register < EMULATOR_REG_ES)
|
|
|
|
{
|
|
|
|
EmulatorContext.GeneralRegs[Register].Long = Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-19 16:55:51 +00:00
|
|
|
Fast486SetSegment(&EmulatorContext, Register - EMULATOR_REG_ES, (USHORT)Value);
|
2013-10-09 21:48:52 +00:00
|
|
|
}
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN EmulatorGetFlag(ULONG Flag)
|
|
|
|
{
|
2013-07-07 20:53:23 +00:00
|
|
|
return (EmulatorContext.Flags.Long & Flag) ? TRUE : FALSE;
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID EmulatorSetFlag(ULONG Flag)
|
|
|
|
{
|
2013-07-07 20:53:23 +00:00
|
|
|
EmulatorContext.Flags.Long |= Flag;
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID EmulatorClearFlag(ULONG Flag)
|
|
|
|
{
|
2013-07-07 20:53:23 +00:00
|
|
|
EmulatorContext.Flags.Long &= ~Flag;
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 19:31:00 +00:00
|
|
|
VOID EmulatorStep(VOID)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-08-31 19:18:12 +00:00
|
|
|
/* Dump the state for debugging purposes */
|
2013-10-19 16:55:51 +00:00
|
|
|
// Fast486DumpState(&EmulatorContext);
|
2013-08-31 19:18:12 +00:00
|
|
|
|
|
|
|
/* Execute the next instruction */
|
2013-10-19 16:55:51 +00:00
|
|
|
Fast486StepInto(&EmulatorContext);
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 19:31:00 +00:00
|
|
|
VOID EmulatorCleanup(VOID)
|
2013-06-17 00:00:36 +00:00
|
|
|
{
|
2013-08-06 20:01:05 +00:00
|
|
|
/* Free the memory allocated for the 16-bit address space */
|
|
|
|
if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress);
|
2013-06-17 00:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 17:15:45 +00:00
|
|
|
VOID EmulatorSetA20(BOOLEAN Enabled)
|
|
|
|
{
|
|
|
|
A20Line = Enabled;
|
|
|
|
}
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
/* EOF */
|