diff --git a/emu6502_web/pkg/emu6502_web.js b/emu6502_web/pkg/emu6502_web.js new file mode 100644 index 0000000..2617472 --- /dev/null +++ b/emu6502_web/pkg/emu6502_web.js @@ -0,0 +1,607 @@ +let wasm; + +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +function getObject(idx) { return heap[idx]; } + +let heap_next = heap.length; + +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + +let cachedUint8ArrayMemory0 = null; + +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(state => { + wasm.__wbindgen_export_0.get(state.dtor)(state.a, state.b) +}); + +function makeMutClosure(arg0, arg1, dtor, f) { + const state = { a: arg0, b: arg1, cnt: 1, dtor }; + const real = (...args) => { + // First up with a closure we increment the internal reference + // count. This ensures that the Rust closure environment won't + // be deallocated while we're invoking it. + state.cnt++; + const a = state.a; + state.a = 0; + try { + return f(a, state.b, ...args); + } finally { + if (--state.cnt === 0) { + wasm.__wbindgen_export_0.get(state.dtor)(a, state.b); + CLOSURE_DTORS.unregister(state); + } else { + state.a = a; + } + } + }; + real.original = state; + CLOSURE_DTORS.register(real, state, state); + return real; +} +function __wbg_adapter_18(arg0, arg1, arg2) { + wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc1d035a6de362fd8(arg0, arg1, addHeapObject(arg2)); +} + +let WASM_VECTOR_LEN = 0; + +const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +function passStringToWasm0(arg, malloc, realloc) { + + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8ArrayMemory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8ArrayMemory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} +/** +* @returns {Promise} +*/ +export function init_emul() { + const ret = wasm.init_emul(); + return takeObject(ret); +} + +let cachedDataViewMemory0 = null; + +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); + } +} +function __wbg_adapter_69(arg0, arg1, arg2, arg3) { + wasm.wasm_bindgen__convert__closures__invoke2_mut__ha587152db2951b09(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); +} + +const EmulatorFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_emulator_free(ptr >>> 0, 1)); +/** +*/ +export class Emulator { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Emulator.prototype); + obj.__wbg_ptr = ptr; + EmulatorFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + EmulatorFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_emulator_free(ptr, 0); + } + /** + * @param {string} name + * @param {Uint8Array} array + * @param {number} drive + * @returns {boolean} + */ + load_disk(name, array, drive) { + const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + const ptr1 = passArray8ToWasm0(array, wasm.__wbindgen_malloc); + const len1 = WASM_VECTOR_LEN; + const ret = wasm.emulator_load_disk(this.__wbg_ptr, ptr0, len0, ptr1, len1, drive); + return ret !== 0; + } + /** + * @returns {Uint8ClampedArray} + */ + frame_buffer() { + const ret = wasm.emulator_frame_buffer(this.__wbg_ptr); + return takeObject(ret); + } + /** + * @param {boolean} state + */ + video_50hz(state) { + wasm.emulator_video_50hz(this.__wbg_ptr, state); + } + /** + */ + clear_dirty_page_frame_buffer() { + wasm.emulator_clear_dirty_page_frame_buffer(this.__wbg_ptr); + } + /** + * @returns {Uint8ClampedArray} + */ + get_dirty_region_frame_buffer() { + const ret = wasm.emulator_get_dirty_region_frame_buffer(this.__wbg_ptr); + return takeObject(ret); + } + /** + * @returns {Int16Array} + */ + sound_buffer() { + const ret = wasm.emulator_sound_buffer(this.__wbg_ptr); + return takeObject(ret); + } + /** + */ + clear_sound_buffer() { + wasm.emulator_clear_sound_buffer(this.__wbg_ptr); + } + /** + */ + step_cpu() { + wasm.emulator_step_cpu(this.__wbg_ptr); + } + /** + * @returns {number} + */ + cpu_cycles() { + const ret = wasm.emulator_cpu_cycles(this.__wbg_ptr); + return ret >>> 0; + } + /** + * @returns {boolean} + */ + is_video_50hz() { + const ret = wasm.emulator_is_video_50hz(this.__wbg_ptr); + return ret !== 0; + } + /** + */ + interrupt_reset() { + wasm.emulator_interrupt_reset(this.__wbg_ptr); + } + /** + * @param {number} index + * @param {number} value + */ + set_paddle(index, value) { + wasm.emulator_set_paddle(this.__wbg_ptr, index, value); + } + /** + * @param {number} index + */ + reset_paddle(index) { + wasm.emulator_reset_paddle(this.__wbg_ptr, index); + } + /** + * @param {number} index + * @param {number} value + */ + pushbutton_latch(index, value) { + wasm.emulator_pushbutton_latch(this.__wbg_ptr, index, value); + } + /** + * @param {number} value + */ + keyboard_latch(value) { + wasm.emulator_keyboard_latch(this.__wbg_ptr, value); + } + /** + * @param {boolean} flag + */ + any_key_down(flag) { + wasm.emulator_any_key_down(this.__wbg_ptr, flag); + } + /** + * @returns {boolean} + */ + is_apple2e() { + const ret = wasm.emulator_is_apple2e(this.__wbg_ptr); + return ret !== 0; + } + /** + * @param {boolean} state + */ + full_speed(state) { + wasm.emulator_full_speed(this.__wbg_ptr, state); + } + /** + */ + toggle_joystick() { + wasm.emulator_toggle_joystick(this.__wbg_ptr); + } + /** + * @returns {boolean} + */ + is_disk_motor_on() { + const ret = wasm.emulator_is_disk_motor_on(this.__wbg_ptr); + return ret !== 0; + } + /** + * @param {boolean} ntsc + */ + video_ntsc(ntsc) { + wasm.emulator_video_ntsc(this.__wbg_ptr, ntsc); + } +} + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + if (module.headers.get('Content-Type') != 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbg_emulator_new = function(arg0) { + const ret = Emulator.__wrap(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); + }; + imports.wbg.__wbg_queueMicrotask_48421b3cc9052b68 = function(arg0) { + const ret = getObject(arg0).queueMicrotask; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_function = function(arg0) { + const ret = typeof(getObject(arg0)) === 'function'; + return ret; + }; + imports.wbg.__wbindgen_cb_drop = function(arg0) { + const obj = takeObject(arg0).original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + return ret; + }; + imports.wbg.__wbg_queueMicrotask_12a30234db4045d3 = function(arg0) { + queueMicrotask(getObject(arg0)); + }; + imports.wbg.__wbg_new_abda76e883ba8a5f = function() { + const ret = new Error(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) { + const ret = getObject(arg1).stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } + }; + imports.wbg.__wbindgen_number_new = function(arg0) { + const ret = arg0; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_undefined = function(arg0) { + const ret = getObject(arg0) === undefined; + return ret; + }; + imports.wbg.__wbg_newnoargs_76313bd6ff35d0f2 = function(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_call_1084a111329e68ce = function() { return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_object_clone_ref = function(arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_self_3093d5d1f7bcb682 = function() { return handleError(function () { + const ret = self.self; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_window_3bcfc4d31bc012f8 = function() { return handleError(function () { + const ret = window.window; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_globalThis_86b222e13bdf32ed = function() { return handleError(function () { + const ret = globalThis.globalThis; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_global_e5a3fe56f8be9485 = function() { return handleError(function () { + const ret = global.global; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_call_89af060b4e1523f2 = function() { return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_getTime_91058879093a1589 = function(arg0) { + const ret = getObject(arg0).getTime(); + return ret; + }; + imports.wbg.__wbg_getTimezoneOffset_c9929a3cc94500fe = function(arg0) { + const ret = getObject(arg0).getTimezoneOffset(); + return ret; + }; + imports.wbg.__wbg_new_7982fb43cfca37ae = function(arg0) { + const ret = new Date(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new0_65387337a95cf44d = function() { + const ret = new Date(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_now_b7a162010a9e75b4 = function() { + const ret = Date.now(); + return ret; + }; + imports.wbg.__wbg_new_b85e72ed1bfd57f9 = function(arg0, arg1) { + try { + var state0 = {a: arg0, b: arg1}; + var cb0 = (arg0, arg1) => { + const a = state0.a; + state0.a = 0; + try { + return __wbg_adapter_69(a, state0.b, arg0, arg1); + } finally { + state0.a = a; + } + }; + const ret = new Promise(cb0); + return addHeapObject(ret); + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_resolve_570458cb99d56a43 = function(arg0) { + const ret = Promise.resolve(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_then_95e6edc0f89b73b1 = function(arg0, arg1) { + const ret = getObject(arg0).then(getObject(arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_buffer_b7b08af79b0b0974 = function(arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_b5293b0eedbac651 = function(arg0, arg1, arg2) { + const ret = new Int16Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_653918b06eb11b62 = function(arg0) { + const ret = new Int16Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_94126d2ad22a595c = function(arg0, arg1, arg2) { + const ret = new Uint8ClampedArray(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_e36b5ccdd852e18d = function(arg0) { + const ret = new Uint8ClampedArray(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_memory = function() { + const ret = wasm.memory; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_closure_wrapper121 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 33, __wbg_adapter_18); + return addHeapObject(ret); + }; + + return imports; +} + +function __wbg_init_memory(imports, memory) { + +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedDataViewMemory0 = null; + cachedUint8ArrayMemory0 = null; + + + + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + + if (typeof module !== 'undefined' && Object.getPrototypeOf(module) === Object.prototype) + ({module} = module) + else + console.warn('using deprecated parameters for `initSync()`; pass a single object instead') + + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(module_or_path) { + if (wasm !== undefined) return wasm; + + + if (typeof module_or_path !== 'undefined' && Object.getPrototypeOf(module_or_path) === Object.prototype) + ({module_or_path} = module_or_path) + else + console.warn('using deprecated parameters for the initialization function; pass a single object instead') + + if (typeof module_or_path === 'undefined') { + module_or_path = new URL('emu6502_web_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { + module_or_path = fetch(module_or_path); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await module_or_path, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync }; +export default __wbg_init; diff --git a/emu6502_web/pkg/emu6502_web_bg.wasm b/emu6502_web/pkg/emu6502_web_bg.wasm new file mode 100644 index 0000000..5a840b2 Binary files /dev/null and b/emu6502_web/pkg/emu6502_web_bg.wasm differ