So I've been working on a Chip-8 emulator as a final project for my CompSci class, and have encountered an issue that seems to extend beyond my code. A large amount of the demos I've downloaded (and I'm sure they're genuine Chip-8 programs, not SuperChip or anything like that) contain machine instructions that don't fit the format of any Chip-8 opcode.
http://mattmik.com/files/chip8/mastering/chip8.html
At the bottom of the page is a list of all the opcodes, each 2 bytes long, and what each nibble of data in them represents. However, a fair number of the programs have instructions that don't meet any the format for any instruction. For example, here's a hex dump from one of them - I'll point out a few individual cases within it
0000000 6a 00 6b 04 6c 01 6d 00 6e 02 23 26 23 20 60 30
0000010 61 01 f0 15 f0 07 f1 18 30 00 12 14 22 42 23 20
0000020 7d 01 23 20 60 08 e0 a1 23 0a 4a 00 12 3e a3 62
0000030 d8 91 79 01 d8 91 4f 01 12 f4 49 18 12 e4 22 b2
0000040 12 1e 4c 01 22 6c 4c 02 22 7a 4c 03 22 88 4c 04
0000050 22 96 4c 05 22 a4 a3 59 d6 72 44 00 00 ee a3 57
0000060 d4 52 42 00 00 ee a3 5b d2 32 00 ee 66 28 67 09
0000070 64 00 65 00 62 00 63 00 00 ee 66 28 67 0e 64 28
0000080 65 14 62 00 63 00 00 ee 66 28 67 07 64 28 65 0c
0000090 62 16 63 11 00 ee 66 28 67 07 64 28 65 0e 62 16
00000a0 63 14 00 ee 66 28 67 05 64 28 65 10 62 16 63 0b
00000b0 00 ee a3 59 d6 72 76 fe d6 72 44 00 00 ee a3 57
00000c0 d4 52 74 02 44 44 74 c0 d4 52 42 00 00 ee a3 5b
00000d0 d2 32 72 02 4c 04 72 02 4c 05 72 02 42 44 72 c0
00000e0 d2 32 00 ee 7c 01 6d 00 6e 02 00 e0 4c 06 6c 01
00000f0 6a 00 12 0a 60 06 f0 18 7b ff 4b 00 13 08 6d 00
0000100 6e 02 00 e0 6a 00 12 0a 13 08 4a 01 00 ee 60 02
0000110 f0 18 6a 01 88 d0 78 01 89 e0 79 01 d8 91 00 ee
0000120 a3 54 dd e2 00 ee 64 19 63 00 a3 56 d3 41 73 08
0000130 33 40 13 2c 63 1e 64 1b fc 29 d3 45 4b 04 a3 5f
0000140 4b 03 a3 60 4b 02 a3 61 4b 01 a3 62 63 01 74 02
0000150 d3 41 00 ee 80 f8 ff 80 e0 10 70 88 ee 11 77 aa
0000160 a8 a0 80 00
0000164
At 0x154, there's
80 f8
but no instruction begining with 8 can end with an 8 - the only legal instructions ending with an 8 must end with 1,2,3,4,5,6,7, or e. Another one, at 0x158,
e0 10
no instruction matches this format either. the second byte of any instruction starting with e has to be 9E or A1.
This is only a small number of the errors - there's several more of these 'impossible' instructions throughout the code
Am I doing something drastically wrong? How should I deal with these instructions? Just skip over them? Is the page I'm using as my Chip-8 resource somehow incomplete? Any advice on how to deal with this is greatly appreciated. Thanks!
Bear in mind that I'm totally unfamiliar with chip-8 specifically; just low-level computing in general.
That's very probably data; the graphics and sound that make up the game. You don't have to "deal with it"; if the program is written correctly the instruction pointer will never point to that area.
If it DOES end up pointing there, that's an error just like dividing by zero; "deal with it" however you want, presumably by showing the user a message saying "you tried to execute an invalid instruction you numpty."
That's what programmers mean when they say "undefined behavior;" there literally is no definition for what is supposed to happen when the instruction pointer points to something that isn't an instruction. You may do whatever you want, because a correctly made program is never supposed to do it (in real life they do anyway, all the time in fact, but they really shouldn't.)