Add a list of available examples

Signed-off-by: Junjie Mao <junjie.mao@enight.me>
This commit is contained in:
Junjie Mao 2015-09-16 10:42:54 +08:00
parent ac30f4f5b3
commit f6c3fd1091
7 changed files with 164 additions and 18 deletions

View File

@ -1,5 +1,7 @@
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
@ -35,14 +37,42 @@ module.exports = function(grunt) {
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint', 'concat']
},
connect: {
server: {
options: {
port: 8082,
base: './',
keepalive: true
}
}
},
php: {
dist: {
options: {
port: 8082,
base: '.',
keepalive: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
grunt.registerTask('http', ['php']);
};
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/

View File

@ -0,0 +1,7 @@
; c = a + b
LOADI R5, 10
LOADI R6, 20
ADDI R5, R5, R6
STORE R5, 10
HALT

View File

@ -0,0 +1,45 @@
; Time-sharing between two processes
; Additionally the yellow LED is switched once an overflow occurs.
; The red LED is toggled via an interrupt when the red button is pressed.
; ---- INIT
MOV b0, 0x00
MOV b1, 0x20
; Enable interrupts for the red button (= pin 2)
; Pin: 7 6 5 4 3 2 1 0
; Mask: 0 0 0 0 0 1 0 0 = 4dec
ENABLE 4
; ---- Blink green and increment b0 by b1
main:
ADD b0, b1
DEBUG b0 ; send current value of b0 to debugger
JC carry ; jump if b0 had an overflow
TOGGLE 5 ; toggle green LED
PAUSE 30000 ; wait for ~450ms
JMP main
; ---- Switch yellow
carry:
TOGGLE 4 ; toggle yellow LED
JMP main
; ---- called via interrupt when the red button is pressed
isr1:
TOGGLE 3 ; toggle red LED
ECHO helloWorld ; send string "hello world" to debugger
RETI ; return to main program
helloWorld:
STRING "hello world"
; ---- interrupt table
ORG 0x100
DW 0 ; pin 0 (not wired)
DW 0 ; black button
DA isr1 ; red button
END

21
examples/scandir.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/* taken from: https://github.com/eladkarako/download.eladkarako.com */
$path = '.';
$files = [];
$handle = @opendir('./' . $path . '/');
while ($file = @readdir($handle)) {
if (($tmp = strlen($file) - 4) >= 0 && strpos($file, ".txt", $tmp) !== FALSE) {
$comment = substr(fgets(fopen($file, 'r')), 2);
array_push($files, $file . '|' . $comment);
}
}
@closedir($handle);
sort($files); //uksort($files, "strnatcasecmp");
$files = json_encode($files);
unset($handle,$ext,$file,$path);
?>
<?php echo $files; ?>

View File

@ -28,21 +28,25 @@
<div class="col-lg-7 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Code <small>(<a href="./instruction-set.html" target="_blank" style="color: #337AB7">Instruction Set</a>)</small></h4>
</div>
<div class="panel-body">
<form role="form">
<textarea id="sourceCode"
class="form-control source-code"
style="margin-bottom:5px;"
rows="30"
tab-support
select-line
ng-model="code"></textarea>
<button type="button" class="btn btn-default" ng-click="assemble()">Assemble</button>
<button type="button" class="btn btn-default" ng-click="upload()">Upload</button>
</form>
<h4 class="panel-title">Code <small>(<a href="./instruction-set.html" target="_blank" style="color: #337AB7">Instruction Set</a>)</small></h4>
</div>
<button type="button" class="btn btn-default" ng-click="assemble()">Assemble</button>
<button type="button" class="btn btn-default" ng-click="upload()">Upload</button>
Examples:
<select ng-model="example" ng-options="item.id as item.desc for item in examples" ng-change="showExample(example)" ng-init="initExamples()"></select>
<!-- <select id="examples" ng-change="showExample(x)" ng-model="x"> -->
<!-- <option value="haha">haha</option> -->
<!-- <option value="hoho">hoho</option> -->
<!-- </select> -->
<form role="form">
<textarea id="sourceCode"
class="form-control source-code"
style="margin-bottom:5px;"
rows="30"
tab-support
select-line
ng-model="code"></textarea>
</form>
</div>
</div>
<div class="clearfix visible-xs visible-sm"></div>

View File

@ -5,11 +5,15 @@
"author": "Marco Schweighauser",
"license": "MIT",
"devDependencies": {
"angular": "~1.4.5",
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-watch": "~0.5.3",
"angular": "~1.4.5"
"grunt-http-server": "0.0.2",
"grunt-php": "^1.5.1",
"load-grunt-tasks": "^3.2.0"
}
}

View File

@ -1,4 +1,4 @@
app.controller('Ctrl', ['$document', '$scope', '$timeout', 'cpu', 'memory', 'assembler', 'uploader', function ($document, $scope, $timeout, cpu, memory, assembler, uploader) {
app.controller('Ctrl', ['$document', '$scope', '$timeout', '$http', 'cpu', 'memory', 'assembler', 'uploader', function ($document, $scope, $timeout, $http, cpu, memory, assembler, uploader) {
$scope.memory = memory;
$scope.cpu = cpu;
$scope.error = '';
@ -14,7 +14,8 @@ app.controller('Ctrl', ['$document', '$scope', '$timeout', 'cpu', 'memory', 'ass
{speed: 8, desc: "8 HZ"},
{speed: 16, desc: "16 HZ"}];
$scope.speed = 4;
$scope.outputStartIndex = 232;
$scope.example = '';
$scope.examples = [];
//$scope.code = "; Simple example\n; Writes Hello World to the output\n\n JMP start\nhello: DB \"Hello World!\" ; Variable\n DB 0 ; String terminator\n\nstart:\n MOV C, hello ; Point to var \n MOV D, 232 ; Point to output\n CALL print\n HLT ; Stop execution\n\nprint: ; print(C:*from, D:*to)\n PUSH A\n PUSH B\n MOV B, 0\n.loop:\n MOV A, [C] ; Get char from var\n MOV [D], A ; Write to output\n INC C\n INC D \n CMP B, [C] ; Check if end\n JNZ .loop ; jump if not\n\n POP B\n POP A\n RET";
$scope.code = "; Simple example\n; R1+R2=R0\n\nLOADI R0,10\nLOADI R1,20\nLOADI R2,30\nADDI R0,R1,R2\nHALT";
@ -137,6 +138,32 @@ app.controller('Ctrl', ['$document', '$scope', '$timeout', 'cpu', 'memory', 'ass
}
};
$scope.initExamples = function() {
var response = $http.get('examples/scandir.php');
response.success(function(data, status, headers, config) {
var filelist = String(data).split(',');
for (var i = 0, l = filelist.length; i < l; i++) {
var contents = filelist[i].split('|');
var filename = contents[0], desc = contents[1];
$scope.examples.push({id: filename, desc: desc});
}
});
response.error(function(data, status, headers, config) {
console.error("ajax failed");
});
};
$scope.showExample = function(key) {
var response = $http.get('examples/' + $scope.example);
response.success(function(data, status, headers, config) {
$scope.code = data;
});
response.error(function(data, status, headers, config) {
console.error("ajax failed");
});
};
$scope.jumpToLine = function (index) {
$document[0].getElementById('sourceCode').scrollIntoView();
$scope.selectedLine = $scope.mapping[index];
@ -175,3 +202,11 @@ app.controller('Ctrl', ['$document', '$scope', '$timeout', 'cpu', 'memory', 'ass
}
};
}]);
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/