1 |
2 |
alfik |
/*
|
2 |
|
|
* Copyright (c) 2014, Aleksander Osman
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
9 |
|
|
* list of conditions and the following disclaimer.
|
10 |
|
|
*
|
11 |
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
13 |
|
|
* and/or other materials provided with the distribution.
|
14 |
|
|
*
|
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18 |
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21 |
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
package ao486.module.memory;
|
28 |
|
|
|
29 |
|
|
import java.util.HashSet;
|
30 |
|
|
|
31 |
|
|
public class InvalidateListener implements Listener {
|
32 |
|
|
|
33 |
|
|
public interface InvalidateInterface {
|
34 |
|
|
void invdcode_finished(int cycle) throws Exception;
|
35 |
|
|
void invddata_finished(int cycle) throws Exception;
|
36 |
|
|
void wbinvddata_finished(int cycle) throws Exception;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
public void invdcode(int cycle, InvalidateInterface invalidate) throws Exception {
|
40 |
|
|
invdcode.add(cycle);
|
41 |
|
|
this.invalidate = invalidate;
|
42 |
|
|
}
|
43 |
|
|
public void invddata(int cycle, InvalidateInterface invalidate) throws Exception {
|
44 |
|
|
invddata.add(cycle);
|
45 |
|
|
this.invalidate = invalidate;
|
46 |
|
|
}
|
47 |
|
|
public void wbinvddata(int cycle, InvalidateInterface invalidate) throws Exception {
|
48 |
|
|
wbinvddata.add(cycle);
|
49 |
|
|
this.invalidate = invalidate;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
//----------------
|
53 |
|
|
|
54 |
|
|
@Override
|
55 |
|
|
public void set_input(int cycle, Input input) throws Exception {
|
56 |
|
|
if(invdcode.contains(cycle) || invdcode_active) {
|
57 |
|
|
invdcode_active = true;
|
58 |
|
|
input.invdcode_do = true;
|
59 |
|
|
}
|
60 |
|
|
if(invddata.contains(cycle) || invddata_active) {
|
61 |
|
|
invddata_active = true;
|
62 |
|
|
input.invddata_do = true;
|
63 |
|
|
}
|
64 |
|
|
if(wbinvddata.contains(cycle) || wbinvddata_active) {
|
65 |
|
|
wbinvddata_active = true;
|
66 |
|
|
input.wbinvddata_do = true;
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
@Override
|
71 |
|
|
public void get_output(int cycle, Output output) throws Exception {
|
72 |
|
|
if(output.invdcode_done) {
|
73 |
|
|
invdcode_active = false;
|
74 |
|
|
invalidate.invdcode_finished(cycle);
|
75 |
|
|
}
|
76 |
|
|
if(output.invddata_done) {
|
77 |
|
|
invddata_active = false;
|
78 |
|
|
invalidate.invddata_finished(cycle);
|
79 |
|
|
}
|
80 |
|
|
if(output.wbinvddata_done) {
|
81 |
|
|
wbinvddata_active = false;
|
82 |
|
|
invalidate.wbinvddata_finished(cycle);
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
HashSet<Integer> invdcode = new HashSet<>();
|
87 |
|
|
boolean invdcode_active;
|
88 |
|
|
|
89 |
|
|
HashSet<Integer> invddata = new HashSet<>();
|
90 |
|
|
boolean invddata_active;
|
91 |
|
|
|
92 |
|
|
HashSet<Integer> wbinvddata = new HashSet<>();
|
93 |
|
|
public boolean wbinvddata_active;
|
94 |
|
|
|
95 |
|
|
InvalidateInterface invalidate;
|
96 |
|
|
}
|