Kill mega-sena.sh
[lcapit-junk-code.git] / emu8086 / src / ProcStatus.java
blob21a6c582a3c178b27ccd2c1718e49dc802e03061
1 import java.io.*;
3 /**
4 * Stores 8086 registers and flags status.
5 *
6 * @author Luiz Fernando N. Capitulino
7 */
8 public class ProcStatus implements Serializable {
9 /**
10 * All registers contents.
12 private int[] registers;
14 /**
15 * flags register contents.
17 private boolean[] flags_register;
19 /**
20 * Write all flags registers contents to stdout.
22 public void dump_flags()
24 String[] flag_names = { "AF", "CF", "DF", "IF",
25 "OF", "PF", "SF", "ZF" };
26 StringBuilder result = new StringBuilder();
27 result.append("[FLAGS] ");
29 for (int i = 0; i < flag_names.length; i++) {
30 result.append(flag_names[i] + ": ");
31 if (flags_register[i])
32 result.append("1 ");
33 else
34 result.append("0 ");
37 System.out.println(result.toString());
40 /**
41 * Write all registers (except flags) contents to stdout.
43 public void dump_registers()
45 String[] reg_names = { "AX", "AH", "AL",
46 "CX", "CH", "CL",
47 "DX", "DH", "DL",
48 "BX", "BH", "BL",
49 "SI", "DI", "ES",
50 "SP", "BP", "SS",
51 "IP", "CS", "DS" };
52 StringBuilder result = new StringBuilder();
54 result.append("[REGS]\n");
55 for (int i = 0; i < reg_names.length; i++) {
56 result.append(reg_names[i] + ": ");
57 result.append("0x" + Integer.toHexString(registers[i]));
58 if ((i % 3) == 2)
59 result.append('\n');
60 else
61 result.append(" ");
64 System.out.print(result.toString());
67 /**
68 * Set register's contents.
70 * @param reg Registers to set the content
71 * @param value Content
73 public void setRegister(Reg8086 reg, int value)
75 registers[reg.ordinal()] = value;
78 /**
79 * Get register contents.
81 * @param reg Register to get the content
82 * @return Register's content
84 public int getRegister(Reg8086 reg)
86 return registers[reg.ordinal()];
89 /**
90 * Set a 16-bit register and its high and low byte
92 * @param reg register to be set
93 * @param value value to set
94 * @throws InvalidRegisterException
96 public void setRegister_X(Reg8086 reg, int value) throws InvalidRegisterException
98 // set 16-bit value
99 setRegister(reg, value);
101 // set 8-bit high byte
102 int high = (value & 0xFF00) >> 8;
103 Reg8086 regh = Reg8086.convert(reg.ordinal() + 1);
104 setRegister(regh, high);
106 // set 8-bit low byte
107 int low = value & 0xFF;
108 Reg8086 regl = Reg8086.convert(reg.ordinal() + 2);
109 setRegister(regl, low);
113 * Set a 8-bit "high" register and its X
115 * @param reg register to be set
116 * @param value value to set
117 * @throws InvalidRegisterException
119 public void setRegister_H(Reg8086 reg, int value) throws InvalidRegisterException
121 // set 8-bit high byte
122 setRegister(reg, value);
124 // set 16-bit value
125 Reg8086 regx = Reg8086.convert(reg.ordinal() - 1);
126 setRegister(regx, value);
130 * Set a 8-bit "low" register and its X
132 * @param reg register to be set
133 * @param value value to set
134 * @throws InvalidRegisterException
136 public void setRegister_L(Reg8086 reg, int value) throws InvalidRegisterException
138 // set 8-bit low byte
139 setRegister(reg, value);
141 // set 16-bit value
142 Reg8086 regx = Reg8086.convert(reg.ordinal() - 2);
143 setRegister(regx, value);
147 * Set flags register flag.
149 * @param flag flag to set.
151 public void setFlags(RegFlags flag)
153 flags_register[flag.ordinal()] = true;
157 * Unset flags register flag.
159 * @param flag flag to unset.
161 public void unsetFlags(RegFlags flag)
163 flags_register[flag.ordinal()] = false;
167 * Get flags register flag.
169 * @param flag flag to get.
170 * @return Flag content.
172 public boolean getFlag(RegFlags flag)
174 return flags_register[flag.ordinal()];
178 * Constructor.
180 public ProcStatus()
182 registers = new int[21];
183 flags_register = new boolean[8];