Skip to content

Commit

Permalink
Fixed drawing on step
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Bell committed Apr 16, 2012
1 parent c6f1a1f commit ceb7985
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 79 deletions.
159 changes: 80 additions & 79 deletions js/ui.js
Expand Up @@ -194,14 +194,12 @@ $(function() {
}; };


function drawLoop() { function drawLoop() {
if(cpu.running) { for(var i = 0; i < rows; i++) {
for(var i = 0; i < rows; i++) { for(var j = 0; j < cols; j++) {
for(var j = 0; j < cols; j++) { var cell = cellQueue[i][j];
var cell = cellQueue[i][j]; if(cell) {
if(cell) { drawChar(cpu.mem[0x8000 + (i * cols) + j], j, i);
drawChar(cpu.mem[0x8000 + (i * cols) + j], j, i); cellQueue[i][j] = false;
cellQueue[i][j] = false;
}
} }
} }
} }
Expand All @@ -211,17 +209,13 @@ $(function() {
drawLoop(); drawLoop();


function blinkLoop() { function blinkLoop() {
if(cpu.running) { blinkVisible = !blinkVisible;
blinkVisible = !blinkVisible; for(var i = 0; i < rows; i++) {
for(var i = 0; i < rows; i++) { for(var j = 0; j < cols; j++) {
for(var j = 0; j < cols; j++) { if(blinkCells[i][j]) {
if(blinkCells[i][j]) { queueChar(j, i);
queueChar(j, i);
}
} }
} }
} else {
blinkVisible = false;
} }
setTimeout(blinkLoop, blinkInterval); setTimeout(blinkLoop, blinkInterval);
}; };
Expand Down Expand Up @@ -329,71 +323,82 @@ $(function() {
editor.setLineClass(errorLine, null, null); editor.setLineClass(errorLine, null, null);
} }


var debugMs = 16, lastDebug = 0; var lastRam;
function debugLoop() { function debugLoop() {
editor.setLineClass(pcLine, null, null); if($('#debug').hasClass('active') && cpu.running) {
pcLine = editor.setLineClass(assembler.instructionMap[assembler.addressMap[cpu.mem.pc]] - 1, null, 'pcLine'); editor.setLineClass(pcLine, null, null);

pcLine = editor.setLineClass(assembler.instructionMap[assembler.addressMap[cpu.mem.pc]] - 1, null, 'pcLine');
$('#memoryInfo').empty();

function updateRegister(name) {
function updateRegister(name) { $('#' + name + ' .val').text(DCPU16.formatWord(cpu.mem[name]));
$('#' + name + ' .val').text(DCPU16.formatWord(cpu.mem[name])); $('#' + name + ' .point').text(DCPU16.formatWord(cpu.mem[cpu.mem[name]]));
$('#' + name + ' .point').text(DCPU16.formatWord(cpu.mem[cpu.mem[name]])); }
}

for(var i = 0; i < DCPU16.registerNames.length; i++) {
for(var i = 0; i < DCPU16.registerNames.length; i++) { updateRegister(DCPU16.registerNames[i]);
updateRegister(DCPU16.registerNames[i]); }
} updateRegister('pc');
updateRegister('pc'); updateRegister('o');
updateRegister('o');

$('#sp .val').text(DCPU16.formatWord(cpu.mem.stack));
$('#sp .val').text(DCPU16.formatWord(cpu.mem.stack)); $('#sp .point').text(DCPU16.formatWord(cpu.mem[cpu.mem.stack]));
$('#sp .point').text(DCPU16.formatWord(cpu.mem[cpu.mem.stack]));

$('div.tooltip').remove();
$('div.tooltip').remove();

var rowN = 0, table = $('#memoryInfo');
for(var i = 0; i < cpu.ramSize; i += 8) { for(var i = 0; i < cpu.ramSize; i += 8) {
populated = false; var populated = false;
for( j = 0; j < 8; j++) { for(var j = 0; j < 8; j++) {
if(cpu.mem[i + j] || cpu.mem.pc === i + j || cpu.mem.stack === i + j) { if(cpu.getDevice(i + j)) {
populated = true; break;
break; } else if(cpu.mem[i + j] || cpu.mem.pc === i + j || cpu.mem.stack === i + j) {
} populated = true;
} break;

}
if(populated) { }
var row = $('<tr></tr>');

if(populated) {
row.append('<td><strong>' + DCPU16.formatWord(i + j) + '</strong></td>'); var row = table.find('.row' + rowN);
for(var j = 0; j < 8; j++) { if(row.length === 0) {
var cell = $('<td> ' + DCPU16.formatWord(cpu.mem[i + j]) + '</a></td>'); row = $('<tr class="row' + rowN + '"></tr>');
cell.tooltip({ table.append(row);
title: editor.getLine(instructionMap[addressMap[j+i]] - 1) row.append('<td class="address"></td>');
}); }
row.append(cell);
} row.children('.address').text(DCPU16.formatWord(i));


$('#memoryInfo').append(row); for(var j = 0; j < 8; j++) {
} if(!lastRam || cpu.mem[i + j] !== lastRam[i + j]) {
} var cell = row.children('.cell' + j);

if(cell.length === 0) {
$('#cycle').text(cpu.cycle); cell = $('<td class="cell' + j + '"></td>');
row.append(cell);
}

cell.tooltip({
title: editor.getLine(instructionMap[addressMap[j+i]] - 1)
});
cell.text(DCPU16.formatWord(cpu.mem[i + j]));
}
}


rowN++;
}
}
lastRam = cpu.mem.slice(0);

$('#cycle').text(cpu.cycle);
}
setTimeout(debugLoop, 100);
} }
debugLoop();


$('#run').click(function() { $('#run').click(function() {
if(!$(this).hasClass('disabled')) { if(!$(this).hasClass('disabled')) {
if(compile()) { if(compile()) {
debugLoop();
notRun = false; notRun = false;
cpu.run(function() { cpu.run();
if($('#debug').hasClass('active')) {
var now = new Date().getTime();
if(now - lastDebug >= debugMs) {
lastDebug = now;
debugLoop();
}
}
});
$('#step').addClass('disabled'); $('#step').addClass('disabled');
$('#run').addClass('disabled'); $('#run').addClass('disabled');
$('#run span').text('Running...'); $('#run span').text('Running...');
Expand All @@ -414,27 +419,23 @@ $(function() {
$('#debugger').collapse('show'); $('#debugger').collapse('show');
$('#debugger').css('height', 'auto'); $('#debugger').css('height', 'auto');
if(!cpu.running) compile(); if(!cpu.running) compile();
cpu.loopBatch = 50;
} else { } else {
$('#debugIcon').removeClass('icon-chevron-up'); $('#debugIcon').removeClass('icon-chevron-up');
$('#debugIcon').addClass('icon-chevron-down'); $('#debugIcon').addClass('icon-chevron-down');
$('#debugger').collapse('hide'); $('#debugger').collapse('hide');
cpu.loopBatch = 1000;
} }
}); });


$('#reset').click(function() { $('#reset').click(function() {
if(!$(this).hasClass('disabled')) { if(!$(this).hasClass('disabled')) {
reset(); reset();
compile(); compile();
debugLoop();
} }
}); });


$('#step').click(function() { $('#step').click(function() {
if(!$(this).hasClass('disabled')) { if(!$(this).hasClass('disabled')) {
cpu.step(); cpu.step();
debugLoop();
} }
}); });


Expand Down
2 changes: 2 additions & 0 deletions views/upload.jade
@@ -0,0 +1,2 @@
extends index

0 comments on commit ceb7985

Please sign in to comment.