apple2ts icon indicating copy to clipboard operation
apple2ts copied to clipboard

Apple II Emulator in TypeScript

Apple2TS - Apple II Emulator in Typescript

Created by Chris Torrence (chris<at>ct6502<dot>org), with significant contributions from Michael Morrison (codebythepound<at>gmail<dot>com).

node.js CI build/deploy

This project was originally create using Create React App and was then migrated to vite following these steps.

Available NPM Scripts

In the project directory, you can run:

npm install

npm start

Runs the app in the development mode. This should automatically open your browser to http://localhost:6502.

The page will reload when you make changes. You may also see any lint errors in the console.

Testing

Runs all of the jest unit tests:

npm test

Run a single test:

npm test memory.test.ts

Run in watch mode:

npm test -- --watch

Building the Package

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

Upgrade Packages

https://www.hostingadvice.com/how-to/update-npm-packages/

Install npm-check-updates package

npm install -g npm-check-updates

npm outdated

ncu --upgrade

npm install

VS Code Chrome Debugging

Stop all running Chrome instances and then:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

Use npm start to start the running instance.

In launch.json, add a launch configuration:

    {
      "name": "Attach to Chrome",
      "port": 9222,
      "request": "attach",
      "type": "chrome",
      "url": "http://localhost:6502",
      "webRoot": "${workspaceFolder}"
    },

Android Chrome Debugging

Using Android Studio, create a new device (like a phone), start the device.

Start the emulator with npm run host to make the application available to the network. You must do this - you cannot run on localhost:6502 or 10.0.2.2:6502 on Android (it's some conflict with vite and chrome).

Navigate to the provided URL - it will be something like 10.0.0.xxx:6502.

On your Desktop Chrome, go to chrome://inspect/#devices and then choose the appropriate "Remote Target".

iOS Debugging

https://developer.apple.com/documentation/safari-developer-tools/inspecting-ios

Jest Test Debugging in VS Code

In VS Code, add breakpoints to the test code. Then open up package.json, hover over the "test" script, and select 'Debug Script'.

Localhost Certificates

Gamepads will only work with a secure (https) context. To enable https when running from localhost, you need to generate a certificate and install it on your system.

Apple II ROMs

This repository doesn't contain any Apple II ROMs. However, these are fairly easy to find on the web. To make a ROM image, save the raw binary data from the C000-FFFF ROM in a single file. Then convert the file to a Base64 encoding. On the Mac, I used the following command:

    openssl base64 -in rom_2e.bin -out rom_2e.base64.ts

Finally, edit the .ts file, and change the file to be an exported string variable by prepending:

    export const rom=`

Don't forget to append the trailing back quote ` at the end of the file.

Apple II 6502 References

NMOS 6502 Opcodes

6502 Programmers Reference

Assembly Lines: The Complete Book

Flowcharts for Apple II Emulator

Apple II Emulator - Main Loop

Process Instruction

Additional Info and Sponsors

sponsored-by-grida