Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed DIV, cleaned up

  • Loading branch information...
commit 58c72d3d80c2aaa485ea495bc2e1b13f6ae2729a 1 parent 4332cfb
Bryon Vandiver authored
View
1  README
@@ -36,5 +36,4 @@ so you may need to run a lightweight http server to run locally.
Bugs
----------------------------------------
-Predictions are busted (most noticeable in hi-color games)
Interrupts for joypad seem off, as a lot of games boot if you press a key
View
27 src/chips/cpu.js
@@ -124,9 +124,11 @@ jsboyCPU.prototype.reset = function()
}
jsboyCPU.prototype.setCPUSpeed = function(fast) {
- this.doubleSpeed = fast;
+ this.doubleSpeed = fast;
this.prepareSpeed = false;
+ // This is arguably the same speed as a table lookup
+ // due to the presense of a large case statement
this.CYCLES_1 = fast ? 1 : 2;
this.CYCLES_2 = fast ? 2 : 4;
this.CYCLES_3 = fast ? 3 : 6;
@@ -164,25 +166,24 @@ jsboyCPU.prototype.predictEvent = function()
// Never clock more than the rest of the frame!
var predict = this.frameCycles;
- function min( a )
- {
- if( a === null || a > predict )
- return ;
- predict = a;
- }
-
- min(this.gpu.predict());
- min(this.timer.predict());
+ var b = this.gpu.predict();
+ var c = this.timer.predict();
//TODO: SERIAL?
+
+ if( b && b < predict )
+ predict = b;
+ if( c && c < predict )
+ predict = c;
}
// --- Send CPU accumulation clock to the external components
jsboyCPU.prototype.catchUp = function()
{
// Increment it based on the CPU clock, not the system
- var machine = this.doubleSpeed ? this.cycles : (this.cycles >> 1);
-
- this.timer.clock(this.cycles, machine);
+ var cpuCycles = this.doubleSpeed ? this.cycles : (this.cycles >> 1);
+ this.timer.tick(cpuCycles);
+ this.timer.clock(this.cycles);
+
this.gpu.clock(this.cycles);
// Flush the cycle buffer
View
4 src/chips/ops/base.js
@@ -1018,10 +1018,8 @@ jsboyCPU.prototype.stepBase = function(){
case 0x10:
// Put the CPU in halt mode
if( this.prepareSpeed )
- {
this.setCPUSpeed(!this.doubleSpeed);
- this.prepareSpeed = false;
- }
+
// Note: this SHOULD fall through
case 0x76:
if( !this.irq_master )
View
9 src/chips/timer.js
@@ -20,10 +20,13 @@ jsboyTimer.prototype.PRESCALARS = [
(2 * 1024 * 1024) / 16384
];
-jsboyTimer.prototype.clock = function(cycles, machine_cycles)
+jsboyTimer.prototype.tick = function(cycles)
{
- this.div = (this.div + machine_cycles) & 0x1FFFF;
+ this.div = (this.div + cycles) & 0xFFFF;
+}
+jsboyTimer.prototype.clock = function(cycles)
+{
if( !this.enabled )
return ;
@@ -80,7 +83,7 @@ jsboyTimer.prototype.write_TMA = function(data)
jsboyTimer.prototype.read_DIV = function()
{
this.cpu.catchUp();
- return (this.div >> 6) & 0xFF;
+ return this.div >> 8;
}
jsboyTimer.prototype.write_DIV = function()
Please sign in to comment.
Something went wrong with that request. Please try again.