-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterrupts.cpp
88 lines (76 loc) · 1.5 KB
/
Interrupts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Interrupts.h"
/*
* This c'tor create the main interrupt build.
*/
Interrupts::Interrupts(MemStore* mem) {
this->_mem = mem;
}
/*
* This function help us to handle all the Interrupts by interrupt number.
* Input:
* interrupt - the number of the interrupt.
* Output: NULL.
*/
void Interrupts::interruptsHandler(unsigned int interrupt) {
//check if the interrupts flag is true
if (!_mem->_flags.IF)
return;
//check which interrupt match that number
switch (interrupt)
{
case 0:
INT_0(_mem);
break;
case 1:
INT_1(_mem);
break;
case 3:
INT_3(_mem);
break;
case 4:
INT_4(_mem);
break;
case 6:
INT_6(_mem);
break;
case 12:
INT_12(_mem);
break;
case 22:
INT_22(_mem);
break;
default:
throw Error("IntError - Interrupt not found");
break;
}
}
/* Interrupt 0 */
void Interrupts::INT_0(MemStore* mem) {
throw Error("DivideError - Divide by zero");
}
/* Interrupt 1 */
void Interrupts::INT_1(MemStore* mem) {
system("pause");
}
/* Interrupt 3 */
void Interrupts::INT_3(MemStore* mem) {
system("pause");
}
/* Interrupt 4 */
void Interrupts::INT_4(MemStore* mem) {
mem->_flags.OF = true;
throw Error("MemoryError - Overflow");
}
/* Interrupt 6 */
void Interrupts::INT_6(MemStore* mem) {
throw Error("OpcodeError - opcode not found.");
}
/* Interrupt 12 */
void Interrupts::INT_12(MemStore* mem) {
mem->_flags.OF = true;
throw StackError("MemoryError - Stack Overflow");
}
/* Interrupt 22 */
void Interrupts::INT_22(MemStore* mem) {
mem->setRegister(AH, _getch());
}