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

Fixes invalid monitor range bug & adds range validation #17

Merged
merged 4 commits into from
Apr 28, 2015
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
38 changes: 35 additions & 3 deletions simulator/assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ function SimulatorWidget(node) {
ui.toggleMonitor();
simulator.toggleMonitor();
});
$node.find('.start, .length').blur(simulator.handleMonitorRangeChange);
$node.find('.stepButton').click(simulator.debugExec);
$node.find('.gotoButton').click(simulator.gotoAddr);
$node.find('.notesButton').click(ui.showNotes);
$node.find('.code').on('keypress input', simulator.stop);
$node.find('.code').on('keypress input', ui.initialize);
$(document).keypress(memory.storeKeypress);

simulator.handleMonitorRangeChange();
}

function stripText() {
Expand Down Expand Up @@ -1554,12 +1557,40 @@ function SimulatorWidget(node) {
if (monitoring) {
var start = parseInt($node.find('.start').val(), 16);
var length = parseInt($node.find('.length').val(), 16);
if (start >= 0 && length > 0) {
$node.find('.monitor code').html(memory.format(start, length));

var end = start + length - 1;

var monitorNode = $node.find('.monitor code');

if (!isNaN(start) && !isNaN(length) && start >= 0 && length > 0 && end <= 0xffff) {
monitorNode.html(memory.format(start, length));
} else {
monitorNode.html('Cannot monitor this range. Valid ranges are between $0000 and $ffff, inclusive.');
}
}
}

function handleMonitorRangeChange() {

var $start = $node.find('.start'),
$length = $node.find('.length'),
start = parseInt($start.val(), 16),
length = parseInt($length.val(), 16),
end = start + length - 1;

$start.removeClass('monitor-invalid');
$length.removeClass('monitor-invalid');

if(isNaN(start) || start < 0 || start > 0xffff) {

$start.addClass('monitor-invalid');

} else if(isNaN(length) || end > 0xffff) {

$length.addClass('monitor-invalid');
}
}

// Execute one instruction and print values
function debugExec() {
//if (codeRunning) {
Expand Down Expand Up @@ -1645,7 +1676,8 @@ function SimulatorWidget(node) {
gotoAddr: gotoAddr,
reset: reset,
stop: stop,
toggleMonitor: toggleMonitor
toggleMonitor: toggleMonitor,
handleMonitorRangeChange: handleMonitorRangeChange
};
}

Expand Down
5 changes: 5 additions & 0 deletions simulator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
display: none;
}

.monitor-invalid {
border: 1px inset #c00;
padding: 2px 1px;
}

.messages {
margin: 0;
padding: 6px;
Expand Down