This repository was archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdisplay.js
More file actions
51 lines (44 loc) · 1.38 KB
/
display.js
File metadata and controls
51 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
display = {
'emulator': null,
'canvas': null,
'context': null,
'lastFrame': null,
'fontWidth': 0,
'begin': function( emulator, canvas )
{
this.emulator = emulator;
this.canvas = canvas;
this.context = canvas.getContext( "2d" );
this.context.font = '32px Consolas, "Courier New", monospace';
this.fontWidth = this.context.measureText( "M" ).width;
this.canvas.width = this.fontWidth * 32;
this.canvas.height = 32 * 16;
// Have to set font again as resizing the canvas nukes the context...
this.context.font = '32px Consolas, "Courier New", monospace';
this.context.textAlign = 'left';
this.context.textBaseline = 'top';
this.draw();
},
'draw': function()
{
this.context.fillStyle = "black";
this.context.rect( 0, 0, this.canvas.width, this.canvas.height );
this.context.fill();
this.context.fillStyle = 'white';
for( var y = 0; y < 16; y++ )
{
for( var x = 0; x < 32; x++ )
{
var value = this.emulator.memory[ 0x8000 + ( 32 * y ) + x ];
var character = value & 0x007f;
this.context.fillText( String.fromCharCode( character ), x * this.fontWidth, y * 32 );
}
}
var now = new Date().getTime();
var tickLength = now - this.lastFrame;
// We'll run at 50fps, just because.
this.lastFrame = Math.max( this.lastFrame + 20, now + 1 );
var self = this;
setTimeout( function(){ self.draw() }, this.lastFrame - new Date().getTime() );
}
}