This shows you the differences between two versions of the page.
ii:assignments:s2:chip8 [2023/03/06 13:56] radu.mantu [Grading] |
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 22: | Line 22: | ||
* **src/**: Here you will add any new source files that you will write. Try keeping things modular: different files for the instruction decoders, sound system, etc. | * **src/**: Here you will add any new source files that you will write. Try keeping things modular: different files for the instruction decoders, sound system, etc. | ||
* **cli_args.c**: Here you will find an [[https://www.gnu.org/software/libc/manual/html_node/Argp.html|argp]]-based CLI argument parser. Add new arguments to this file. The structure that is exported to the ''main()'' function is defined in **cli_args.h**. | * **cli_args.c**: Here you will find an [[https://www.gnu.org/software/libc/manual/html_node/Argp.html|argp]]-based CLI argument parser. Add new arguments to this file. The structure that is exported to the ''main()'' function is defined in **cli_args.h**. | ||
- | * **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; more on the ISA down below). | + | * **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 73: | Line 73: | ||
* **[5p] CLI arguments:** Add CPU frequency as an CLI argument with //argp//. | * **[5p] CLI arguments:** Add CPU frequency as an CLI argument with //argp//. | ||
* **[5p] Registers & RAM:** Correctly define / instantiate the system registers & guest RAM memory. Load the ROM contents at the correct offset in the guest RAM. | * **[5p] Registers & RAM:** Correctly define / instantiate the system registers & guest RAM memory. Load the ROM contents at the correct offset in the guest RAM. | ||
- | * **[10p] IBM logo:** Implementing the required instructions, you are able to run the IBM logo. | + | * **[10p] IBM logo:** Implementing the required instructions, you are able to run the IBM logo (see the //Test ROMs// section below). |
* **[15p] CPU frequency:** The emulated CPU runs exactly at the specified frequency. | * **[15p] CPU frequency:** The emulated CPU runs exactly at the specified frequency. | ||
* **[15p] Keyboard input:** Able to process keyboard input, detecting key down / up events. | * **[15p] Keyboard input:** Able to process keyboard input, detecting key down / up events. | ||
Line 85: | Line 85: | ||
<note> | <note> | ||
- | Write a README containing the description of your implementation, design choices, challenges you encountered, etc. All submissions that do not include a README will be ignored. | + | Write a README containing the description of your implementation, design choices, challenges you encountered, etc. Feel free to add your feedback here as well. All submissions that do not include a README will be ignored. |
+ | |||
+ | ---- | ||
+ | |||
+ | **NOTE:** Assistants are free do deduct points for bad / illegible code. | ||
</note> | </note> | ||
Line 95: | 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 105: | Line 110: | ||
===== FAQ ===== | ===== FAQ ===== | ||
- | <note important>TODO</note> | + | **Q: Can I write the emulator in something other than C/C++?** \\ |
+ | 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> | ||
+ | **TODO:** Collect questions from Teams / lab and add them here. | ||
+ | </note> |