tinychip/models/instructions.rs
1/// Chip8 instructions (35)
2///
3/// Descriptions sources : http://devernay.free.fr/hacks/chip8/C8TECH10.HTM#00EE
4pub trait Instructions {
5 /// 0nnn - SYS addr
6 ///
7 /// Jump to a machine code routine at nnn.
8 ///
9 /// This instruction is only used on the old computers on which Chip-8 was originally implemented. It is ignored by modern interpreters.
10 fn sys(&mut self);
11 /// 00E0 - CLS
12 ///
13 /// Clear the screen
14 fn cls(&mut self);
15 /// 00EE - RET
16 ///
17 /// Return from a subroutine.
18 ///
19 /// The interpreter sets the program counter to the address at the top of the stack, then subtracts 1 from the stack pointer.
20 fn ret(&mut self);
21 /// 1nnn - JP addr
22 ///
23 /// Jump to location nnn.
24 ///
25 /// The interpreter sets the program counter to nnn.
26 fn jp(&mut self);
27 /// 2nnn - CALL addr
28 ///
29 /// Call subroutine at nnn.
30 ///
31 ///The interpreter increments the stack pointer, then puts the current PC on the top of the stack. The PC is then set to nnn.
32 fn call(&mut self);
33 /// 3xkk - SE Vx, byte
34 ///
35 /// Skip next instruction if Vx = kk.
36 ///
37 /// The interpreter compares register Vx to kk, and if they are equal, increments the program counter by 2.
38 fn se_vx_byte(&mut self);
39 /// 4xkk - SNE Vx, byte
40 ///
41 /// Skip next instruction if Vx != kk.
42 ///
43 /// The interpreter compares register Vx to kk, and if they are not equal, increments the program counter by 2.
44 fn sne_vx_byte(&mut self);
45 /// 5xy0 - SE Vx, Vy
46 ///
47 /// Skip next instruction if Vx = Vy.
48 ///
49 /// The interpreter compares register Vx to register Vy, and if they are equal, increments the program counter by 2.
50 fn se_vx_vy(&mut self);
51 /// 6xkk - LD Vx, byte
52 ///
53 /// Set Vx = kk.
54 ///
55 /// The interpreter puts the value kk into register Vx.
56 fn ld_vx_byte(&mut self);
57 /// 7xkk - ADD Vx, byte
58 ///
59 /// Set Vx = Vx + kk.
60 ///
61 /// Adds the value kk to the value of register Vx, then stores the result in Vx.
62 fn add_vx_byte(&mut self);
63 /// 8xy0 - LD Vx, Vy
64 ///
65 /// Set Vx = Vy.
66 ///
67 /// Stores the value of register Vy in register Vx.
68 fn ld_vx_vy(&mut self);
69 /// 8xy1 - OR Vx, Vy
70 ///
71 /// Set Vx = Vx OR Vy.
72 ///
73 /// Performs a bitwise OR on the values of Vx and Vy, then stores the result in Vx. A bitwise OR compares the corrseponding bits from two values, and if either bit is 1, then the same bit in the result is also 1. Otherwise, it is 0.
74 fn or_vx_vy(&mut self);
75 /// 8xy2 - AND Vx, Vy
76 ///
77 /// Set Vx = Vx AND Vy.
78 ///
79 /// Performs a bitwise AND on the values of Vx and Vy, then stores the result in Vx. A bitwise AND compares the corrseponding bits from two values, and if both bits are 1, then the same bit in the result is also 1. Otherwise, it is 0.
80 fn and_vx_vy(&mut self);
81 /// 8xy3 - XOR Vx, Vy
82 ///
83 /// Set Vx = Vx XOR Vy.
84 ///
85 /// Performs a bitwise exclusive OR on the values of Vx and Vy, then stores the result in Vx. An exclusive OR compares the corrseponding bits from two values, and if the bits are not both the same, then the corresponding bit in the result is set to 1. Otherwise, it is 0.
86 fn xor_vx_vy(&mut self);
87 /// 8xy4 - ADD Vx, Vy
88 ///
89 /// Set Vx = Vx + Vy, set VF = carry.
90 ///
91 /// The values of Vx and Vy are added together. If the result is greater than 8 bits (i.e., > 255,) VF is set to 1, otherwise 0. Only the lowest 8 bits of the result are kept, and stored in Vx.
92 fn add_vx_vy(&mut self);
93 /// 8xy5 - SUB Vx, Vy
94 ///
95 /// Set Vx = Vx - Vy, set VF = NOT borrow.
96 ///
97 /// If Vx > Vy, then VF is set to 1, otherwise 0. Then Vy is subtracted from Vx, and the results stored in Vx.
98 fn sub_vx_vy(&mut self);
99 /// 8xy6 - SHR Vx {, Vy}
100 ///
101 /// Set Vx = Vx SHR 1.
102 ///
103 /// If the least-significant bit of Vx is 1, then VF is set to 1, otherwise 0. Then Vx is divided by 2.
104 fn shr_vx_vy(&mut self);
105 /// 8xy6 - SHR Vx {, Vy}
106 ///
107 /// Set Vx = Vy SHR 1.
108 ///
109 /// If the least-significant bit of Vx is 1, then VF is set to 1, otherwise 0. Then yx is divided by 2.
110 fn shr_vx_vy_original(&mut self);
111 /// 8xy7 - SUBN Vx, Vy
112 ///
113 /// Set Vx = Vy - Vx, set VF = NOT borrow.
114 ///
115 /// If Vy > Vx, then VF is set to 1, otherwise 0. Then Vx is subtracted from Vy, and the results stored in Vx.
116 fn subn_vx_vy(&mut self);
117 /// 8xyE - SHL Vx {, Vy}
118 ///
119 /// Set Vx = Vx SHL 1.
120 ///
121 /// If the most-significant bit of Vx is 1, then VF is set to 1, otherwise to 0. Then Vx is multiplied by 2.
122 fn shl_vx_vy(&mut self);
123 /// 8xyE - SHL Vx {, Vy}
124 ///
125 /// Set Vx = Vy SHL 1.
126 ///
127 /// If the most-significant bit of Vx is 1, then VF is set to 1, otherwise to 0. Then Vy is multiplied by 2.
128 fn shl_vx_vy_original(&mut self);
129 /// 9xy0 - SNE Vx, Vy
130 ///
131 /// Skip next instruction if Vx != Vy.
132 ///
133 /// The values of Vx and Vy are compared, and if they are not equal, the program counter is increased by 2.
134 fn sne_vx_vy(&mut self);
135 /// Annn - LD I, addr
136 ///
137 /// Set I = nnn.
138 ///
139 /// The value of register I is set to nnn.
140 fn ld_i(&mut self);
141 /// Bnnn - JP V0, addr
142 ///
143 /// Jump to location nnn + V0.
144 ///
145 /// The program counter is set to nnn plus the value of V0.
146 fn jp_v(&mut self);
147 /// Cxkk - RND Vx, byte
148 ///
149 /// Set Vx = random byte AND kk.
150 ///
151 /// The interpreter generates a random number from 0 to 255, which is then ANDed with the value kk. The results are stored in Vx. See instruction 8xy2 for more information on AND.
152 fn rnd_vx_byte(&mut self);
153 ///Dxyn - DRW Vx, Vy, nibble
154 ///
155 /// Display n-byte sprite starting at memory location I at (Vx, Vy), set VF = collision.
156 ///
157 /// The interpreter reads n bytes from memory, starting at the address stored in I.
158 ///
159 /// These bytes are then displayed as sprites on screen at coordinates (Vx, Vy).
160 ///
161 /// Sprites are XORed onto the existing screen.
162 ///
163 /// If this causes any pixels to be erased, VF is set to 1, otherwise it is set to 0.
164 ///
165 /// If the sprite is positioned so part of it is outside the coordinates of the display,
166 /// it wraps around to the opposite side of the screen.
167 fn drw_vx_vy_n(&mut self);
168 /// Ex9E - SKP Vx
169 ///
170 /// Skip next instruction if key with the value of Vx is pressed.
171 ///
172 /// Checks the keyboard, and if the key corresponding to the value of Vx is currently in the down position, PC is increased by 2.
173 fn skp_vx(&mut self);
174 /// ExA1 - SKNP Vx
175 ///
176 /// Skip next instruction if key with the value of Vx is not pressed.
177 ///
178 /// Checks the keyboard, and if the key corresponding to the value of Vx is currently in the up position, PC is increased by 2.
179 fn sknp_vx(&mut self);
180 /// Fx07 - LD Vx, DT
181 ///
182 /// Set Vx = delay timer value.
183 ///
184 /// The value of DT is placed into Vx.
185 fn ld_vx_dt(&mut self);
186 /// Fx0A - LD Vx, K
187 ///
188 /// Wait for a key press, store the value of the key in Vx.
189 ///
190 /// All execution stops until a key is pressed, then the value of that key is stored in Vx.
191 fn ld_vx_k(&mut self);
192 /// Fx15 - LD DT, Vx
193 ///
194 /// Set delay timer = Vx.
195 ///
196 /// DT is set equal to the value of Vx.
197 fn ld_dt_vx(&mut self);
198 /// Fx18 - LD ST, Vx
199 ///
200 /// Set sound timer = Vx.
201 ///
202 /// ST is set equal to the value of Vx.
203 fn ld_st_vx(&mut self);
204 /// Fx1E - ADD I, Vx
205 ///
206 /// Set I = I + Vx.
207 ///
208 /// The values of I and Vx are added, and the results are stored in I.
209 fn add_i_vx(&mut self);
210 /// Fx29 - LD F, Vx
211 ///
212 /// Set I = location of sprite for digit Vx.
213 ///
214 /// The value of I is set to the location for the hexadecimal sprite corresponding to the value of Vx. See section 2.4, Display, for more information on the Chip-8 hexadecimal font.
215 fn ld_f_vx(&mut self);
216 /// Fx33 - LD B, Vx
217 ///
218 /// Store BCD representation of Vx in memory locations I, I+1, and I+2.
219 ///
220 /// The interpreter takes the decimal value of Vx, and places the hundreds digit in memory at location in I, the tens digit at location I+1, and the ones digit at location I+2.
221 fn ld_b_vx(&mut self);
222 /// Fx55 - LD [I], Vx
223 ///
224 /// Store registers V0 through Vx in memory starting at location I.
225 ///
226 /// The interpreter copies the values of registers V0 through Vx into memory, starting at the address in I.
227 fn ld_i_vx(&mut self);
228 /// Fx55 - LD [I], Vx
229 ///
230 /// Store registers V0 through Vx in memory starting at location I.
231 ///
232 /// The interpreter copies the values of registers V0 through Vx into memory, starting at the address in I.
233 ///
234 /// Incrementing I to write the memory
235 fn ld_i_vx_original(&mut self);
236 /// Fx65 - LD Vx, [I]
237 ///
238 /// Read registers V0 through Vx from memory starting at location I.
239 ///
240 /// The interpreter reads values from memory starting at location I into registers V0 through Vx.
241 fn ld_vx_i(&mut self);
242 /// Fx55 - LD [I], Vx
243 ///
244 /// Store registers V0 through Vx in memory starting at location I.
245 ///
246 /// The interpreter copies the values of registers V0 through Vx into memory, starting at the address in I.
247 ///
248 /// Incrementing I to read the memory
249 fn ld_vx_i_original(&mut self);
250}