[FAST486][NTVDM]
[reactos.git] / subsystems / ntvdm / bop.c
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: bop.c
5 * PURPOSE: BIOS Operation Handlers
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #define NDEBUG
13
14 #include "emulator.h"
15 #include "bios.h"
16 #include "dos.h"
17 #include "vga.h"
18 #include "pic.h"
19 #include "ps2.h"
20 #include "timer.h"
21
22
23 LPCWSTR ExceptionName[] =
24 {
25 L"Division By Zero",
26 L"Debug",
27 L"Unexpected Error",
28 L"Breakpoint",
29 L"Integer Overflow",
30 L"Bound Range Exceeded",
31 L"Invalid Opcode",
32 L"FPU Not Available"
33 };
34
35 VOID WINAPI Exception(BYTE ExceptionNumber, LPWORD Stack)
36 {
37 WORD CodeSegment, InstructionPointer;
38
39 ASSERT(ExceptionNumber < 8);
40
41 /* Get the CS:IP */
42 InstructionPointer = Stack[STACK_IP];
43 CodeSegment = Stack[STACK_CS];
44
45 /* Display a message to the user */
46 DisplayMessage(L"Exception: %s occured at %04X:%04X",
47 ExceptionName[ExceptionNumber],
48 CodeSegment,
49 InstructionPointer);
50
51 /* Stop the VDM */
52 VdmRunning = FALSE;
53 return;
54 }
55
56 // VOID WINAPI IrqDispatch(BYTE IrqNumber, LPWORD Stack)
57 // {
58 // /* Check if this was an PIC IRQ */
59 // if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8)
60 // {
61 // /* It was an IRQ from the master PIC */
62 // BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack);
63 // }
64 // else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8)
65 // {
66 // /* It was an IRQ from the slave PIC */
67 // BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack);
68 // }
69
70 // return;
71 // }
72
73 // VOID WINAPI BiosInt(BYTE IntNumber, LPWORD Stack)
74 // {
75 // }
76
77 VOID WINAPI IntDispatch(LPWORD Stack)
78 {
79 BYTE IntNum;
80
81 /* Get the interrupt number */
82 IntNum = LOBYTE(Stack[STACK_INT_NUM]);
83
84 /* Check if this was an exception */
85 if (IntNum < 8)
86 {
87 Exception(IntNum, Stack);
88 return;
89 }
90
91 /* Check if this was an PIC IRQ */
92 if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8)
93 {
94 /* It was an IRQ from the master PIC */
95 BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack);
96 return;
97 }
98 else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8)
99 {
100 /* It was an IRQ from the slave PIC */
101 BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack);
102 return;
103 }
104
105 switch (IntNum)
106 {
107 case BIOS_VIDEO_INTERRUPT:
108 {
109 /* This is the video BIOS interrupt, call the BIOS */
110 BiosVideoService(Stack);
111 break;
112 }
113 case BIOS_EQUIPMENT_INTERRUPT:
114 {
115 /* This is the BIOS "get equipment" command, call the BIOS */
116 BiosEquipmentService(Stack);
117 break;
118 }
119 case BIOS_KBD_INTERRUPT:
120 {
121 /* This is the keyboard BIOS interrupt, call the BIOS */
122 BiosKeyboardService(Stack);
123 break;
124 }
125 case BIOS_TIME_INTERRUPT:
126 {
127 /* This is the time BIOS interrupt, call the BIOS */
128 BiosTimeService(Stack);
129 break;
130 }
131 case BIOS_SYS_TIMER_INTERRUPT:
132 {
133 /* BIOS timer update */
134 BiosSystemTimerInterrupt(Stack);
135 break;
136 }
137 case 0x20:
138 {
139 DosInt20h(Stack);
140 break;
141 }
142 case 0x21:
143 {
144 DosInt21h(Stack);
145 break;
146 }
147 case 0x23:
148 {
149 DosBreakInterrupt(Stack);
150 break;
151 }
152 default:
153 {
154 DPRINT1("Unhandled interrupt: 0x%02X\n", IntNum);
155 break;
156 }
157 }
158 }
159
160 VOID WINAPI ControlBop(LPWORD Stack)
161 {
162 IntDispatch(Stack);
163 }
164
165 /* EOF */