News for hackers. Stuff that matters.
Re:Implement an emulator for a fantasy CPU in JavaScript by MuffinFlavored on Sunday August 23, 2020 @08:20PM (#24256481)
I've written a SuperH and TriCore emulator from scratch (qemu wouldn't cut it). I couldn't do it in JavaScript because it falls apart when it comes to bit-shifting and integer arithmetic. A lot of processors rely on the C-like functionality of int32_t, uint32_t, etc.

>>> 0 in JavaScript just doesn't cut it.

Re:Implement an emulator for a fantasy CPU in JavaScript by dnautics on Sunday August 23, 2020 @08:29PM (#24256534)
You can use typedarrays, no? I built a fantasy emulator several years ago, and that was my strategy.
Re:Implement an emulator for a fantasy CPU in JavaScript by MuffinFlavored on Sunday August 23, 2020 @11:36PM (#24257340)
like this?

const a = new Uint8Array([0xFE])

const b = new Uint8Array([0x02])

a[0] = a[0] + b[0]

Re:Implement an emulator for a fantasy CPU in JavaScript by dnautics on Monday August 24, 2020 @12:42PM (#24262411)
yes, although IIRC what I did was more like this:

    const r_idx = {ax: 0, bx: 1...}
    const registers = new Uint8Array([...])
    add = (r1, r2) => registers[r_idx[r1]] = registers[r_idx[r1]] + registers[r_idx[r2]]
which lets you do:

    add("ax", "bx")
which is one step closer to making it look a lot like asm syntax.
Re:Implement an emulator for a fantasy CPU in JavaScript by Jasper_ on Monday August 24, 2020 @01:09PM (#24262764)
I've written quite a number of emulators and file format parses in JavaScript. What was missing for you?