diff --git a/src/emu.js b/src/emu.js
index 7e486441..e98e93a4 100644
--- a/src/emu.js
+++ b/src/emu.js
@@ -643,3 +643,25 @@ function padBytes(data, len) {
r.mem.set(data);
return r.mem;
}
+
+// TODO: better performance, check values
+function AddressDecoder(table) {
+ var self = this;
+ function makeFunction(lo, hi) {
+ var s = "";
+ for (var i=0; i
=" + start + " && a<="+end + "){";
+ s += "a&="+(mask?mask:0xffff)+";";
+ s += "return this.__fn"+i+"(a,v)&0xff;}\n";
+ }
+ s += "return 0;"; // TODO: noise()?
+ return new Function('a', 'v', s);
+ }
+ return makeFunction(0x0, 0xffff).bind(self);
+}
diff --git a/src/platform/galaxian.js b/src/platform/galaxian.js
index fcf4c0bd..526b1448 100644
--- a/src/platform/galaxian.js
+++ b/src/platform/galaxian.js
@@ -150,72 +150,24 @@ var GalaxianPlatform = function(mainElement) {
oram = new RAM(0x100);
outlatches = new RAM(0x8);
membus = {
- read: function(address) {
- if (address < 0x4000) {
- return (rom ? rom[address] : 0) & 0xff;
- } else if (address < 0x4800) {
- address &= 0x3ff;
- return ram.mem[address] & 0xff;
- } else if (address >= 0x5000 && address < 0x5800) {
- address &= 0x3ff;
- return vram.mem[address] & 0xff;
- } else if (address >= 0x5800 && address < 0x6000) {
- address &= 0xff;
- return oram.mem[address] & 0xff;
- } else if (address >= 0x6000 && address < 0x6800) {
- address &= 0x7;
- switch (address) {
- case 0:
- return inputs[0];
- }
- } else if (address >= 0x6800 && address < 0x7000) {
- return inputs[1];
- } else if (address >= 0x7000 && address < 0x7800) {
- address &= 0x7;
- switch (address) {
- case 0:
- return inputs[2];
- }
- } else if (address >= 0x7800 && address < 0x8000) {
- watchdog_counter = INITIAL_WATCHDOG;
- } else {
- console.log("read", hex(address));
- return 0;
- }
- },
- write: function(address, value) {
- //console.log("write", hex(address,4), hex(value,2));
- if (address >= 0x4000 && address < 0x4800) {
- address &= 0x3ff;
- ram.mem[address] = value;
- } else if (address >= 0x5000 && address < 0x5800) {
- address &= 0x3ff;
- vram.mem[address] = value;
- } else if (address >= 0x5800 && address < 0x6000) {
- address &= 0xff;
- oram.mem[address] = value;
- } else if (address >= 0x6000 && address < 0x6800) {
- address &= 0x7;
- outlatches.mem[address] = value;
- } else if (address >= 0x6800 && address < 0x7000) {
- address &= 0x7;
- // TODO: sound
- } else if (address >= 0x7000 && address < 0x7800) {
- address &= 0x7;
- switch (address) {
- case 1:
- interruptEnabled = value;
- break;
- case 4:
- starsEnabled = value;
- break;
- }
- } else if (address >= 0x7800 && address < 0x8000) {
- // TODO: sound
- } else {
- console.log("write", hex(address), hex(value));
- }
- },
+ read: new AddressDecoder([
+ [0x0000, 0x3fff, 0, function(a) { return rom ? rom[a] : null; }],
+ [0x4000, 0x47ff, 0x3ff, function(a) { return ram.mem[a]; }],
+ [0x5000, 0x57ff, 0x3ff, function(a) { return vram.mem[a]; }],
+ [0x5800, 0x5fff, 0xff, function(a) { return oram.mem[a]; }],
+ [0x6000, 0x6000, 0, function(a) { return inputs[0]; }],
+ [0x6800, 0x6800, 0, function(a) { return inputs[1]; }],
+ [0x7000, 0x7000, 0, function(a) { return inputs[2]; }],
+ [0x7800, 0x7800, 0, function(a) { watchdog_counter = INITIAL_WATCHDOG; }],
+ ]),
+ write: new AddressDecoder([
+ [0x4000, 0x47ff, 0x3ff, function(a,v) { ram.mem[a] = v; }],
+ [0x5000, 0x57ff, 0x3ff, function(a,v) { vram.mem[a] = v; }],
+ [0x5800, 0x5fff, 0xff, function(a,v) { oram.mem[a] = v; }],
+ [0x6000, 0x67ff, 0x7, function(a,v) { outlatches.mem[a] = v; }],
+ [0x7001, 0x7001, 0, function(a,v) { interruptEnabled = v; }],
+ [0x7004, 0x7004, 0, function(a,v) { starsEnabled = v; }],
+ ]),
isContended: function() { return false; },
};
iobus = {
@@ -323,7 +275,7 @@ var GalaxianPlatform = function(mainElement) {
watchdog_counter = state.wdc;
interruptEnabled = state.ie;
starsEnabled = state.se;
- frameCounter = fc;
+ frameCounter = state.fc;
inputs[0] = state.in0;
inputs[1] = state.in1;
inputs[2] = state.in2;
@@ -356,7 +308,6 @@ var GalaxianPlatform = function(mainElement) {
this.pause = function() {
timer.stop();
audio.stop();
- console.log(JSON.stringify(this.saveState()));
}
this.resume = function() {
timer.start();
diff --git a/src/platform/spaceinv.js b/src/platform/spaceinv.js
index c3ae9e0c..b18efba7 100644
--- a/src/platform/spaceinv.js
+++ b/src/platform/spaceinv.js
@@ -46,29 +46,20 @@ var SpaceInvadersPlatform = function(mainElement) {
ram = new RAM(0x2000);
displayPCs = new Uint16Array(new ArrayBuffer(0x2000*2));
membus = {
- read: function(address) {
- if (address < 0x2000) {
- return (rom ? rom[address] : 0) & 0xff;
- } else {
- address &= 0x1fff;
- return ram.mem[address] & 0xff;
- }
- },
- write: function(address, value) {
- //console.log("write", hex(address,4), hex(value,2));
- if (address >= 0x2000) {
- address &= 0x1fff;
- value &= 0xff;
- ram.mem[address] = value;
- if (address >= 0x400) {
- // TODO: dirty flags
- var ofs = (address - 0x400)*8;
- for (var i=0; i<8; i++)
- pixels[ofs+i] = (value & (1<