Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ii:assignments:s2:chip8 [2023/03/06 14:13]
radu.mantu [Code Skeleton]
ii:assignments:s2:chip8 [2023/04/26 11:37] (current)
florin.stancu
Line 1: Line 1:
 ~~NOTOC~~ ~~NOTOC~~
  
-====== CHIP-8 ​emulator ​======+====== CHIP-8 ​Emulator (bonus) ​======
  
 ===== Context ===== ===== Context =====
Line 24: Line 24:
     * **display.c**:​ This is the implementation of the GUI. You don't have to make any changes to it. Just use the functions in your instruction decodes (e.g.: ''​clear_screen()''​ for the ''​00E0''​ instruction).     * **display.c**:​ This is the implementation of the GUI. You don't have to make any changes to it. Just use the functions in your instruction decodes (e.g.: ''​clear_screen()''​ for the ''​00E0''​ instruction).
     * **main.c**: A sample program that renders a random hex digit to the screen; replace this with your implementation.     * **main.c**: A sample program that renders a random hex digit to the screen; replace this with your implementation.
-  * **makefile**:​ It has the usual ''​build''​ and ''​clean''​ targets. Unless you want to write the interpreter in C++, you probably won't have to change anything. If you need other external libraries, add the required flags to the ''​LDFLAGS''​ variable (e.g.: ''​-lm''​ for basic math library).+  * **makefile**:​ It has the usual ''​build''​ and ''​clean''​ targets. Unless you want to write the interpreter in C++, you probably won't have to change anything. If you need other external libraries, add the required flags to the ''​LDFLAGS''​ variable (e.g.: ''​-lm''​ for basic math library). Any new sources that you add to **src/** will be automatically detected and compiled into the final binary.
  
 ===== Resources ===== ===== Resources =====
Line 60: Line 60:
 ==== Keyboard ==== ==== Keyboard ====
  
-The computers that originally used CHIP-8 had a 4x4 keypad, as shown in the figure below. You can map these keys to your keyboard anyway you want. Note that SDL2 also implements support for keyboard input detection. Check out [[https://​wiki.libsdl.org/​SDL2/​SDL_GetKeyboardState|SDL_GetKeyboardState()]],​ or the event driven API (TODO).+The computers that originally used CHIP-8 had a 4x4 keypad, as shown in the figure below. You can map these keys to your keyboard anyway you want. Note that SDL2 also implements support for keyboard input detection. Check out [[https://​wiki.libsdl.org/​SDL2/​SDL_GetKeyboardState|SDL_GetKeyboardState()]],​ or the [[https://​wiki.libsdl.org/​SDL2/​CategoryEvents|event driven API]].
  
 {{ :​ii:​assignments:​s2:​chip-8_keypad.png?​500 |}} {{ :​ii:​assignments:​s2:​chip-8_keypad.png?​500 |}}
Line 99: Line 99:
     * ''​00E0'':​ clear screen     * ''​00E0'':​ clear screen
     * ''​1NNN'':​ jump to address ''​NNN''​     * ''​1NNN'':​ jump to address ''​NNN''​
-    * ''​6XNN'':​ set the value of the ''​V[X]''​ register to ''​NN''​+    * ''​6XNN'':​ set the value of the ''​Vx''​ register to ''​NN''​ 
 +    * ''​7XNN'':​ add ''​NN''​ to register ''​Vx''​
     * ''​ANNN'':​ set the value of the ''​I''​ register to ''​NNN''​     * ''​ANNN'':​ set the value of the ''​I''​ register to ''​NNN''​
-    * ''​DXYN'':​ display a ''​N''​-byte sprite at location ''​V[X]'',​ ''​V[Y]''​+    * ''​DXYN'':​ display a ''​N''​-byte sprite at location ''​Vx'',​ ''​Vy''​
   * [[https://​github.com/​corax89/​chip8-test-rom|chip8-test-rom 1]]: Tests the 18 instructions described in the README.   * [[https://​github.com/​corax89/​chip8-test-rom|chip8-test-rom 1]]: Tests the 18 instructions described in the README.
   * [[https://​github.com/​metteo/​chip8-test-rom|chip8-test-rom 2]]: More tests.   * [[https://​github.com/​metteo/​chip8-test-rom|chip8-test-rom 2]]: More tests.
Line 111: Line 112:
 **Q: Can I write the emulator in something other than C/C++?** \\ **Q: Can I write the emulator in something other than C/C++?** \\
 A: No. A: No.
 +
 +**Q: What platform will this assignment be tested on?** \\
 +A: Linux only.
 +
 +**Q: How do I read the instruction codes in the specification?​** \\
 +A: In the spec, the instructions are represented as 4 characters, each signifying a nibble (4 bits). Hex digits (''​0-9A-F''​) are invariants and you should try to match them exactly. E.g. ''​00EE''​ (''​RET''​) is composed of 4 constant nibbles. Whenever you see ''​X''​ or ''​Y'',​ that part of the opcode is variable and it represents what general purpose register (''​V''​) is involved in that operation. E.g. ''​FX65''​ (''​LD Vx, [I]''​) will load in register ''​Vx''​ the value located at the memory address stored in register ''​I'';​ basically, it's dereferencing a pointer. Finally, whenever you see a sequence of ''​K''​ or ''​N''​ characters (notation can differ), know that these are //immediate values//. These are basically arguments for the instructions that are embedded in the opcode itself. E.g. ''​6XKK''​ (''​LD Vx, byte''​) will load the value ''​KK''​ into ''​Vx''​. So for ''​614F'',​ we will have ''​V1 = 0x4F''​.
 +
 +**Q: There are so many CHIP-8 emulators out there. What if I'm tempted to "take inspiration"​ from some of them?** \\
 +A: Once you come up with a solution of your own //and implement it//, it's ok to look at other approaches. After all, to write good code you first need to read good code. However, taking inspiration and "​taking inspiration"​ are two different things. In addition to a manual review, we'll also perform an AST comparison of your submitted code, against each other and as many public CHIP-8 projects as we can find. Just keep that in mind :p
  
 <​note>​ <​note>​
 **TODO:** Collect questions from Teams / lab and add them here. **TODO:** Collect questions from Teams / lab and add them here.
 </​note>​ </​note>​
ii/assignments/s2/chip8.1678104784.txt.gz · Last modified: 2023/03/06 14:13 by radu.mantu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0