mirror of https://github.com/rusefi/RomRaider.git
fix bitwise switch when not all checkboxes are on screen
This commit is contained in:
parent
fcbfc85327
commit
2b0ea46757
|
@ -33,6 +33,8 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JTextArea;
|
||||
|
||||
import com.romraider.Settings;
|
||||
import com.romraider.util.ByteUtil;
|
||||
|
||||
import static com.romraider.util.ByteUtil.isBitSet;
|
||||
|
||||
public class TableBitwiseSwitch extends Table {
|
||||
|
@ -89,23 +91,30 @@ public class TableBitwiseSwitch extends Table {
|
|||
|
||||
@Override
|
||||
public byte[] saveFile(byte[] input) {
|
||||
|
||||
boolean[] bools = new boolean[8];
|
||||
// get original values
|
||||
boolean[] bools = ByteUtil.byteToBoolArr(input[storageAddress]);
|
||||
// invert original values because input checboxes are in reverse order
|
||||
for(int i=0; i<bools.length/2; i++){
|
||||
boolean temp = bools[i];
|
||||
bools[i] = bools[bools.length -i -1];
|
||||
bools[bools.length -i -1] = temp;
|
||||
}
|
||||
// set to new state from checkboxes, in reverse order
|
||||
for (Entry<String, Integer> entry: controlBits.entrySet()) {
|
||||
JCheckBox cb = getButtonByText(entry.getKey());
|
||||
bools[entry.getValue()] = cb.isSelected();
|
||||
}
|
||||
// reverse back the array so it is correct representation of byte
|
||||
for(int i=0; i<bools.length/2; i++){
|
||||
boolean temp = bools[i];
|
||||
bools[i] = bools[bools.length -i -1];
|
||||
bools[bools.length -i -1] = temp;
|
||||
}
|
||||
|
||||
int bits = 0;
|
||||
for (int i = 0; i < bools.length; i++) {
|
||||
if (bools[i])
|
||||
bits |= 1 << i;
|
||||
}
|
||||
|
||||
input[storageAddress] = (byte) bits;
|
||||
input[storageAddress] = ByteUtil.booleanArrayToBit(bools);
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
public void setValues(String name, String input) {
|
||||
controlBits.put(name, Integer.parseInt(input));
|
||||
}
|
||||
|
|
|
@ -104,6 +104,21 @@ public final class ByteUtil {
|
|||
return (b & 1 << position) != 0;
|
||||
}
|
||||
|
||||
public static boolean[] byteToBoolArr(byte b) {
|
||||
boolean boolArr[] = new boolean[8];
|
||||
for(int i=0;i<8;i++) boolArr[i] = (b & (byte)(128 / Math.pow(2, i))) != 0;
|
||||
return boolArr;
|
||||
}
|
||||
|
||||
public static byte booleanArrayToBit(boolean[] arr){
|
||||
byte val = 0;
|
||||
for (boolean b: arr) {
|
||||
val <<= 1;
|
||||
if (b) val |= 1;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
private static int[] computeFailure(byte[] pattern) {
|
||||
int[] failure = new int[pattern.length];
|
||||
int j = 0;
|
||||
|
|
Loading…
Reference in New Issue