A chip8 and super chip8 emulator.

Overview

(s)chip8 Emulator

CHIP-8 是一种解释型编程语言,由 Joseph Weisbecker 开发。它最初用于 COSMAC VIP 和 Telmac 1800 8 位微型计算机在 70 年代中期。CHIP-8 程序在一个 CHIP-8 虚拟机上运行。它的问世是为了让电子游戏更容易为这些电脑编程。CHIP-8 的简单性,以及它悠久的历史和流行程度,确保了 CHIP-8 模拟器和程序直到今天仍在生产。

本项目的目标:

  • 了解模拟器的编写,实现了一个 Chip8 模拟器(同时兼容 Spuer Chip8 的指令)
  • 分别用 TypeScript 和 Rust 实现了一遍,用熟悉的 TypeScript 先学会 Chip8 的实现,再用 Rust 练练手
  • 通过 Rust 编译 WebAssembly,学习 WebAssembly 的使用

资料:

内存

+---------------+= 0x000 (0) Start of Chip-8 RAM
| 0x000 to 0x1FF|
| Reserved for  |
|  interpreter  |
+---------------+= 0x200 (512) Start of most Chip-8 programs
|               |
|               |
|               |
+- - - - - - - -+= 0x600 (1536) Start of ETI 660 Chip-8 programs
|               |
|               |
|               |
|               |
|               |
| 0x200 to 0xFFF|
|     Chip-8    |
| Program / Data|
|     Space     |
|               |
|               |
|               |
+---------------+= 0xFFF (4095) End of Chip-8 RAM

Chip8 的内存是 4-KB 的大小。每一个内存单元大小为 8-bit,即 1-byte。编号从 0x0000 开始,最后一个是 0x0FFF,从上往下,编号依次变大。一共可以分为 4096(4 * 1024) 个内存单元。内存的地址大小可以使用 12-bit 大小。 地址的描述通常使用三位的十六进制表示。即 0x200,0xFFF 等

0x000 ~ 0x1FF 范围的地址是 chip8 系统内存空间,模拟器用这部分内容存储 Font 数据。

CPU

Chip8 的 CPU 主要用寄存器(register), 定时器(timer),按键缓存(key_pressed_buf),屏幕缓存(screen_buf)组成。

  • 寄存器:
    • 通用寄存器:16 个 8-bit 的通用寄存器,记为 V0 ~ VF,其中 VF 用来表示 flag 标记。可以用一个 16 长度数组表示,数组的每一个元素是一个寄存器,每个元素的类型是 uint8
    • 程序计数器:一个 16-bit 的程序计数器,即 PC 寄存器。初始值为 0x200。Chip8 的内存是 4k,实际上 PC 的最大值是 12-bit。
    • 索引寄存器:一个 16-bit 的地址索引寄存器。
    • 栈顶寄存器:8-bit 的栈顶寄存器,指向当前栈顶。内存直接使用了具有栈特点的数据结构模拟,这个寄存器可以忽略。
  • 计时器:两个 8-bit 的定时器,一个 delay timer, 一个 sound timer,都按照 60hz 的频率递减直到 0
  • 按键缓存:使用一个大小 16 的列表作为按键缓存,映射了 Chip8 的按键,按下的键其值为 1,未按的键是 0
  • 屏幕缓存:传统的 Chip8 使用内存的 0xF00 ~ 0xFFF 用作屏幕缓存。模拟则可以使用另外的数据来存储

Keyboard

chip8 的键盘、及布局如左图所示,程序模拟,将键盘(右图)的按键映射到 Chip8 的按键。

1 2 3 C        1 2 3 4
4 5 6 D   ->   Q W E R
7 8 9 E        A S D F
A 0 B F        Z X C V
You might also like...

✏️ Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped

✏️ Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped

Sugar High Introduction Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped Usage npm install --save sugar-high import { h

Dec 8, 2022

:iphone: A super lightweight HTML, Sass, CSS, and JavaScript framework for building responsive websites

Responsive Boilerplate A powerful, accessible, developer friendly, framework for building responsive websites Responsive Boilerplate is the developers

Dec 22, 2022

Super minimal selector and event library

min.js A super tiny JavaScript library to execute simple DOM querying and hooking event listeners. Aims to return the raw DOM node for you to manipula

Dec 13, 2022

Our super simple URL shortener. Powered by Deno and Supabase.

Feelantera URL Shortener This is our super simple URL shortener. Powered by Supabase and Deno, and Oak for the http framework. You can deploy this pro

Oct 14, 2022

🚀 The super app for creators and their audience.

🚀 The super app for creators and their audience.

OneSocial It's the ultimate super app for creators and their audience. With OneSocial, you can share your thoughts on blog, manage an active newslette

Oct 21, 2022

tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.

tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.

tb-grid Lightweight (1kb gzipped) 12 column grid system, built with css grid. 👉 Demos & Playground Have a look at those examples: Main Demo: https:/

Dec 28, 2022

Super Mario 64 ported to JavaScript and WebAssembly via Emscripten.

SM64-JS Super Mario 64 ported to JavaScript and WebAssembly via Emscripten. REPL Takedown I was forced to take down the REPL for this project due to c

Dec 23, 2022

A super simple static site generator

Teeny: A simple static site generator ⚠️ Disclaimer: This is a tool I built in a couple of hours to generate my personal blog yakkomajuri.github.io. I

Nov 18, 2022

Repo of MVRT's super scout website

MVRT Super Scout Development Clone repo and install dependencies git clone https://github.com/mvrt-115/super-scout-dashboard.git npm install Include

Sep 10, 2022
Owner
daief
明日复明日,明日何其多。我生待明日,万事成蹉跎。
daief
🕹 GBA emulator on your React project - easy and powerful to use!

GBA emulator on your React project - easy and powerful to use! Just three steps to set it up ✨ 1 - Apply GbaProvider import { GbaProvider } from 'reac

Bruno Macabeus 43 Dec 23, 2022
A Chip-8 Emulator written in javascript

Chippy A Chip-8 Emulator written in javascript Live DEMO Features Display Controls CPU Controls Sound Controls Rom Selection Debug Features Register D

Kenneth Lamb 4 Jun 15, 2022
A browser-based emulator for Zeal 8-bit Computer

Zeal 8-bit Computer emulator This project is a software emulator for Zeal 8-bit Computer: a homebrew 8-bit computer based on a Z80 CPU. Click here for

Zeal 8-bit 33 Nov 27, 2022
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands

JavaScript Library for Web Based Terminal Emulators Summary jQuery Terminal Emulator is a plugin for creating command line interpreters in your applic

Jakub T. Jankiewicz 2.8k Jan 1, 2023
Multithread emulator. The wrun allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file

wrun This lib allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file. This means tha

Felippe Regazio 9 Nov 5, 2022
Mag🔥Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener

Mag ?? Lit Mag ?? Lit - A super fast and easy-to-use free and open source private encrypted Magnet/HTTP(s) Link Shortener https://maglit.ml Features ✅

null 280 Jan 8, 2023
🌗 1 line of code to apply auto dark / light theme and support custom theme for your website. Super fast and lightweight theme library.

themes.js A super lightweight and fast Theme library with auto system color scheme detection in JavaScript. Features Auto detect Dark / Light mode by

SerKo 4 Nov 29, 2022
A super tiny Javascript library to make DOM elements draggable and movable. ~500 bytes and no dependencies.

dragmove.js A super tiny Javascript library to make DOM elements draggable and movable. Has touch screen support. Zero dependencies and 500 bytes Gzip

Kailash Nadh 814 Dec 29, 2022
A super simple and lightweight API to get crypto token live information.

TokenStats ?? ?? A super simple and lightweight API to get crypto token live information. APP URL https://tokenstats.herokuapp.com/ Quick Start To get

Abdulfatai Suleiman 21 Jun 28, 2022
Super Mario Bros using JavaScript and Kaboom.js

mario-kaboom.js Super Mario Bros using JavaScript and kaboom.js ?? This is a game of Super Mario Bros made using javascript and javascript gaming libr

Damini Pandey 3 May 6, 2022