Add a printer

Signed-off-by: Junjie Mao <junjie.mao@enight.me>
This commit is contained in:
Junjie Mao 2015-09-17 16:46:55 +08:00
parent fedc22763e
commit e2d018e9da
5 changed files with 49 additions and 19 deletions

View File

@ -53,6 +53,7 @@
tmp1: LOADB R3, 0x04
ADDI RE, RE, R3
LOADP R0, RE
STOREM R0, 0xFE ; Send the result to the printer
ADDI RE, RE, R1
HALT

View File

@ -51,6 +51,12 @@
</div>
<div class="clearfix visible-xs visible-sm"></div>
<div class="col-lg-5 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Printer</h4>
</div>
<div class="panel-body source-code">{{ printer.data }}</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">CPU & Memory</h4>
@ -136,23 +142,6 @@
<span style="margin-left:5px;">Instructions:</span>
<a ng-click="displayInstr = true" ng-hide="displayInstr">Show</a>
<a ng-click="displayInstr = false" ng-show="displayInstr">Hide</a>
<!-- <span style="margin-left:5px;">View:</span> -->
<!-- <a ng-click="displayHex = true" ng-hide="displayHex">Hex</a> -->
<!-- <a ng-click="displayHex = false" ng-show="displayHex">Decimal</a> -->
<!-- <br> -->
<!-- Register addressing: -->
<!-- <span style="margin-left:5px;">A:</span> -->
<!-- <a ng-click="displayA = true" ng-hide="displayA">Show</a> -->
<!-- <a ng-click="displayA = false" ng-show="displayA">Hide</a> -->
<!-- <span style="margin-left:5px;">B:</span> -->
<!-- <a ng-click="displayB = true" ng-hide="displayB">Show</a> -->
<!-- <a ng-click="displayB = false" ng-show="displayB">Hide</a> -->
<!-- <span style="margin-left:5px;">C:</span> -->
<!-- <a ng-click="displayC = true" ng-hide="displayC">Show</a> -->
<!-- <a ng-click="displayC = false" ng-show="displayC">Hide</a> -->
<!-- <span style="margin-left:5px;">D:</span> -->
<!-- <a ng-click="displayD = true" ng-hide="displayD">Show</a> -->
<!-- <a ng-click="displayD = false" ng-show="displayD">Hide</a> -->
</small>
</p>
</div>

View File

@ -1,4 +1,4 @@
app.service('memory', [function () {
app.service('memory', ['printer', function (printer) {
var memory = {
data: Array(256),
lastAccess: -1,
@ -10,6 +10,10 @@ app.service('memory', [function () {
}
self.lastAccess = address;
if (address == 0xFE) {
return printer.load();
}
return self.data[address];
},
store: function (address, value) {
@ -20,6 +24,10 @@ app.service('memory', [function () {
}
self.lastAccess = address;
if (address == 0xFE) {
return printer.store(value);
}
self.data[address] = value;
},
reset: function () {

30
src/emulator/printer.js Normal file
View File

@ -0,0 +1,30 @@
app.service('printer', [function () {
var printer = {
data: '',
load: function() {
return 0;
},
store: function(value) {
var self = this;
if (value < 16)
self.data += '0' + value.toString(16) + " ";
else
self.data += value.toString(16) + " ";
},
reset: function () {
var self = this;
self.data = '';
}
};
printer.reset();
return printer;
}]);
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/

View File

@ -1,4 +1,5 @@
app.controller('Ctrl', ['$document', '$scope', '$timeout', '$http', 'cpu', 'memory', 'assembler', 'uploader', function ($document, $scope, $timeout, $http, cpu, memory, assembler, uploader) {
app.controller('Ctrl', ['$document', '$scope', '$timeout', '$http', 'cpu', 'memory', 'printer', 'assembler', 'uploader', function ($document, $scope, $timeout, $http, cpu, memory, printer, assembler, uploader) {
$scope.printer = printer;
$scope.memory = memory;
$scope.cpu = cpu;
$scope.error = '';
@ -21,6 +22,7 @@ app.controller('Ctrl', ['$document', '$scope', '$timeout', '$http', 'cpu', 'memo
$scope.reset = function () {
cpu.reset();
memory.reset();
printer.reset();
$scope.error = '';
$scope.selectedLine = -1;
$scope.mapping = undefined;