# JS로 에뮬레이터 만들고 멀티UI와 연동하기

> Clean Markdown view of GeekNews topic #1911. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=1911](https://news.hada.io/topic?id=1911)
- GeekNews Markdown: [https://news.hada.io/topic/1911.md](https://news.hada.io/topic/1911.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2020-04-18T09:15:17+09:00
- Updated: 2020-04-18T09:15:17+09:00
- Original source: [taniarascia.com](https://www.taniarascia.com/writing-an-emulator-in-javascript-chip8/)
- Points: 7
- Comments: 3

## Topic Body

- 1970년대 8비트 머신에서 사용하던 Chip-8 인터프리터를 JS로 구현

- 웹/CLI/네이티브 앱과 연동

- 실제로는 인터프리터지만, 에뮬레이터와 가깝기 때문에 에뮬레이터를 만드는 법을 배우려는 사람에게 적합.

- Memory(4KB), Program Counter, Register, Index Register, Stack, Stack Pointer, Timer 등을 변수로 선언

  CPU를 구성하고, 4x4 HEX 키보드, 64x32 디스플레이 를 구현

- 자바스크립트 코드로 Raylib Node.js 바인딩을 이용해서 다양한 네이티브 환경에서 실행가능

## Comments



### Comment 1608

- Author: xguru
- Created: 2020-04-18T09:15:42+09:00
- Points: 1

8비트 구조라 코드가 복잡하지 않아서 꽤 읽기 재미있습니다.

아래 코드가 인상적이었어요.

class CPU {

ㅤconstructor() {

ㅤㅤthis.memory = new Uint8Array(4096)

ㅤㅤthis.registers = new Uint8Array(16)

ㅤㅤthis.stack = new Uint16Array(16)

ㅤㅤthis.ST = 0

ㅤㅤthis.DT = 0

ㅤㅤthis.I = 0

ㅤㅤthis.SP = -1

ㅤㅤthis.PC = 0x200

ㅤ}

}

### Comment 1613

- Author: barmi
- Created: 2020-04-18T16:52:59+09:00
- Points: 1
- Parent comment: 1608
- Depth: 1

스택이 16바이트로 너무 작다고 생각했는데, 메모리가 4k라 가능할것 같네요.

### Comment 1614

- Author: barmi
- Created: 2020-04-18T16:53:57+09:00
- Points: 1
- Parent comment: 1613
- Depth: 2

아~ 16워드, 워드 16개
