├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── DaChip8JS.sln ├── DaChip8JS ├── Bridge │ └── bridge.json ├── Chip8.cs ├── DaChip8JS.csproj ├── Font.cs ├── HTML │ └── Index.html ├── KeyCode.cs ├── Main.cs ├── OpCodeData.cs └── packages.config ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [dantup] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | DaChip8JS/HTML/Roms/ 2 | DaChip8JS/HTML/Scripts/ 3 | 4 | ## Ignore Visual Studio temporary files, build results, and 5 | ## files generated by popular Visual Studio add-ons. 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | [Xx]64/ 22 | [Xx]86/ 23 | [Bb]uild/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # Cordova 47 | [Bb]ld/ 48 | [Pp]lugins/android.json 49 | [Pp]lugins/windows.json 50 | [Pp]lugins/wp8.json 51 | [Pp]lugins/remote_ios.json 52 | [Pp]latforms/ 53 | 54 | # DNX 55 | project.lock.json 56 | artifacts/ 57 | 58 | *_i.c 59 | *_p.c 60 | *_i.h 61 | *.ilk 62 | *.meta 63 | *.obj 64 | *.pch 65 | *.pdb 66 | *.pgc 67 | *.pgd 68 | *.rsp 69 | *.sbr 70 | *.tlb 71 | *.tli 72 | *.tlh 73 | *.tmp 74 | *.tmp_proj 75 | *.log 76 | *.vspscc 77 | *.vssscc 78 | .builds 79 | *.pidb 80 | *.svclog 81 | *.scc 82 | 83 | # Chutzpah Test files 84 | _Chutzpah* 85 | 86 | # Visual C++ cache files 87 | ipch/ 88 | *.aps 89 | *.ncb 90 | *.opendb 91 | *.opensdf 92 | *.sdf 93 | *.cachefile 94 | *.VC.db 95 | 96 | # Visual Studio profiler 97 | *.psess 98 | *.vsp 99 | *.vspx 100 | *.sap 101 | 102 | # TFS 2012 Local Workspace 103 | $tf/ 104 | 105 | # Guidance Automation Toolkit 106 | *.gpState 107 | 108 | # ReSharper is a .NET coding add-in 109 | _ReSharper*/ 110 | *.[Rr]e[Ss]harper 111 | *.DotSettings.user 112 | 113 | # JustCode is a .NET coding add-in 114 | .JustCode 115 | 116 | # TeamCity is a build add-in 117 | _TeamCity* 118 | 119 | # DotCover is a Code Coverage Tool 120 | *.dotCover 121 | 122 | # NCrunch 123 | _NCrunch_* 124 | .*crunch*.local.xml 125 | nCrunchTemp_* 126 | 127 | # MightyMoose 128 | *.mm.* 129 | AutoTest.Net/ 130 | 131 | # Web workbench (sass) 132 | .sass-cache/ 133 | 134 | # Installshield output folder 135 | [Ee]xpress/ 136 | 137 | # DocProject is a documentation generator add-in 138 | DocProject/buildhelp/ 139 | DocProject/Help/*.HxT 140 | DocProject/Help/*.HxC 141 | DocProject/Help/*.hhc 142 | DocProject/Help/*.hhk 143 | DocProject/Help/*.hhp 144 | DocProject/Help/Html2 145 | DocProject/Help/html 146 | 147 | # Click-Once directory 148 | publish/ 149 | 150 | # Publish Web Output 151 | *.[Pp]ublish.xml 152 | *.azurePubxml 153 | 154 | # TODO: Un-comment the next line if you do not want to checkin 155 | # your web deploy settings because they may include unencrypted 156 | # passwords 157 | #*.pubxml 158 | *.publishproj 159 | 160 | # NuGet Packages 161 | *.nupkg 162 | # The packages folder can be ignored because of Package Restore 163 | **/packages/* 164 | # except build/, which is used as an MSBuild target. 165 | !**/packages/build/ 166 | # Uncomment if necessary however generally it will be regenerated when needed 167 | #!**/packages/repositories.config 168 | # NuGet v3's project.json files produces more ignoreable files 169 | *.nuget.props 170 | *.nuget.targets 171 | 172 | # Microsoft Azure Build Output 173 | csx/ 174 | *.build.csdef 175 | 176 | # Microsoft Azure Emulator 177 | ecf/ 178 | rcf/ 179 | 180 | # Microsoft Azure ApplicationInsights config file 181 | ApplicationInsights.config 182 | 183 | # Windows Store app package directory 184 | AppPackages/ 185 | BundleArtifacts/ 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | [Ss]tyle[Cc]op.* 196 | ~$* 197 | *~ 198 | *.dbmdl 199 | *.dbproj.schemaview 200 | *.pfx 201 | *.publishsettings 202 | node_modules/ 203 | orleans.codegen.cs 204 | 205 | # RIA/Silverlight projects 206 | Generated_Code/ 207 | 208 | # Backup & report files from converting an old project file 209 | # to a newer Visual Studio version. Backup files are not needed, 210 | # because we have git ;-) 211 | _UpgradeReport_Files/ 212 | Backup*/ 213 | UpgradeLog*.XML 214 | UpgradeLog*.htm 215 | 216 | # SQL Server files 217 | *.mdf 218 | *.ldf 219 | 220 | # Business Intelligence projects 221 | *.rdl.data 222 | *.bim.layout 223 | *.bim_*.settings 224 | 225 | # Microsoft Fakes 226 | FakesAssemblies/ 227 | 228 | # GhostDoc plugin setting file 229 | *.GhostDoc.xml 230 | 231 | # Node.js Tools for Visual Studio 232 | .ntvs_analysis.dat 233 | 234 | # Visual Studio 6 build log 235 | *.plg 236 | 237 | # Visual Studio 6 workspace options file 238 | *.opt 239 | 240 | # Visual Studio LightSwitch build output 241 | **/*.HTMLClient/GeneratedArtifacts 242 | **/*.DesktopClient/GeneratedArtifacts 243 | **/*.DesktopClient/ModelManifest.xml 244 | **/*.Server/GeneratedArtifacts 245 | **/*.Server/ModelManifest.xml 246 | _Pvt_Extensions 247 | 248 | # LightSwitch generated files 249 | GeneratedArtifacts/ 250 | ModelManifest.xml 251 | 252 | # Paket dependency manager 253 | .paket/paket.exe 254 | 255 | # FAKE - F# Make 256 | .fake/ -------------------------------------------------------------------------------- /DaChip8JS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaChip8JS", "DaChip8JS\DaChip8JS.csproj", "{448631F1-A61C-4724-A6AF-ACF12E654E73}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {448631F1-A61C-4724-A6AF-ACF12E654E73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {448631F1-A61C-4724-A6AF-ACF12E654E73}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {448631F1-A61C-4724-A6AF-ACF12E654E73}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {448631F1-A61C-4724-A6AF-ACF12E654E73}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /DaChip8JS/Bridge/bridge.json: -------------------------------------------------------------------------------- 1 | { 2 | "output": "HTML/Scripts", 3 | "outputBy": "Project", 4 | "combineScripts": true 5 | } -------------------------------------------------------------------------------- /DaChip8JS/Chip8.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace DanTup.DaChip8JS 6 | { 7 | class Chip8 8 | { 9 | const int ScreenWidth = 64, ScreenHeight = 32; 10 | 11 | Action draw; 12 | Action beep; 13 | bool[,] buffer = new bool[ScreenWidth, ScreenHeight]; 14 | 15 | // To reduce flicker, we delay clearing pixels by a frame 16 | bool[,] pendingClearBuffer = new bool[ScreenWidth, ScreenHeight]; 17 | 18 | // Registers 19 | byte[] V = new byte[16]; 20 | // Timers 21 | byte Delay; 22 | // Address/Program Counters 23 | ushort I, PC = 0x200; 24 | // Stack 25 | byte SP; 26 | ushort[] Stack = new ushort[16]; 27 | 28 | // Memory & ROM 29 | byte[] RAM = new byte[0x1000]; 30 | 31 | // OpCodes 32 | Dictionary> opCodes; 33 | Dictionary> opCodesMisc; 34 | 35 | Random rnd = new Random(); 36 | 37 | // Keys that are currently pressed. 38 | HashSet pressedKeys = new HashSet(); 39 | 40 | public Chip8(Action draw, Action beep) 41 | { 42 | this.draw = draw; 43 | this.beep = beep; 44 | 45 | WriteFont(); 46 | 47 | opCodes = new Dictionary> 48 | { 49 | { 0x0, ClearOrReturn }, 50 | { 0x1, Jump }, 51 | { 0x2, CallSubroutine }, 52 | { 0x3, SkipIfXEqual }, 53 | { 0x4, SkipIfXNotEqual }, 54 | { 0x5, SkipIfXEqualY }, 55 | { 0x6, SetX }, 56 | { 0x7, AddX }, 57 | { 0x8, Arithmetic }, 58 | { 0x9, SkipIfXNotEqualY }, 59 | { 0xA, SetI }, 60 | { 0xB, JumpWithOffset }, 61 | { 0xC, Rnd }, 62 | { 0xD, DrawSprite }, 63 | { 0xE, SkipOnKey }, 64 | { 0xF, Misc }, 65 | }; 66 | 67 | opCodesMisc = new Dictionary> 68 | { 69 | { 0x07, SetXToDelay }, 70 | { 0x0A, WaitForKey }, 71 | { 0x15, SetDelay }, 72 | { 0x18, SetSound }, 73 | { 0x1E, AddXToI }, 74 | { 0x29, SetIForChar }, 75 | { 0x33, BinaryCodedDecimal }, 76 | { 0x55, SaveX }, 77 | { 0x65, LoadX }, 78 | }; 79 | } 80 | 81 | void WriteFont() 82 | { 83 | var offset = 0x0; 84 | WriteFont(5 * offset++, Font.D0); 85 | WriteFont(5 * offset++, Font.D1); 86 | WriteFont(5 * offset++, Font.D2); 87 | WriteFont(5 * offset++, Font.D3); 88 | WriteFont(5 * offset++, Font.D4); 89 | WriteFont(5 * offset++, Font.D5); 90 | WriteFont(5 * offset++, Font.D6); 91 | WriteFont(5 * offset++, Font.D7); 92 | WriteFont(5 * offset++, Font.D8); 93 | WriteFont(5 * offset++, Font.D9); 94 | WriteFont(5 * offset++, Font.DA); 95 | WriteFont(5 * offset++, Font.DB); 96 | WriteFont(5 * offset++, Font.DC); 97 | WriteFont(5 * offset++, Font.DD); 98 | WriteFont(5 * offset++, Font.DE); 99 | WriteFont(5 * offset++, Font.DF); 100 | } 101 | 102 | void WriteFont(int address, long fontData) 103 | { 104 | RAM[address + 0] = (byte)((fontData & 0xF000000000) >> (8 * 4)); 105 | RAM[address + 1] = (byte)((fontData & 0x00F0000000) >> (8 * 3)); 106 | RAM[address + 2] = (byte)((fontData & 0x0000F00000) >> (8 * 2)); 107 | RAM[address + 3] = (byte)((fontData & 0x000000F000) >> (8 * 1)); 108 | RAM[address + 4] = (byte)((fontData & 0x00000000F0) >> (8 * 0)); 109 | } 110 | 111 | public void LoadProgram(byte[] data) 112 | { 113 | Array.Copy(data, 0, RAM, 0x200, data.Length); 114 | } 115 | 116 | public void Tick() 117 | { 118 | // Read the two bytes of OpCode (big endian). 119 | var opCode = (ushort)(RAM[PC++] << 8 | RAM[PC++]); 120 | 121 | //Debug.WriteLine((PC - 2).ToString("X4") + ": " + opCode.ToString("X4")); 122 | 123 | // Split data into the possible formats the instruction might need. 124 | // https://en.wikipedia.org/wiki/CHIP-8#Opcode_table 125 | var op = new OpCodeData() 126 | { 127 | OpCode = opCode, 128 | NNN = (ushort)(opCode & 0x0FFF), 129 | NN = (byte)(opCode & 0x00FF), 130 | N = (byte)(opCode & 0x000F), 131 | X = (byte)((opCode & 0x0F00) >> 8), 132 | Y = (byte)((opCode & 0x00F0) >> 4), 133 | }; 134 | 135 | // Loop up the OpCode using the first nibble and execute. 136 | opCodes[(byte)(opCode >> 12)](op); 137 | } 138 | 139 | public void Tick60Hz() 140 | { 141 | //Debug.WriteLine("60Hz tick"); 142 | if (Delay > 0) 143 | Delay--; 144 | 145 | draw(buffer); 146 | } 147 | 148 | // Misc has its own dictionary because it's full of random stuff. 149 | void Misc(OpCodeData data) 150 | { 151 | if (opCodesMisc.ContainsKey(data.NN)) 152 | opCodesMisc[data.NN](data); 153 | } 154 | 155 | public void KeyDown(byte key) 156 | { 157 | pressedKeys.Add(key); 158 | } 159 | 160 | public void KeyUp(byte key) 161 | { 162 | pressedKeys.Remove(key); 163 | } 164 | 165 | // http://devernay.free.fr/hacks/chip8/C8TECH10.HTM#3.1 166 | 167 | /// 168 | /// Handles 0x0... which either clears the screen or returns from a subroutine. 169 | /// 170 | void ClearOrReturn(OpCodeData data) 171 | { 172 | if (data.NN == 0xE0) 173 | { 174 | for (var x = 0; x < ScreenWidth; x++) 175 | for (var y = 0; y < ScreenHeight; y++) 176 | buffer[x, y] = false; 177 | } 178 | else if (data.NN == 0xEE) 179 | PC = Pop(); 180 | } 181 | 182 | /// 183 | /// Jumps to location nnn (not a subroutine, so old PC is not pushed to the stack). 184 | /// 185 | void Jump(OpCodeData data) 186 | { 187 | PC = data.NNN; 188 | } 189 | 190 | /// 191 | /// Jumps to location nnn + v[0] (not a subroutine, so old PC is not pushed to the stack). 192 | /// 193 | void JumpWithOffset(OpCodeData data) 194 | { 195 | PC = (ushort)(data.NNN + V[0]); 196 | } 197 | 198 | /// 199 | /// Jumps to subroutine nnn (unlike Jump, this pushes the previous PC to the stack to allow return). 200 | /// 201 | void CallSubroutine(OpCodeData data) 202 | { 203 | Push(PC); 204 | PC = data.NNN; 205 | } 206 | 207 | /// 208 | /// Skips the next instruction (two bytes) if V[x] == nn. 209 | /// 210 | void SkipIfXEqual(OpCodeData data) 211 | { 212 | if (V[data.X] == data.NN) 213 | PC += 2; 214 | } 215 | 216 | /// 217 | /// Skips the next instruction (two bytes) if V[x] != nn. 218 | /// 219 | void SkipIfXNotEqual(OpCodeData data) 220 | { 221 | if (V[data.X] != data.NN) 222 | PC += 2; 223 | } 224 | 225 | /// 226 | /// Skips the next instruction (two bytes) if V[x] == V[y]. 227 | /// 228 | void SkipIfXEqualY(OpCodeData data) 229 | { 230 | if (V[data.X] == V[data.Y]) 231 | PC += 2; 232 | } 233 | 234 | /// 235 | /// Skips the next instruction (two bytes) if V[x] != V[y]. 236 | /// 237 | void SkipIfXNotEqualY(OpCodeData data) 238 | { 239 | if (V[data.X] != V[data.Y]) 240 | PC += 2; 241 | } 242 | 243 | /// 244 | /// Sets V[x] == nn. 245 | /// 246 | void SetX(OpCodeData data) 247 | { 248 | V[data.X] = data.NN; 249 | } 250 | 251 | /// 252 | /// Adds nn to V[x]. 253 | /// 254 | void AddX(OpCodeData data) 255 | { 256 | V[data.X] += data.NN; // TODO: Do we need to handle overflow? 257 | } 258 | 259 | /// 260 | /// Sets V[x] to V[y]. 261 | /// 262 | void Arithmetic(OpCodeData data) 263 | { 264 | switch (data.N) 265 | { 266 | case 0x0: 267 | V[data.X] = V[data.Y]; 268 | break; 269 | case 0x1: 270 | V[data.X] |= V[data.Y]; 271 | break; 272 | case 0x2: 273 | V[data.X] &= V[data.Y]; 274 | break; 275 | case 0x3: 276 | V[data.X] ^= V[data.Y]; 277 | break; 278 | case 0x4: 279 | V[0xF] = (byte)(V[data.X] + V[data.Y] > 0xFF ? 1 : 0); // Set flag if we overflowed. 280 | V[data.X] += V[data.Y]; 281 | break; 282 | case 0x5: 283 | V[0xF] = (byte)(V[data.X] > V[data.Y] ? 1 : 0); // Set flag if we underflowed. 284 | V[data.X] -= V[data.Y]; 285 | break; 286 | case 0x6: 287 | V[0xF] = (byte)((V[data.X] & 0x1) != 0 ? 1 : 0); // Set flag if we shifted a 1 off the end. 288 | V[data.X] /= 2; // Shift right. 289 | break; 290 | case 0x7: // Note: This is Y-X, 5 was X-Y. 291 | V[0xF] = (byte)(V[data.Y] > V[data.X] ? 1 : 0); // Set flag if we underflowed. 292 | V[data.Y] -= V[data.X]; 293 | break; 294 | case 0xE: 295 | V[0xF] = (byte)((V[data.X] & 0xF) != 0 ? 1 : 0); // Set flag if we shifted a 1 off the end. 296 | V[data.X] *= 2; // Shift left. 297 | break; 298 | } 299 | } 300 | 301 | /// 302 | /// Sets the I register. 303 | /// 304 | void SetI(OpCodeData data) 305 | { 306 | I = data.NNN; 307 | } 308 | 309 | /// 310 | /// ANDs a random number with nn and stores in V[x]. 311 | /// 312 | void Rnd(OpCodeData data) 313 | { 314 | V[data.X] = (byte)(rnd.Next(0, 256) & data.NN); 315 | } 316 | 317 | /// 318 | /// Draws an n-byte sprite from register I at V[x], V[y]. Sets V[0xF] if it collides. 319 | /// 320 | void DrawSprite(OpCodeData data) 321 | { 322 | var startX = V[data.X]; 323 | var startY = V[data.Y]; 324 | //Debug.WriteLine(string.Format("Drawing {0}-line sprite from {1} at {2}, {3}", data.N, I, startX, startY)); 325 | 326 | // Write any pending clears 327 | for (var x = 0; x < ScreenWidth; x++) 328 | { 329 | for (var y = 0; y < ScreenHeight; y++) 330 | { 331 | if (pendingClearBuffer[x, y]) 332 | { 333 | pendingClearBuffer[x, y] = false; 334 | buffer[x, y] = false; 335 | } 336 | } 337 | } 338 | 339 | V[0xF] = 0; 340 | for (var i = 0; i < data.N; i++) 341 | { 342 | var spriteLine = RAM[I + i]; // A line of the sprite to render 343 | 344 | for (var bit = 0; bit < 8; bit++) 345 | { 346 | var x = (startX + bit) % ScreenWidth; 347 | var y = (startY + i) % ScreenHeight; 348 | 349 | var spriteBit = ((spriteLine >> (7 - bit)) & 1); 350 | var oldBit = buffer[x, y] ? 1 : 0; 351 | 352 | // New bit is XOR of existing and new. 353 | var newBit = oldBit ^ spriteBit; 354 | 355 | if (newBit != 0) 356 | buffer[x, y] = true; 357 | else // Otherwise write a pending clear 358 | pendingClearBuffer[x, y] = true; 359 | 360 | // If we wiped out a pixel, set flag for collission. 361 | if (oldBit != 0 && newBit == 0) 362 | V[0xF] = 1; 363 | } 364 | } 365 | } 366 | 367 | /// 368 | /// Skips the next instruction based on the key at V[x] being pressed/not pressed. 369 | /// 370 | void SkipOnKey(OpCodeData data) 371 | { 372 | if ( 373 | (data.NN == 0x9E && pressedKeys.Contains(V[data.X])) // 9E = IfKeyPressed 374 | || (data.NN == 0xA1 && !pressedKeys.Contains(V[data.X])) // A1 = IfKeyNotPressed 375 | ) 376 | PC += 2; 377 | } 378 | 379 | /// 380 | /// Waits for a key to be pressed by looping at the current instruction. 381 | /// 382 | void WaitForKey(OpCodeData data) 383 | { 384 | // If we have a key pressed, store it and more on. 385 | if (pressedKeys.Count != 0) 386 | V[data.X] = pressedKeys.First(); 387 | else 388 | // Otherwise, wind the PC back so we will keep executing this instruction. 389 | PC -= 2; 390 | } 391 | 392 | /// 393 | /// Sets V[x] to equal the Delay register. 394 | /// 395 | void SetXToDelay(OpCodeData data) 396 | { 397 | V[data.X] = Delay; 398 | } 399 | 400 | /// 401 | /// Sets the delay register to V[x]. 402 | /// 403 | void SetDelay(OpCodeData data) 404 | { 405 | Delay = V[data.X]; 406 | } 407 | 408 | /// 409 | /// Play sound for V[x] 60ths of a second. 410 | /// 411 | void SetSound(OpCodeData data) 412 | { 413 | beep((int)(V[data.X] * (1000f / 60))); 414 | } 415 | 416 | /// 417 | /// Adds V[x] to register I. 418 | /// 419 | void AddXToI(OpCodeData data) 420 | { 421 | I += V[data.X]; 422 | } 423 | 424 | /// 425 | /// Sets I to the correct location of the font sprite V[x]. 426 | /// Each font sprite is 5 bytes long. 427 | /// 428 | void SetIForChar(OpCodeData data) 429 | { 430 | //Debug.WriteLine(string.Format("Setting I to {0} to render a {1}", V[data.X] * 5, V[data.X].ToString("X"))); 431 | I = (ushort)(V[data.X] * 5); // 0 is at 0x0, 1 is at 0x5, ... 432 | } 433 | 434 | /// 435 | /// Takes the decimal representation of V[x] and puts each character into memory locations 436 | /// starting at I (with a maximum of 3). 437 | /// 438 | void BinaryCodedDecimal(OpCodeData data) 439 | { 440 | RAM[I + 0] = (byte)((V[data.X] / 100) % 10); 441 | RAM[I + 1] = (byte)((V[data.X] / 10) % 10); 442 | RAM[I + 2] = (byte)(V[data.X] % 10); 443 | } 444 | 445 | /// 446 | /// Saves all registers to the address in register I. 447 | /// 448 | void SaveX(OpCodeData data) 449 | { 450 | for (var i = 0; i <= data.X; i++) 451 | RAM[I + i] = V[i]; 452 | } 453 | 454 | /// 455 | /// Loads all registers from the address in register I. 456 | /// 457 | void LoadX(OpCodeData data) 458 | { 459 | for (var i = 0; i <= data.X; i++) 460 | V[i] = RAM[I + i]; 461 | } 462 | 463 | /// 464 | /// Pushes a 16-bit value onto the stack, incrementing the SP. 465 | /// 466 | void Push(ushort value) 467 | { 468 | Stack[SP++] = value; 469 | } 470 | 471 | /// 472 | /// Retrieves a 16-bit value from the stack, decrementing the SP. 473 | /// 474 | ushort Pop() 475 | { 476 | return Stack[--SP]; 477 | } 478 | } 479 | } 480 | -------------------------------------------------------------------------------- /DaChip8JS/DaChip8JS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {448631F1-A61C-4724-A6AF-ACF12E654E73} 8 | Library 9 | Properties 10 | DanTup.DaChip8JS 11 | DaChip8JS 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | true 28 | 5 29 | 30 | 31 | AnyCPU 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | true 39 | 40 | 41 | 42 | 43 | 44 | 45 | ..\packages\Bridge.Core.1.14.0\lib\net40\Bridge.dll 46 | True 47 | 48 | 49 | ..\packages\Bridge.Collections.1.3.1\lib\net40\Bridge.Collections.dll 50 | True 51 | 52 | 53 | ..\packages\Bridge.Html5.1.14.0\lib\net40\Bridge.Html5.dll 54 | True 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 81 | 82 | 83 | 84 | 91 | -------------------------------------------------------------------------------- /DaChip8JS/Font.cs: -------------------------------------------------------------------------------- 1 | namespace DanTup.DaChip8JS 2 | { 3 | static class Font 4 | { 5 | // Fonts are 4x5. Each line must be a byte wide so is padded with 0x00. 6 | // Eg: 7 | // 0: 8 | // #### = 1111 = F0 9 | // # # = 1001 = 90 10 | // # # = 1001 = 90 11 | // # # = 1001 = 90 12 | // #### = 1111 = F0 13 | 14 | public const long D0 = 0xF0909090F0; 15 | public const long D1 = 0x2060202070; 16 | public const long D2 = 0xF010F080F0; 17 | public const long D3 = 0xF010F010F0; 18 | public const long D4 = 0x9090F01010; 19 | public const long D5 = 0xF080F010F0; 20 | public const long D6 = 0xF080F090F0; 21 | public const long D7 = 0xF010204040; 22 | public const long D8 = 0xF090F090F0; 23 | public const long D9 = 0xF090F010F0; 24 | public const long DA = 0xF090F09090; 25 | public const long DB = 0xE090E090E0; 26 | public const long DC = 0xF0808080F0; 27 | public const long DD = 0xE0909090E0; 28 | public const long DE = 0xF080F080F0; 29 | public const long DF = 0xF080F08080; 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DaChip8JS/HTML/Index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | DaChip8JS 5 | 6 | 13 | 14 | 15 | 16 | Fork me on GitHub 17 | 18 |

DaChip8JS

19 | 20 |

DaChip8JS is my C# CHIP-8 interpreter converted to run in the browser using Bridge.NET.

21 | 22 |

Breakout (Brix hack) [David Winter, 1997]

23 | 24 |

The ROM loaded below is Breakout (Brix hack) [David Winter, 1997] from the Chip-8 Pack.

25 | 26 |

You can use the cursor keys to move the paddle on a desktop or tap on the left/right half of the gamescreen on a mobile device.

27 | 28 |
29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /DaChip8JS/KeyCode.cs: -------------------------------------------------------------------------------- 1 | namespace DanTup.DaChip8JS 2 | { 3 | enum KeyCode 4 | { 5 | D1 = 49, 6 | D2 = 50, 7 | D3 = 51, 8 | D4 = 52, 9 | Q = 81, 10 | W = 87, 11 | E = 69, 12 | R = 82, 13 | A = 65, 14 | S = 83, 15 | D = 68, 16 | F = 70, 17 | Z = 90, 18 | X = 88, 19 | C = 67, 20 | V = 86, 21 | LeftCursor = 37, 22 | RightCursor = 39, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DaChip8JS/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Bridge.Html5; 4 | 5 | namespace DanTup.DaChip8JS 6 | { 7 | public static class Main 8 | { 9 | static Chip8 chip8; 10 | const string ROM = "/ROMs/Chip-8 Pack/Chip-8 Games/Breakout (Brix hack) [David Winter, 1997].ch8"; 11 | 12 | static readonly int minimumSetIntervalResolution = 4; // HTML5 has minimum resolution of 4ms http://developer.mozilla.org/en/DOM/window.setTimeout#Minimum_delay_and_timeout_nesting 13 | static readonly int targetElapsedTime60Hz = (int)(1000f / 60); // 60 tickets per second 14 | static readonly int targetElapsedTime = (int)(1000f / 500); // 500 ticks per second 15 | 16 | // Debug stuff. 17 | static int cycles = 0; 18 | static int gameStartTime = 0; 19 | static HTMLDivElement debug; 20 | 21 | static HTMLCanvasElement screen; 22 | static CanvasRenderingContext2D screenContext; 23 | static ImageData lightPixel; 24 | 25 | // Beep (we cheat with this and just play once, regardless of duration). 26 | static HTMLAudioElement beep; 27 | 28 | [Ready] 29 | public static void OnReady() 30 | { 31 | // If we're hosted in a page with a start button, hook it up. Otherwise, start. 32 | var startButton = Document.GetElementById("start-dachip8js-game"); 33 | if (startButton != null) 34 | startButton.OnClick = delegate (MouseEvent e) { startButton.Style.Display = Display.None; StartGame(); beep.Play(); }; 35 | else 36 | StartGame(); 37 | } 38 | 39 | public static void StartGame() 40 | { 41 | debug = Document.GetElementById("debug"); 42 | 43 | // Set up canvas rendering. 44 | screen = Document.GetElementById("screen"); 45 | screenContext = screen.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D); 46 | lightPixel = screenContext.CreateImageData(1, 1); 47 | lightPixel.Data[1] = 0x64; // Set green part (#006400) 48 | lightPixel.Data[3] = 255; // Alpha 49 | 50 | // Set up touch events for canvas so we can play on mobile. 51 | screen.OnTouchStart += SetTouchDown; 52 | screen.OnTouchEnd += SetTouchUp; 53 | 54 | // Set up audio. 55 | // http://stackoverflow.com/a/23395136/25124 56 | beep = new HTMLAudioElement("data:audio/wav;base64,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qJrx4KOQjahZxWbcZgztj2c49nKmkId44S71j0c8eV9yDK6uPRzx5X18eDvjvQ6yKo9ZSS6l//8elePK/Lf//IInrOF/FvDoADYAGBMGb7FtErm5MXMlmPAJQVgWta7Zx2go+8xJ0UiCb8LHHdftWyLJE0QIAIsI+UbXu67dZMjmgDGCGl1H+vpF4NSDckSIkk7Vd+sxEhBQMRU8j/12UIRhzSaUdQ+rQU5kGeFxm+hb1oh6pWWmv3uvmReDl0UnvtapVaIzo1jZbf/pD6ElLqSX+rUmOQNpJFa/r+sa4e/pBlAABoAAAAA3CUgShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU="); 57 | 58 | // Create the interpreter. 59 | chip8 = new Chip8(Draw, Beep); 60 | 61 | // Pass keypresses over to the interpreter. 62 | Document.OnKeyDown += SetKeyDown; 63 | Document.OnKeyUp += SetKeyUp; 64 | 65 | // Kick off async loading of ROM. 66 | BeginLoadRom(ROM); 67 | } 68 | 69 | static void BeginLoadRom(string rom) 70 | { 71 | var req = new XMLHttpRequest(); 72 | req.ResponseType = XMLHttpRequestResponseType.ArrayBuffer; 73 | req.Open("GET", rom); 74 | req.OnLoad = e => EndLoadRom(GetResponseAsByteArray(req)); 75 | req.Send(); 76 | } 77 | 78 | static byte[] GetResponseAsByteArray(XMLHttpRequest req) 79 | { 80 | return new Uint8Array(req.Response as ArrayBuffer).As(); 81 | } 82 | 83 | static void EndLoadRom(byte[] data) 84 | { 85 | chip8.LoadProgram(data); 86 | 87 | StartGameLoop(); 88 | } 89 | 90 | static void Draw(bool[,] buffer) 91 | { 92 | var width = buffer.GetLength(0); 93 | var height = buffer.GetLength(1); 94 | // For performance, we only draw lit pixels so we need to clear the screen first. 95 | screenContext.ClearRect(0, 0, width, height); 96 | for (var x = 0; x < width; x++) 97 | for (var y = 0; y < height; y++) 98 | if (buffer[x, y]) 99 | screenContext.PutImageData(lightPixel, x, y); 100 | } 101 | 102 | static void Beep(int milliseconds) 103 | { 104 | beep.Play(); 105 | } 106 | 107 | static Dictionary keyMapping = new Dictionary 108 | { 109 | { KeyCode.D1, 0x1 }, 110 | { KeyCode.D2, 0x2 }, 111 | { KeyCode.D3, 0x3 }, 112 | { KeyCode.D4, 0xC }, 113 | { KeyCode.Q, 0x4 }, 114 | { KeyCode.W, 0x5 }, 115 | { KeyCode.E, 0x6 }, 116 | { KeyCode.R, 0xD }, 117 | { KeyCode.A, 0x7 }, 118 | { KeyCode.S, 0x8 }, 119 | { KeyCode.D, 0x9 }, 120 | { KeyCode.F, 0xE }, 121 | { KeyCode.Z, 0xA }, 122 | { KeyCode.X, 0x0 }, 123 | { KeyCode.C, 0xB }, 124 | { KeyCode.V, 0xF }, 125 | { KeyCode.LeftCursor, 0x4 }, 126 | { KeyCode.RightCursor, 0x6 }, 127 | }; 128 | 129 | static void SetKeyDown(KeyboardEvent e) 130 | { 131 | if (keyMapping.ContainsKey((KeyCode)e.KeyCode)) 132 | chip8.KeyDown(keyMapping[(KeyCode)e.KeyCode]); 133 | } 134 | 135 | static void SetKeyUp(KeyboardEvent e) 136 | { 137 | if (keyMapping.ContainsKey((KeyCode)e.KeyCode)) 138 | chip8.KeyUp(keyMapping[(KeyCode)e.KeyCode]); 139 | } 140 | 141 | static void SetTouchDown(TouchEvent e) 142 | { 143 | if (e.Touches[0].ClientX < screen.ClientWidth / 2) 144 | chip8.KeyDown(keyMapping[KeyCode.LeftCursor]); 145 | else 146 | chip8.KeyDown(keyMapping[KeyCode.RightCursor]); 147 | e.PreventDefault(); 148 | } 149 | 150 | static void SetTouchUp(TouchEvent e) 151 | { 152 | chip8.KeyUp(keyMapping[KeyCode.LeftCursor]); 153 | chip8.KeyUp(keyMapping[KeyCode.RightCursor]); 154 | e.PreventDefault(); 155 | } 156 | 157 | static void StartGameLoop() 158 | { 159 | Window.SetInterval(Tick, minimumSetIntervalResolution); 160 | Window.SetInterval(chip8.Tick60Hz, targetElapsedTime60Hz); 161 | } 162 | 163 | static void Tick() 164 | { 165 | var numTicksToExecute = minimumSetIntervalResolution / targetElapsedTime; 166 | for (var i = 0; i < numTicksToExecute; i++) 167 | { 168 | cycles++; 169 | debug.TextContent = string.Format("Target cycle time {0}ms, average {1}ms", targetElapsedTime, (Window.Performance.Now() - gameStartTime) / cycles); 170 | chip8.Tick(); 171 | } 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /DaChip8JS/OpCodeData.cs: -------------------------------------------------------------------------------- 1 | namespace DanTup.DaChip8JS 2 | { 3 | struct OpCodeData 4 | { 5 | public ushort OpCode; 6 | public ushort NNN; 7 | public byte NN, X, Y, N; 8 | } 9 | } -------------------------------------------------------------------------------- /DaChip8JS/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Danny Tuppeny 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DaChip8JS [![Build status](https://ci.appveyor.com/api/projects/status/github/DanTup/DaChip8JS?svg=true)](https://ci.appveyor.com/project/DanTup/dachip8js) 2 | 3 | DaChip8JS is my [C# CHIP-8 interpreter](https://github.com/DanTup/DaChip8) running in the browser using Bridge.NET. 4 | 5 | > **[Read the blog post (which includes an embedded live playable demo!) here](http://blog.dantup.com/2016/06/dachip8js-my-csharp-chip8-interpreter-running-in-the-browser/)**. 6 | 7 | ## ROMs 8 | 9 | For testing, I am using the Chip-8 Pack downloaded from [chip8.com](http://www.chip8.com/?page=109). These ROMs are not committed to the repo, so you will need to download and extract them into `HTML/ROMs/Chip-8 Pack` to run. 10 | 11 | ## Demo 12 | 13 | Here's a short video showing `Breakout (Brix hack) [David Winter, 1997].ch8` from the Chip-8 pack. I believe the flickering is part of the game, and not my fault! This works basically the same as the C# version (albeit consuming far more resources currently). 14 | 15 | [![DaChip8JS - DanTup's JS Chip-8 Interpreter](http://img.youtube.com/vi/tDgoDhCumPg/0.jpg)](http://www.youtube.com/watch?v=tDgoDhCumPg "DaChip8JS - DanTup's JS Chip-8 Interpreter") 16 | --------------------------------------------------------------------------------