ac6502 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/components/CPU.js +1170 -0
- package/dist/components/CPU.js.map +1 -0
- package/dist/components/Cart.js +23 -0
- package/dist/components/Cart.js.map +1 -0
- package/dist/components/IO/Empty.js +19 -0
- package/dist/components/IO/Empty.js.map +1 -0
- package/dist/components/IO/GPIOAttachments/GPIOAttachment.js +71 -0
- package/dist/components/IO/GPIOAttachments/GPIOAttachment.js.map +1 -0
- package/dist/components/IO/GPIOAttachments/GPIOJoystickAttachment.js +90 -0
- package/dist/components/IO/GPIOAttachments/GPIOJoystickAttachment.js.map +1 -0
- package/dist/components/IO/GPIOAttachments/GPIOKeyboardEncoderAttachment.js +489 -0
- package/dist/components/IO/GPIOAttachments/GPIOKeyboardEncoderAttachment.js.map +1 -0
- package/dist/components/IO/GPIOAttachments/GPIOKeyboardMatrixAttachment.js +274 -0
- package/dist/components/IO/GPIOAttachments/GPIOKeyboardMatrixAttachment.js.map +1 -0
- package/dist/components/IO/GPIOCard.js +597 -0
- package/dist/components/IO/GPIOCard.js.map +1 -0
- package/dist/components/IO/InputBoard.js +19 -0
- package/dist/components/IO/InputBoard.js.map +1 -0
- package/dist/components/IO/LCDCard.js +19 -0
- package/dist/components/IO/LCDCard.js.map +1 -0
- package/dist/components/IO/RAMCard.js +63 -0
- package/dist/components/IO/RAMCard.js.map +1 -0
- package/dist/components/IO/RTCCard.js +483 -0
- package/dist/components/IO/RTCCard.js.map +1 -0
- package/dist/components/IO/SerialCard.js +282 -0
- package/dist/components/IO/SerialCard.js.map +1 -0
- package/dist/components/IO/SoundCard.js +620 -0
- package/dist/components/IO/SoundCard.js.map +1 -0
- package/dist/components/IO/StorageCard.js +428 -0
- package/dist/components/IO/StorageCard.js.map +1 -0
- package/dist/components/IO/VGACard.js +9 -0
- package/dist/components/IO/VGACard.js.map +1 -0
- package/dist/components/IO/VideoCard.js +623 -0
- package/dist/components/IO/VideoCard.js.map +1 -0
- package/dist/components/IO.js +3 -0
- package/dist/components/IO.js.map +1 -0
- package/dist/components/Machine.js +310 -0
- package/dist/components/Machine.js.map +1 -0
- package/dist/components/RAM.js +24 -0
- package/dist/components/RAM.js.map +1 -0
- package/dist/components/ROM.js +23 -0
- package/dist/components/ROM.js.map +1 -0
- package/dist/index.js +441 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/CPU.test.js +1626 -0
- package/dist/tests/CPU.test.js.map +1 -0
- package/dist/tests/Cart.test.js +119 -0
- package/dist/tests/Cart.test.js.map +1 -0
- package/dist/tests/IO/GPIOAttachments/GPIOAttachment.test.js +339 -0
- package/dist/tests/IO/GPIOAttachments/GPIOAttachment.test.js.map +1 -0
- package/dist/tests/IO/GPIOAttachments/GPIOJoystickAttachment.test.js +126 -0
- package/dist/tests/IO/GPIOAttachments/GPIOJoystickAttachment.test.js.map +1 -0
- package/dist/tests/IO/GPIOAttachments/GPIOKeyboardEncoderAttachment.test.js +779 -0
- package/dist/tests/IO/GPIOAttachments/GPIOKeyboardEncoderAttachment.test.js.map +1 -0
- package/dist/tests/IO/GPIOAttachments/GPIOKeyboardMatrixAttachment.test.js +355 -0
- package/dist/tests/IO/GPIOAttachments/GPIOKeyboardMatrixAttachment.test.js.map +1 -0
- package/dist/tests/IO/GPIOCard.test.js +503 -0
- package/dist/tests/IO/GPIOCard.test.js.map +1 -0
- package/dist/tests/IO/RAMCard.test.js +229 -0
- package/dist/tests/IO/RAMCard.test.js.map +1 -0
- package/dist/tests/IO/RTCCard.test.js +177 -0
- package/dist/tests/IO/RTCCard.test.js.map +1 -0
- package/dist/tests/IO/SerialCard.test.js +423 -0
- package/dist/tests/IO/SerialCard.test.js.map +1 -0
- package/dist/tests/IO/SoundCard.test.js +528 -0
- package/dist/tests/IO/SoundCard.test.js.map +1 -0
- package/dist/tests/IO/StorageCard.test.js +647 -0
- package/dist/tests/IO/StorageCard.test.js.map +1 -0
- package/dist/tests/IO/VideoCard.test.js +549 -0
- package/dist/tests/IO/VideoCard.test.js.map +1 -0
- package/dist/tests/Machine.test.js +383 -0
- package/dist/tests/Machine.test.js.map +1 -0
- package/dist/tests/RAM.test.js +160 -0
- package/dist/tests/RAM.test.js.map +1 -0
- package/dist/tests/ROM.test.js +123 -0
- package/dist/tests/ROM.test.js.map +1 -0
- package/jest.config.cjs +9 -0
- package/package.json +43 -0
- package/src/components/CPU.ts +1371 -0
- package/src/components/Cart.ts +20 -0
- package/src/components/IO/GPIOAttachments/GPIOAttachment.ts +189 -0
- package/src/components/IO/GPIOAttachments/GPIOJoystickAttachment.ts +99 -0
- package/src/components/IO/GPIOAttachments/GPIOKeyboardEncoderAttachment.ts +465 -0
- package/src/components/IO/GPIOAttachments/GPIOKeyboardMatrixAttachment.ts +287 -0
- package/src/components/IO/GPIOCard.ts +677 -0
- package/src/components/IO/RAMCard.ts +68 -0
- package/src/components/IO/RTCCard.ts +518 -0
- package/src/components/IO/SerialCard.ts +335 -0
- package/src/components/IO/SoundCard.ts +711 -0
- package/src/components/IO/StorageCard.ts +473 -0
- package/src/components/IO/VideoCard.ts +730 -0
- package/src/components/IO.ts +11 -0
- package/src/components/Machine.ts +364 -0
- package/src/components/RAM.ts +23 -0
- package/src/components/ROM.ts +19 -0
- package/src/index.ts +474 -0
- package/src/tests/CPU.test.ts +2045 -0
- package/src/tests/Cart.test.ts +149 -0
- package/src/tests/IO/GPIOAttachments/GPIOAttachment.test.ts +413 -0
- package/src/tests/IO/GPIOAttachments/GPIOJoystickAttachment.test.ts +147 -0
- package/src/tests/IO/GPIOAttachments/GPIOKeyboardEncoderAttachment.test.ts +961 -0
- package/src/tests/IO/GPIOAttachments/GPIOKeyboardMatrixAttachment.test.ts +449 -0
- package/src/tests/IO/GPIOCard.test.ts +644 -0
- package/src/tests/IO/RAMCard.test.ts +284 -0
- package/src/tests/IO/RTCCard.test.ts +222 -0
- package/src/tests/IO/SerialCard.test.ts +530 -0
- package/src/tests/IO/SoundCard.test.ts +659 -0
- package/src/tests/IO/StorageCard.test.ts +787 -0
- package/src/tests/IO/VideoCard.test.ts +668 -0
- package/src/tests/Machine.test.ts +437 -0
- package/src/tests/RAM.test.ts +196 -0
- package/src/tests/ROM.test.ts +154 -0
- package/tsconfig.json +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# 6502 Emulator
|
|
2
|
+
|
|
3
|
+
A comprehensive, cycle-accurate emulator for the [A.C. Wright Design 6502](https://github.com/acwright/6502) computer system, built with TypeScript and Node.js.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This emulator provides a complete software implementation of a 65C02-based computer system, designed to run the same code as the hardware implementation. It features full I/O peripheral support, including video, sound, serial communication, storage, and GPIO interfaces.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Cycle-Accurate 65C02 CPU Emulation**
|
|
12
|
+
- Full instruction set support
|
|
13
|
+
- Accurate timing and cycle counting
|
|
14
|
+
- IRQ and NMI interrupt handling
|
|
15
|
+
|
|
16
|
+
- **Memory Architecture**
|
|
17
|
+
- System RAM and ROM
|
|
18
|
+
- Cartridge support for program loading
|
|
19
|
+
- Multiple RAM expansion cards
|
|
20
|
+
|
|
21
|
+
- **Video Output**
|
|
22
|
+
- TMS9918 Video Display Processor emulation
|
|
23
|
+
- Multiple graphics modes (Graphics I/II, Text, Multicolor)
|
|
24
|
+
- 256×192 active display area in 320×240 buffer
|
|
25
|
+
- Hardware sprites support
|
|
26
|
+
- Real-time rendering via SDL
|
|
27
|
+
|
|
28
|
+
- **Audio Output**
|
|
29
|
+
- MOS 6518 SID Sound card emulation with sample generation
|
|
30
|
+
- 44.1 kHz audio output
|
|
31
|
+
- SDL audio integration
|
|
32
|
+
|
|
33
|
+
- **I/O Peripherals**
|
|
34
|
+
- **Serial Card**: 6551 UART communication with configurable baud rate, parity, data/stop bits
|
|
35
|
+
- **Storage Card**: Compact Flash 8-bit IDE mode persistent storage emulation
|
|
36
|
+
- **RTC Card**: DS1511Y real-time clock emulation with IRQ/NMI support
|
|
37
|
+
- **GPIO Card**: 65C22 VIA (Versatile Interface Adapter) emulation
|
|
38
|
+
- Two 8-bit bidirectional I/O ports
|
|
39
|
+
- Two 16-bit timers with interrupts
|
|
40
|
+
- Shift register for serial I/O
|
|
41
|
+
|
|
42
|
+
- **Input Devices**
|
|
43
|
+
- Keyboard support (matrix and encoder modes)
|
|
44
|
+
- Joystick/gamepad support with button mapping
|
|
45
|
+
- SDL input handling
|
|
46
|
+
|
|
47
|
+
- **Development Features**
|
|
48
|
+
- Comprehensive test suite with Jest
|
|
49
|
+
- Command-line interface with multiple options
|
|
50
|
+
- Debug and monitoring capabilities
|
|
51
|
+
- Code coverage reporting
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
Get up and running in seconds:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Install globally
|
|
59
|
+
npm install -g ac6502
|
|
60
|
+
|
|
61
|
+
# Run the emulator
|
|
62
|
+
ac6502
|
|
63
|
+
|
|
64
|
+
# Load a ROM
|
|
65
|
+
ac6502 --rom /path/to/rom.bin
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
### Via NPM (Recommended)
|
|
71
|
+
|
|
72
|
+
Install globally via npm:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install -g ac6502
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### From Source
|
|
79
|
+
|
|
80
|
+
#### Prerequisites
|
|
81
|
+
|
|
82
|
+
- Node.js (v16 or higher)
|
|
83
|
+
- npm or yarn
|
|
84
|
+
|
|
85
|
+
#### Install Dependencies
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm install
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Build
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm run build
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
98
|
+
|
|
99
|
+
### Basic Usage
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm start
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or use the CLI directly:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
ac6502 [options]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Command-Line Options
|
|
112
|
+
|
|
113
|
+
- `-c, --cart <path>` - Load a cartridge ROM file
|
|
114
|
+
- `-r, --rom <path>` - Load a system ROM file
|
|
115
|
+
- `-f, --freq <frequency>` - Set CPU frequency in Hz (default: 2000000)
|
|
116
|
+
- `-s, --scale <factor>` - Set display scale factor (default: 2)
|
|
117
|
+
- `-p, --port <device>` - Serial port device path
|
|
118
|
+
- `-b, --baudrate <rate>` - Serial baud rate (default: 9600)
|
|
119
|
+
- `-a, --parity <type>` - Serial parity: none, even, odd (default: none)
|
|
120
|
+
- `-d, --databits <bits>` - Serial data bits: 5, 6, 7, 8 (default: 8)
|
|
121
|
+
- `-t, --stopbits <bits>` - Serial stop bits: 1, 1.5, 2 (default: 1)
|
|
122
|
+
- `-S, --storage <path>` - Set storage file path for Compact Flash card persistence
|
|
123
|
+
|
|
124
|
+
### Examples
|
|
125
|
+
|
|
126
|
+
Load a cartridge:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
ac6502 --cart /path/to/game.bin
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Connect to serial hardware:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
ac6502 --port /dev/ttyUSB0 --baudrate 9600 --rom /path/to/monitor.bin
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Architecture
|
|
139
|
+
|
|
140
|
+
### Component Structure
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
Machine
|
|
144
|
+
├── CPU (65C02)
|
|
145
|
+
├── RAM (System Memory)
|
|
146
|
+
├── ROM (System BIOS/Monitor)
|
|
147
|
+
├── Cart (Optional Cartridge)
|
|
148
|
+
└── I/O Cards (8 slots)
|
|
149
|
+
├── IO1: RAM Card (Expansion)
|
|
150
|
+
├── IO2: RAM Card (Expansion)
|
|
151
|
+
├── IO3: RTC Card (Real-Time Clock)
|
|
152
|
+
├── IO4: Storage Card (Compact Flash 8-bit IDE Mode)
|
|
153
|
+
├── IO5: Serial Card (6551 UART)
|
|
154
|
+
├── IO6: GPIO Card (65C22 VIA)
|
|
155
|
+
├── IO7: Sound Card (6581 SID)
|
|
156
|
+
└── IO8: Video Card (TMS9918)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### GPIO Attachments
|
|
160
|
+
|
|
161
|
+
The GPIO card supports multiple attachment types:
|
|
162
|
+
|
|
163
|
+
- **Keyboard Matrix**: PS/2-style keyboard matrix scanning
|
|
164
|
+
- **Keyboard Encoder**: Parallel keyboard encoder
|
|
165
|
+
- **Joystick**: Game controller with 8 buttons and directional input
|
|
166
|
+
|
|
167
|
+
### Memory Map
|
|
168
|
+
|
|
169
|
+
The system uses a standard 6502 memory layout with I/O cards mapped into the address space. Each I/O card occupies a dedicated region accessible via memory-mapped registers.
|
|
170
|
+
|
|
171
|
+
## Development
|
|
172
|
+
|
|
173
|
+
### Project Structure
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
src/
|
|
177
|
+
├── index.ts # Main entry point and emulator loop
|
|
178
|
+
├── components/
|
|
179
|
+
│ ├── CPU.ts # 65C02 CPU implementation
|
|
180
|
+
│ ├── Machine.ts # System integration
|
|
181
|
+
│ ├── RAM.ts # RAM module
|
|
182
|
+
│ ├── ROM.ts # ROM module
|
|
183
|
+
│ ├── Cart.ts # Cartridge support
|
|
184
|
+
│ ├── IO.ts # I/O interface
|
|
185
|
+
│ └── IO/ # I/O peripheral implementations
|
|
186
|
+
│ ├── GPIOCard.ts
|
|
187
|
+
│ ├── RAMCard.ts
|
|
188
|
+
│ ├── RTCCard.ts
|
|
189
|
+
│ ├── SerialCard.ts
|
|
190
|
+
│ ├── SoundCard.ts
|
|
191
|
+
│ ├── StorageCard.ts
|
|
192
|
+
│ ├── VideoCard.ts
|
|
193
|
+
│ └── GPIOAttachments/
|
|
194
|
+
│ ├── GPIOAttachment.ts
|
|
195
|
+
│ ├── GPIOJoystickAttachment.ts
|
|
196
|
+
│ ├── GPIOKeyboardEncoderAttachment.ts
|
|
197
|
+
│ └── GPIOKeyboardMatrixAttachment.ts
|
|
198
|
+
└── tests/ # Comprehensive test suite
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Running Tests
|
|
202
|
+
|
|
203
|
+
Run all tests:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
npm test
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Watch mode for development:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
npm run test:watch
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Generate coverage report:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
npm run test:coverage
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Release Build
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
git tag vX.Y.Z
|
|
225
|
+
git push origin main --tags
|
|
226
|
+
npm publish
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Technical Details
|
|
230
|
+
|
|
231
|
+
- **Language**: TypeScript
|
|
232
|
+
- **Target**: CommonJS (Node.js)
|
|
233
|
+
- **Testing**: Jest with ts-jest
|
|
234
|
+
- **Graphics**: SDL via @kmamal/sdl
|
|
235
|
+
- **Serial**: SerialPort library
|
|
236
|
+
- **CLI**: Commander.js
|
|
237
|
+
|
|
238
|
+
## Performance
|
|
239
|
+
|
|
240
|
+
The emulator targets 2 MHz operation by default (configurable) and attempts to maintain accurate timing by synchronizing with real-time clock cycles. The frame rate is capped at 60 FPS for video output.
|
|
241
|
+
|
|
242
|
+
## Credits
|
|
243
|
+
|
|
244
|
+
- CPU implementation adapted from [OneLoneCoder's olcNES](https://github.com/OneLoneCoder/olcNES)
|
|
245
|
+
- TMS9918 implementation based on [vrEmuTms9918](https://github.com/visrealm/vrEmuTms9918) by Troy Schrapel
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT License - See [LICENSE](LICENSE) file for details
|
|
250
|
+
|
|
251
|
+
## Author
|
|
252
|
+
|
|
253
|
+
A.C. Wright
|
|
254
|
+
|
|
255
|
+
## Repository
|
|
256
|
+
|
|
257
|
+
[https://github.com/acwright/6502-Emulator](https://github.com/acwright/6502-Emulator)
|
|
258
|
+
|
|
259
|
+
## Contributing
|
|
260
|
+
|
|
261
|
+
This project is part of the [A.C. Wright Design 6502](https://github.com/acwright/6502) hardware project. Contributions, issues, and feature requests are welcome!
|