|
@@ -346,46 +346,46 @@ int main(int argc, char **argv) {
|
346
|
346
|
reg = (opcode & 0x0F00) >> 8;
|
347
|
347
|
switch ((byte) opcode)
|
348
|
348
|
{
|
349
|
|
- case 0x07:
|
|
349
|
+ case 0x07: // set reg to delay time
|
350
|
350
|
if (DEBUG) printf("Copying delay timer to reg %i (%hx)", reg, state.registers[reg]);
|
351
|
351
|
state.registers[reg] = delay;
|
352
|
352
|
break;
|
353
|
353
|
|
354
|
|
- case 0x0A:
|
|
354
|
+ case 0x0A: // wait for input and store it in reg
|
355
|
355
|
wait = 1;
|
356
|
356
|
store = reg;
|
357
|
357
|
break;
|
358
|
358
|
|
359
|
|
- case 0x15:
|
|
359
|
+ case 0x15: // set delay timer to value in reg
|
360
|
360
|
delay = state.registers[reg];
|
361
|
361
|
break;
|
362
|
362
|
|
363
|
|
- case 0x18:
|
|
363
|
+ case 0x18: // set sound timer to value in reg
|
364
|
364
|
sound = state.registers[reg];
|
365
|
365
|
break;
|
366
|
366
|
|
367
|
|
- case 0x1E:
|
|
367
|
+ case 0x1E: // Add value stored in VX to I
|
368
|
368
|
state.address_I += state.registers[reg];
|
369
|
369
|
if (DEBUG) printf("Adding reg %i (%hx) to I (%x)", reg, state.registers[reg], state.address_I);
|
370
|
370
|
break;
|
371
|
371
|
|
372
|
|
- case 0x29:
|
|
372
|
+ case 0x29: // set I to address of font character
|
373
|
373
|
state.address_I = state.registers[reg] * 5;
|
374
|
374
|
break;
|
375
|
375
|
|
376
|
|
- case 0x33:;
|
|
376
|
+ case 0x33:; // encode value in reg as a BCD at I, I+1, I+2
|
377
|
377
|
int value = state.registers[reg];
|
378
|
378
|
state.memory[state.address_I] = value / 100;
|
379
|
379
|
state.memory[state.address_I + 1] = (value / 10) % 10;
|
380
|
380
|
state.memory[state.address_I + 2] = value % 10;
|
381
|
381
|
break;
|
382
|
382
|
|
383
|
|
- case 0x55:
|
|
383
|
+ case 0x55: // dump registers V0 -> VX at I
|
384
|
384
|
for (int i = 0; i <= reg; ++i)
|
385
|
385
|
state.memory[state.address_I + i] = state.registers[i];
|
386
|
386
|
break;
|
387
|
387
|
|
388
|
|
- case 0x65:
|
|
388
|
+ case 0x65: // retrieve registers V0 -> VX from I
|
389
|
389
|
for (int i = 0; i <= reg; ++i)
|
390
|
390
|
state.registers[i] = state.memory[state.address_I + i];
|
391
|
391
|
break;
|