Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight read #34

Merged
merged 9 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Settings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AssembleAll = false
AssembleOnOpen = false
BareMachine = false
DataSegmentHighlighting = true
ExplicitWriteHighlighting = true
DelayedBranching = false
DisplayAddressesInHex = true
DisplayValuesInHex = true
Expand All @@ -13,7 +13,7 @@ ExtendedAssembler = true
LabelWindowVisibility = false
LoadExceptionHandler = false
ProgramArguments = false
RegistersHighlighting = true
ExplicitReadHighlighting = true
StartAtMain = false
WarningsAreErrors = false
PopupInstructionGuidance = true
Expand All @@ -26,8 +26,8 @@ TextSegmentHighlightBackground = 0x00ffff99
TextSegmentHighlightForeground = 0
TextSegmentDelaySlotHighlightBackground = 0x33ff00
TextSegmentDelaySlotHighlightForeground = 0
DataSegmentHighlightBackground = 0x0099ccff
DataSegmentHighlightForeground = 0
RegisterHighlightBackground = 0x0099cc55
RegisterHighlightForeground = 0
ExplicitWriteHighlightBackground = 0x00ff8080
ExplicitWriteHighlightForeground = 0
ExplicitReadHighlightBackground = 0x0099ccff
ExplicitReadHighlightForeground = 0
DeriveCurrentDirectory = false
44 changes: 22 additions & 22 deletions src/rars/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public enum Bool {
*/
PROGRAM_ARGUMENTS("ProgramArguments", false),
/**
* Flag to control whether or not highlighting is applied to data segment window
* Flag to control whether or not highlighting is applied when explicit writing
*/
DATA_SEGMENT_HIGHLIGHTING("DataSegmentHighlighting", true),
EXPLICIT_WRITE_HIGHLIGHTING("ExplicitWriteHighlighting", true),
/**
* Flag to control whether or not highlighting is applied to register windows
* Flag to control whether or not highlighting is applied when explicit reading
*/
REGISTERS_HIGHLIGHTING("RegistersHighlighting", true),
EXPLICIT_READ_HIGHLIGHTING("ExplicitReadHighlighting", true),
/**
* Flag to control whether or not assembler automatically initializes program counter to 'main's address
*/
Expand Down Expand Up @@ -244,25 +244,25 @@ String getName() {
*/
public static final int TEXTSEGMENT_DELAYSLOT_HIGHLIGHT_FONT = 4;
/**
* Font for text segment highlighted background
* Font for data segment highlighted background
*/
public static final int DATASEGMENT_HIGHLIGHT_FONT = 5;
public static final int EXPLICIT_WRITE_HIGHLIGHT_FONT = 5;
/**
* Font for register highlighted background
* Font for data segment highlighted background
*/
public static final int REGISTER_HIGHLIGHT_FONT = 6;
public static final int EXPLICIT_READ_HIGHLIGHT_FONT = 6;

private static final String[] fontFamilySettingsKeys = {"EditorFontFamily", "EvenRowFontFamily",
"OddRowFontFamily", " TextSegmentHighlightFontFamily", "TextSegmentDelayslotHighightFontFamily",
"DataSegmentHighlightFontFamily", "RegisterHighlightFontFamily"
"ExplicitWriteHighlightFontFamily","ExplicitReadHighlightFontFamily"
};
private static final String[] fontStyleSettingsKeys = {"EditorFontStyle", "EvenRowFontStyle",
"OddRowFontStyle", " TextSegmentHighlightFontStyle", "TextSegmentDelayslotHighightFontStyle",
"DataSegmentHighlightFontStyle", "RegisterHighlightFontStyle"
"ExplicitWriteHighlightFontStyle", "ExplicitWriteHighlightFontStyle"
};
private static final String[] fontSizeSettingsKeys = {"EditorFontSize", "EvenRowFontSize",
"OddRowFontSize", " TextSegmentHighlightFontSize", "TextSegmentDelayslotHighightFontSize",
"DataSegmentHighlightFontSize", "RegisterHighlightFontSize"
"ExplicitWriteHighlightFontSize", "ExplicitWriteHighlightFontSize"
};


Expand Down Expand Up @@ -321,21 +321,21 @@ String getName() {
*/
public static final int TEXTSEGMENT_DELAYSLOT_HIGHLIGHT_FOREGROUND = 7;
/**
* RGB color for text segment highlighted background
* RGB color for highlighted background when explicitly writing data
*/
public static final int DATASEGMENT_HIGHLIGHT_BACKGROUND = 8;
public static final int EXPLICIT_WRITE_HIGHLIGHT_BACKGROUND = 8;
/**
* RGB color for text segment highlighted foreground
* RGB color for highlighted foreground when explicitly writing data
*/
public static final int DATASEGMENT_HIGHLIGHT_FOREGROUND = 9;
public static final int EXPLICIT_WRITE_HIGHLIGHT_FOREGROUND = 9;
/**
* RGB color for register highlighted background
* RGB color for highlighted background when explicitly reading data
*/
public static final int REGISTER_HIGHLIGHT_BACKGROUND = 10;
public static final int EXPLICIT_READ_HIGHLIGHT_BACKGROUND = 10;
/**
* RGB color for register highlighted foreground
* RGB color for highlighted foreground when explicitly reading data
*/
public static final int REGISTER_HIGHLIGHT_FOREGROUND = 11;
public static final int EXPLICIT_READ_HIGHLIGHT_FOREGROUND = 11;
/**
* RGB background color of Editor
*/
Expand Down Expand Up @@ -371,8 +371,8 @@ public enum ColorMode {
"EvenRowBackground", "EvenRowForeground", "OddRowBackground", "OddRowForeground",
"TextSegmentHighlightBackground", "TextSegmentHighlightForeground",
"TextSegmentDelaySlotHighlightBackground", "TextSegmentDelaySlotHighlightForeground",
"DataSegmentHighlightBackground", "DataSegmentHighlightForeground",
"RegisterHighlightBackground", "RegisterHighlightForeground",
"ExplicitWriteHighlightBackground", "ExplicitWriteHighlightForeground",
"ExplicitReadHighlightBackground", "ExplicitReadHighlightForeground",
"EditorBackground", "EditorForeground", "EditorLineHighlight", "EditorSelection", "EditorCaretColor"};
/**
* Last resort default values for color settings;
Expand All @@ -381,7 +381,7 @@ public enum ColorMode {
* Must match key by list position.
*/
private static String[] defaultColorSettingsValues = {
"0x00e0e0e0", "0", "0x00ffffff", "0", "0x00ffff99", "0", "0x0033ff00", "0", "0x0099ccff", "0", "0x0099cc55", "0", "0x00ffffff", "0x00000000", "0x00eeeeee", "0x00ccccff", "0x00000000"};
"0x00e0e0e0", "0", "0x00ffffff", "0", "0x00ffff99", "0", "0x0033ff00", "0", "0x00ff8080", "0", "0x0099ccff","0", "0x00ffffff", "0x00000000", "0x00eeeeee", "0x00ccccff", "0x00000000"};

interface SystemColorProvider { Color getColor();}
private SystemColorProvider[] systemColors;
Expand Down
10 changes: 10 additions & 0 deletions src/rars/riscv/hardware/RegisterBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public long getValue(int num) {
return getRegister(num).getValue();
}

/**
* Returns the value of the register. Observers are not notified.
*
* @param num The register's number.
* @return value The value of the given register.
*/
public long getValueNoNotify(int num) {
return getRegister(num).getValueNoNotify();
}

/**
* Returns the value of the register.
*
Expand Down
11 changes: 11 additions & 0 deletions src/rars/riscv/hardware/RegisterFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public static int getValue(int num) {

}

/**
* Returns the value of the register. Observers are not notified.
*
* @param num The register's number.
* @return value The value of the given register.
*/
public static int getValueNoNotify(int num) {
return (int) instance.getValueNoNotify(num);

}

/**
* Returns the value of the register.
*
Expand Down
32 changes: 24 additions & 8 deletions src/rars/venus/DataSegmentWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class DataSegmentWindow extends JInternalFrame implements Observer {
private static final boolean KERNEL_MODE = true;

private boolean addressHighlighting = false;
private boolean writingHighlight = false;
private boolean asciiDisplay = false;
private int addressRow, addressColumn, addressRowFirstAddress;
private Settings settings;
Expand Down Expand Up @@ -118,6 +119,7 @@ public DataSegmentWindow(NumberDisplayBaseChooser[] choosers) {
firstAddress = homeAddress; // first address to display at any given time
userOrKernelMode = USER_MODE;
addressHighlighting = false;
writingHighlight = false;
contentPane = this.getContentPane();
tablePanel = new JPanel(new GridLayout(1, 2, 10, 0));
JPanel features = new JPanel();
Expand Down Expand Up @@ -411,7 +413,7 @@ private int getBaseAddressIndexForAddress(int address) {
desiredComboBoxIndex = EXTERN_BASE_ADDRESS_INDEX;
}
// Check distance from global pointer; can be either side of it...
thisDistance = Math.abs(address - RegisterFile.getValue(RegisterFile.GLOBAL_POINTER_REGISTER)); // distance from global pointer
thisDistance = Math.abs(address - RegisterFile.getValueNoNotify(RegisterFile.GLOBAL_POINTER_REGISTER)); // distance from global pointer
if (thisDistance < shortDistance) {
shortDistance = thisDistance;
desiredComboBoxIndex = GLOBAL_POINTER_ADDRESS_INDEX;
Expand All @@ -429,7 +431,7 @@ private int getBaseAddressIndexForAddress(int address) {
desiredComboBoxIndex = HEAP_BASE_ADDRESS_INDEX;
}
// Check distance from stack pointer. Can be on either side of it...
thisDistance = Math.abs(address - RegisterFile.getValue(RegisterFile.STACK_POINTER_REGISTER));
thisDistance = Math.abs(address - RegisterFile.getValueNoNotify(RegisterFile.STACK_POINTER_REGISTER));
if (thisDistance < shortDistance) {
shortDistance = thisDistance;
desiredComboBoxIndex = STACK_POINTER_BASE_ADDRESS_INDEX;
Expand Down Expand Up @@ -855,7 +857,15 @@ public void update(Observable observable, Object obj) {
int address = access.getAddress();
// Use the same highlighting technique as for Text Segment -- see
// AddressCellRenderer class below.
writingHighlight = true;
this.highlightCellForAddress(address);
} else if (access.getAccessType() == AccessNotice.READ) {
int address = access.getAddress();
// If it's not fetching an instruction, will highlight in data segment the cell corresponding to the address
if (!Memory.inTextSegment(address)) {
writingHighlight = false; //so it is a reading highlight
this.highlightCellForAddress(address);
}
}
}
}
Expand All @@ -865,7 +875,8 @@ private void updateRowHeight() {
return;
}
Font possibleFonts[] = {
settings.getFontByPosition(Settings.DATASEGMENT_HIGHLIGHT_FONT),
settings.getFontByPosition(Settings.EXPLICIT_WRITE_HIGHLIGHT_FONT),
settings.getFontByPosition(Settings.EXPLICIT_READ_HIGHLIGHT_FONT),
settings.getFontByPosition(Settings.EVEN_ROW_FONT),
settings.getFontByPosition(Settings.ODD_ROW_FONT),
};
Expand Down Expand Up @@ -1033,11 +1044,16 @@ public Component getTableCellRendererComponent(JTable table, Object value,

cell.setHorizontalAlignment(SwingConstants.RIGHT);
int rowFirstAddress = Binary.stringToInt(table.getValueAt(row, ADDRESS_COLUMN).toString());
if (settings.getBooleanSetting(Settings.Bool.DATA_SEGMENT_HIGHLIGHTING) && addressHighlighting &&
rowFirstAddress == addressRowFirstAddress && column == addressColumn) {
cell.setBackground(settings.getColorSettingByPosition(Settings.DATASEGMENT_HIGHLIGHT_BACKGROUND));
cell.setForeground(settings.getColorSettingByPosition(Settings.DATASEGMENT_HIGHLIGHT_FOREGROUND));
cell.setFont(settings.getFontByPosition(Settings.DATASEGMENT_HIGHLIGHT_FONT));
if (settings.getBooleanSetting(Settings.Bool.EXPLICIT_WRITE_HIGHLIGHTING) && addressHighlighting &&
rowFirstAddress == addressRowFirstAddress && column == addressColumn && writingHighlight) {
cell.setBackground(settings.getColorSettingByPosition(Settings.EXPLICIT_WRITE_HIGHLIGHT_BACKGROUND));
cell.setForeground(settings.getColorSettingByPosition(Settings.EXPLICIT_WRITE_HIGHLIGHT_FOREGROUND));
cell.setFont(settings.getFontByPosition(Settings.EXPLICIT_WRITE_HIGHLIGHT_FONT));
} else if (settings.getBooleanSetting(Settings.Bool.EXPLICIT_READ_HIGHLIGHTING) && addressHighlighting &&
rowFirstAddress == addressRowFirstAddress && column == addressColumn && !writingHighlight) { //not writing highlight means reading highlight
cell.setBackground(settings.getColorSettingByPosition(Settings.EXPLICIT_READ_HIGHLIGHT_BACKGROUND));
cell.setForeground(settings.getColorSettingByPosition(Settings.EXPLICIT_READ_HIGHLIGHT_FOREGROUND));
cell.setFont(settings.getFontByPosition(Settings.EXPLICIT_READ_HIGHLIGHT_FONT));
} else if (row % 2 == 0) {
cell.setBackground(settings.getColorSettingByPosition(Settings.EVEN_ROW_BACKGROUND));
cell.setForeground(settings.getColorSettingByPosition(Settings.EVEN_ROW_FOREGROUND));
Expand Down
Loading