| @@ -8,6 +8,7 @@ class Memory{ | |||
| if (size > 0){ | |||
| this.__map = new Uint8Array(size); | |||
| } | |||
| this.__listeners = {}; | |||
| } | |||
| get size(){return (this.__map) ? this.__map.length : 0;} | |||
| @@ -20,10 +21,26 @@ class Memory{ | |||
| get byte(){return (this.__map) ? this.__map[this.__addr] : -1;} | |||
| set byte(b){ | |||
| if (!this.__ro && this.__map) | |||
| if (!this.__ro && this.__map){ | |||
| this.__map[this.__addr] = b; | |||
| if (this.__addr in this.__listeners) | |||
| this.__listeners[this.__addr].forEach((fn)=>{fn(b);}); | |||
| } | |||
| } | |||
| onAddressWrite(addr, fn){ | |||
| if (addr < 0 || addr >= this.size) | |||
| throw new RangeError("Memory address is out of bounds."); | |||
| if (typeof(fn) !== 'function') | |||
| throw new TypeErrpr("Expected a callback function."); | |||
| if (!(addr in this.__listeners)) | |||
| this.__listeners[addr] = []; | |||
| // WARNING: Not testing to see if using the same function more than once. | |||
| this.__listeners[addr].push(fn); | |||
| } | |||
| // This method is intended for the emulator to fill a Read-Only memory module with data prior to | |||
| // the start of execution. This method should never be used in a running system. | |||
| sysStore(address, data){ | |||
| if (this.__map){ | |||
| let dc = data; | |||