annotate engine-runner.js @ 50:a9d7445d07d4

Just a few JS warning fixes.
author Atul Varma <varmaa@toolness.com>
date Fri, 16 May 2008 02:14:19 -0700
parents 2c4d6b171f60
children 7dc2c7bded08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 function Zui() {
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2 }
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
4 Zui.prototype = {
36
afa332a44721 The zui now has a getSize() method which returns the size of the screen in characters. This is communicated to the z-machine.
Atul Varma <varmaa@toolness.com>
parents: 35
diff changeset
5
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
6 // Returns a 2-element list containing the width and height of the
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
7 // screen, in characters. The width may be 255, which means
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
8 // "infinite".
36
afa332a44721 The zui now has a getSize() method which returns the size of the screen in characters. This is communicated to the z-machine.
Atul Varma <varmaa@toolness.com>
parents: 35
diff changeset
9
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
10 getSize: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
11 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
12 onLineInput: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
13 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
14 onCharacterInput: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
15 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
16 onSave: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
17 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
18 onRestore: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
19 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
20 onQuit: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
21 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
22 onRestart: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
23 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
24 onWimpOut: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
25 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
26 onBreakpoint: function(callback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
27 },
49
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
28
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
29 // From the Z-Machine spec for set_text_style: Sets the text style
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
30 // to: Roman (if 0), Reverse Video (if 1), Bold (if 2), Italic (4),
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
31 // Fixed Pitch (8). In some interpreters (though this is not
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
32 // required) a combination of styles is possible (such as reverse
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
33 // video and bold). In these, changing to Roman should turn off all
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
34 // the other styles currently set.
2c4d6b171f60 Text styles now display properly in the lower window (but not the upper one, yet).
Atul Varma <varmaa@toolness.com>
parents: 47
diff changeset
35
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
36 onSetStyle: function(textStyle, foreground, background) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
37 },
35
be2a410b8518 Added docs for onEraseWindow(), changed implementation to match.
Atul Varma <varmaa@toolness.com>
parents: 34
diff changeset
38
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
39 // From the Z-Machine spec for split_window: Splits the screen so
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
40 // that the upper window has the given number of lines: or, if
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
41 // this is zero, unsplits the screen again.
37
9e7a743ccac5 Added very, very buggy support for the top window.
Atul Varma <varmaa@toolness.com>
parents: 36
diff changeset
42
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
43 onSplitWindow: function(numLines) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
44 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
45 onSetWindow: function(window) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
46 },
37
9e7a743ccac5 Added very, very buggy support for the top window.
Atul Varma <varmaa@toolness.com>
parents: 36
diff changeset
47
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
48 // From the Z-Machine spec for erase_window: Erases window with
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
49 // given number (to background colour); or if -1 it unsplits the
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
50 // screen and clears the lot; or if -2 it clears the screen
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
51 // without unsplitting it.
35
be2a410b8518 Added docs for onEraseWindow(), changed implementation to match.
Atul Varma <varmaa@toolness.com>
parents: 34
diff changeset
52
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
53 onEraseWindow: function(window) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
54 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
55 onEraseLine: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
56 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
57 onSetCursor: function(x, y) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
58 },
47
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
59
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
60 // From the Z-Machine spec for buffer_mode: If set to 1, text output
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
61 // on the lower window in stream 1 is buffered up so that it can be
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
62 // word-wrapped properly. If set to 0, it isn't.
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
63
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
64 onSetBufferMode: function(flag) {
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
65 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
66 onSetInputStream: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
67 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
68 onGetCursor: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
69 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
70 onPrint: function(output) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
71 },
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
72 onPrintTable: function(lines) {
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
73 }
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
74 };
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
75
34
cf2303c41d8c Added logging functionality to engine-runner.
Atul Varma <varmaa@toolness.com>
parents: 32
diff changeset
76 function EngineRunner(engine, zui, logfunc) {
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
77 this._engine = engine;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
78 this._zui = zui;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
79 this._isRunning = false;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
80 this._isInLoop = false;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
81 this._isWaitingForCallback = false;
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
82
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
83 if (logfunc) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
84 this._log = logfunc;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
85 } else {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
86 this._log = function() {};
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
87 }
34
cf2303c41d8c Added logging functionality to engine-runner.
Atul Varma <varmaa@toolness.com>
parents: 32
diff changeset
88
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
89 var self = this;
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
90
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
91 this.__proto__ = {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
92 stop: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
93 self._isRunning = false;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
94 },
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
95
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
96 run: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
97 var size = self._zui.getSize();
36
afa332a44721 The zui now has a getSize() method which returns the size of the screen in characters. This is communicated to the z-machine.
Atul Varma <varmaa@toolness.com>
parents: 35
diff changeset
98
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
99 self._isRunning = true;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
100 self._engine.m_memory[0x20] = size[1];
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
101 self._engine.m_memory[0x21] = size[0];
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
102 self._continueRunning();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
103 },
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
104
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
105 _continueRunning: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
106 while (self._isRunning && !self._isWaitingForCallback) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
107 self._loop();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
108 }
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
109 },
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
110
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
111 _receiveLineInput: function(input) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
112 self._isWaitingForCallback = false;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
113 self._engine.answer(1, input);
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
114 if (!self._isInLoop) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
115 self._continueRunning();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
116 } else {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
117 /* We're still inside _loop(), so just return. */
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
118 }
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
119 },
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
120
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
121 _receiveCharacterInput: function(input) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
122 self._isWaitingForCallback = false;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
123 self._engine.answer(0, input);
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
124 if (!self._isInLoop) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
125 self._continueRunning();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
126 } else {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
127 /* We're still inside _loop(), so just return. */
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
128 }
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
129 },
32
3a85b5915ea6 Added bad implementation of character input. The 'info' command in Troll no longer crashes the Z-Machine, but because we don't currently support multiple windows and the the 'info' command uses the top window as an interface, it still looks like it's hanging.
Atul Varma <varmaa@toolness.com>
parents: 31
diff changeset
130
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
131 _loop: function() {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
132 if (self._isInLoop)
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
133 throw new Error("Already in loop!");
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
134
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
135 self._isInLoop = true;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
136 var engine = self._engine;
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
137
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
138 engine.run();
38
696fef276111 Top window output is less buggy now.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
139
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
140 var text = engine.consoleText();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
141 if (text)
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
142 self._zui.onPrint(text);
38
696fef276111 Top window output is less buggy now.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
143
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
144 var effect = '"' + engine.effect(0) + '"';
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
145
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
146 var logString = "[ " + engine.effect(0);
34
cf2303c41d8c Added logging functionality to engine-runner.
Atul Varma <varmaa@toolness.com>
parents: 32
diff changeset
147
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
148 for (var i = 1; engine.effect(i) != undefined; i++) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
149 var value = engine.effect(i);
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
150 if (typeof value == "string")
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
151 value = value.quote();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
152 logString += ", " + value;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
153 }
34
cf2303c41d8c Added logging functionality to engine-runner.
Atul Varma <varmaa@toolness.com>
parents: 32
diff changeset
154
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
155 self._log(logString + " ]");
34
cf2303c41d8c Added logging functionality to engine-runner.
Atul Varma <varmaa@toolness.com>
parents: 32
diff changeset
156
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
157 switch (effect) {
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
158 case GNUSTO_EFFECT_INPUT:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
159 self._isWaitingForCallback = true;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
160 self._zui.onLineInput(self._receiveLineInput);
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
161 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
162 case GNUSTO_EFFECT_INPUT_CHAR:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
163 self._isWaitingForCallback = true;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
164 self._zui.onCharacterInput(self._receiveCharacterInput);
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
165 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
166 case GNUSTO_EFFECT_SAVE:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
167 case GNUSTO_EFFECT_RESTORE:
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
168 throw new Error("Unimplemented effect: " + effect);
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
169 case GNUSTO_EFFECT_QUIT:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
170 self.stop();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
171 self._zui.onQuit();
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
172 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
173 case GNUSTO_EFFECT_RESTART:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
174 case GNUSTO_EFFECT_WIMP_OUT:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
175 case GNUSTO_EFFECT_BREAKPOINT:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
176 case GNUSTO_EFFECT_FLAGS_CHANGED:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
177 case GNUSTO_EFFECT_PIRACY:
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
178 throw new Error("Unimplemented effect: " + effect);
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
179 case GNUSTO_EFFECT_STYLE:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
180 self._zui.onSetStyle(engine.effect(1),
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
181 engine.effect(2),
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
182 engine.effect(3));
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
183 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
184 case GNUSTO_EFFECT_SOUND:
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
185 throw new Error("Unimplemented effect: " + effect);
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
186 case GNUSTO_EFFECT_SPLITWINDOW:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
187 self._zui.onSplitWindow(engine.effect(1));
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
188 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
189 case GNUSTO_EFFECT_SETWINDOW:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
190 self._zui.onSetWindow(engine.effect(1));
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
191 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
192 case GNUSTO_EFFECT_ERASEWINDOW:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
193 self._zui.onEraseWindow(engine.effect(1));
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
194 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
195 case GNUSTO_EFFECT_ERASELINE:
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
196 throw new Error("Unimplemented effect: " + effect);
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
197 case GNUSTO_EFFECT_SETCURSOR:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
198 self._zui.onSetCursor(engine.effect(2),
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
199 engine.effect(1));
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
200 break;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
201 case GNUSTO_EFFECT_SETBUFFERMODE:
47
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
202 self._zui.onSetBufferMode(engine.effect(1));
1effb310d6ee Added stub implementation for setBufferMode().
Atul Varma <varmaa@toolness.com>
parents: 43
diff changeset
203 break;
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
204 case GNUSTO_EFFECT_SETINPUTSTREAM:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
205 case GNUSTO_EFFECT_GETCURSOR:
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
206 case GNUSTO_EFFECT_PRINTTABLE:
50
a9d7445d07d4 Just a few JS warning fixes.
Atul Varma <varmaa@toolness.com>
parents: 49
diff changeset
207 throw new Error("Unimplemented effect: " + effect);
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
208 }
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
209
43
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
210 self._isInLoop = false;
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
211 }
e45b81cdb4d0 Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
212 };
6
aeb4289c141f Added a test runner class w/ simple test suite.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
213 }