Skip to content

Commit

Permalink
Fixed control buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Rempp committed Apr 23, 2014
1 parent f04a5e2 commit 39dbcb7
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 47 deletions.
96 changes: 64 additions & 32 deletions src/js/emu/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ function(
_Gui = null;

var Cpu = {
_cpuPaused : false,
STATE_PAUSED : 0,
STATE_RUNNING : 1,
STATE_STOPPED : 2,

state : 2,

_debugFlag : false,

// Should this be on or off to begin?
_haltFlag : false,

_drawFlag : false,

_cycles : 0,
Expand All @@ -47,20 +52,26 @@ function(
cpuModel,
Gui
){
// Initialize settings and state
_this.state = _this.STATE_RUNNING;
_this._drawFlag = false;
_this._cycles = 0;
_this._haltFlag = false;

// Setup debugging
if (SettingsModel.get('emuSettings')['startInDebug'])
{
_this._debugFlag = true;
}

// Save the gui module
_Gui = Gui;

// Save the cpu module
_cpu = cpuModel;

// Initialize the CPU
_this.reset(SettingsModel.get('emuSettings')["blobSettings"]);

// Setup debugging
if (SettingsModel.get('emuSettings')['startInDebug'])
{
_this._debugFlag = true;
}
_cpu.reset(_this, SettingsModel.get('emuSettings')["blobSettings"]);

// Initialize input
Input.setupInput();
Expand Down Expand Up @@ -89,38 +100,48 @@ function(
// Emulation loop
run : function ()
{
this.state = this.STATE_RUNNING;

for(;;)
{
if (11500 === this._cycles) this._debugFlag = true;
console.log("running...")
// if (11500 === this._cycles) this._debugFlag = true;
// if (0x011D === _cpu._regIP) this._debugFlag = true;

if (this._haltFlag){
if (this._haltFlag || this.state === this.STATE_STOPPED){
Gfx.drawGraphics();
break;
}

if (!this._cpuPaused)
if (this.state === this.STATE_PAUSED)
{
// Emulate one cycle
_cpu.emulateCycle();
break;
}

this._cycles++;
// Emulate one cycle
_cpu.emulateCycle();

// TODO: This is wrong! Research the correct timing
//if (0 === this._cycles % 100) this._drawFlag = true;
this._cycles++;

// If the draw flag is set, update the screen
if(this._drawFlag)
{
Gfx.drawGraphics();
this._drawFlag = false;
}
// TODO: This is wrong! Research the correct timing
//if (0 === this._cycles % 100) this._drawFlag = true;

// Store key press state (Press and Release)
Input.setKeys();
// If the draw flag is set, update the screen
if(this._drawFlag)
{
Gfx.drawGraphics();
this._drawFlag = false;
}

if (this._debugFlag) break;
// Store key press state (Press and Release)
Input.setKeys();


if (this._debugFlag && !this._haltFlag)
{
this.pause();
break;
}
}
},

Expand All @@ -134,18 +155,26 @@ function(
this._blob = blob;
},

reset : function (settings)
reset : function ()
{
this._cycles = 0;
this._cpuPaused = false;
this._haltFlag = false;
this.state = this.STATE_STOPPED;
this._drawFlag = false;
this._cycles = 0;
this._haltFlag = false;

_cpu.reset(this, settings);
_cpu.reset(this, SettingsModel.get('emuSettings')["blobSettings"]);

Gfx.drawGraphics();

_Gui.setControlState("stopped");

_Gui.disableDebug();
},

pause : function ()
{
this._cpuPaused = true;
this.state = this.STATE_PAUSED;
_Gui.setControlState("paused");
},

halt : function (options)
Expand All @@ -162,6 +191,9 @@ function(
Gfx.drawGraphics();

this._haltFlag = true;
this.state = this.STATE_STOPPED;

_Gui.setControlState("stopped");

if (options.enterDebug)
{
Expand Down
16 changes: 14 additions & 2 deletions src/js/emu/emu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ function(

run : function ()
{
// Boot the CPU
Cpu.boot();
Cpu._debugFlag = false;
if (Cpu.state === Cpu.STATE_PAUSED)
{
Cpu.run();
}
else
{
Cpu.boot();
}
},

reset : function ()
{
if (Cpu.state === Cpu.STATE_RUNNING)
{
Cpu.halt();
}

Cpu.reset();
},

Expand Down
34 changes: 26 additions & 8 deletions src/js/gui/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,40 @@ function(

_controlView : null,

_debugInfoView : null,
_debugDecodeView : null,
_debugRegisterView : null,
_debugMemoryView : null,

init : function ()
{
this._controlView = new ControlView();
$("#gui-controls").append(this._controlView.render().el);
},

setControlState : function (state)
{
this._controlView.setState(state);
},

debugUpdateInfo : function (data)
{
var debugInfoView = new DebugInfoView(data);
$("#gui-debug-info").html(debugInfoView.render().el);
this._debugInfoView = new DebugInfoView(data);
$("#gui-debug-info").html(this._debugInfoView.render().el);
},

debugUpdateDecode : function (decObj)
{
var decModel = new DebugDecodeModel(decObj);
var debugDecodeView = new DebugDecodeView({model: decModel});
$("#gui-debug-decode").html(debugDecodeView.render().el);
this._debugDecodeView = new DebugDecodeView({model: decModel});
$("#gui-debug-decode").html(this._debugDecodeView.render().el);
},

debugUpdateRegister : function (regObj)
{
var regModel = new DebugRegisterModel(regObj);
var debugRegisterView = new DebugRegisterView({model: regModel});
$("#gui-debug-register").html(debugRegisterView.render().el);
this._debugRegisterView = new DebugRegisterView({model: regModel});
$("#gui-debug-register").html(this._debugRegisterView.render().el);
},

debugUpdateMemory : function (memObj)
Expand All @@ -71,8 +81,16 @@ function(
numRows : 5,
numCols : 8
});
var debugMemoryView = new DebugMemoryView({model: memModel});
$("#gui-debug-memory").html(debugMemoryView.render().el);
this._debugMemoryView = new DebugMemoryView({model: memModel});
$("#gui-debug-memory").html(this._debugMemoryView.render().el);
},

disableDebug : function ()
{
this._debugInfoView.disable();
this._debugDecodeView.disable();
this._debugRegisterView.disable();
this._debugMemoryView.disable();
}
};

Expand Down
19 changes: 18 additions & 1 deletion src/js/gui/views/ControlView.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function(
"click .button-pause" : "pause",
"click .button-halt" : "halt",
"click .button-step" : "step",
"click .button-settings" : "settings",
"click .button-settings" : "settings"
//"keyup .button-settings" : "keyUp",
//"keydown .button-settings" : "keyDown"
},
Expand Down Expand Up @@ -156,6 +156,23 @@ function(
settingsView.show();
},

setState : function (state)
{
console.log(state);
switch (state)
{
case "running" :
_toggleState("run", this.$el);
break;
case "stopped" :
_toggleState("halt", this.$el);
break;
case "paused" :
_toggleState("pause", this.$el);
break;
}
},

keyDown : function (event)
{
// F7 - pause
Expand Down
5 changes: 5 additions & 0 deletions src/js/gui/views/DebugDecodeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ function(
return this;
},

disable : function ()
{
this.$el.hide();
},

toConsole : function ()
{
console.log("" +
Expand Down
5 changes: 5 additions & 0 deletions src/js/gui/views/DebugInfoView.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ define([
return this;
},

disable : function ()
{
this.$el.hide();
},

vidTest : function ()
{
Gfx.debugVideoTestPattern();
Expand Down
5 changes: 5 additions & 0 deletions src/js/gui/views/DebugMemoryView.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function(
return this;
},

disable : function ()
{
this.$el.hide();
},

doCenter : function ()
{
var addr = $("#debug-memory-center").val();
Expand Down
5 changes: 5 additions & 0 deletions src/js/gui/views/DebugRegisterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ function(
return this;
},

disable : function ()
{
this.$el.hide();
},

toConsole : function ()
{
var regObj = this.model.attributes;
Expand Down
11 changes: 7 additions & 4 deletions src/js/gui/views/LoadBlobView.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ function(

// Load blob
_loadBlob(emuSettings.blobProgram, function(arrayBuffer){
if (arrayBuffer) {
Emu.runBlob(arrayBuffer)
}
loaderView.hide();
require(['gui/gui'], function(GUI) {
if (arrayBuffer) {
GUI.setControlState("running");
Emu.runBlob(arrayBuffer)
}
loaderView.hide();
});
});
}
else
Expand Down

0 comments on commit 39dbcb7

Please sign in to comment.