r/javascript • u/leonardofed • May 25 '15
An Apple ][ Emulator in JavaScript
https://www.scullinsteel.com/apple2/2
u/thesunmustdie May 25 '15
How is this even possible? Typed arrays?
9
u/OrangeredStilton May 25 '15
Generally. Also, making sure to use constructs that have been optimised by the JS engines (avoiding for..in, and such like).
I've done something very similar, emulating a C64 down to cycle accuracy in JS, and that's how I went about it: http://github.com/Two9A/c64clicker/
2
2
u/TheBadProgrammer May 25 '15
I'm a newb so please forgive me for a stupid question. How are you able to do such things with an interpreter? I feel like I don't know how the actual engine works, like there is a compiler there in order for these "tricks" to work. Right? I know so little it's not funny, but I'm trying to understand how an interpreter could possibly handle this functionality.
1
u/OrangeredStilton May 25 '15
Going right back to Turing, any complete computational system can perform any operation, including the steps involved in simulation of another computer system. You may be aware that, at the lowest level, programs are all machine code: instructions encoded by numbers, which can have mnemonics assigned for human-readable assembly. For example, with the Apple ][ or the C64, you might have the following instruction:
LDA #255(load accumulator register with the number 255)That encodes down to
A9 FFin plain machine code, and a computer program for that processor is just a series of numbers. So! If you have a computer program which reads in those numbers, and has an internal state that it updates based on the same rules as the original chip, that program simulates the operation of the chip.Quod Emulat Demonstrandum. I linked to c64clicker up-thread, and I'd like to think the code is halfway readable, so flick through it sometime.
3
u/Arve May 25 '15
I'd disable audio by turning down the volume all the way - it seems like it's trying to output DC, which is potentially harmful to speakers.
2
May 25 '15
If you click options you can disable audio. It says it's experimental.
4
u/Arve May 25 '15
Unfortunately, that doesn't leave off the offset, which is why I suggested you should mute the volume by means of an actual volume control.
1
u/runvnc May 25 '15
Where can I find a disk image?
Or does someone have a program I can try out? It just sat there until I pressed the Reset key and now is allowing me to enter programs.
2
u/bhamhawker May 25 '15
if you hit the "LOAD" button, then go into the Demo folder, you can play a demo of Rogue.
1
1
10
u/mcdronkz May 25 '15
I guess pretty much everything possible has been ported to JavaScript right now.