Ruby Quiz <james / grayproductions.net> writes:

>1. Make the emulator read the file. All opcodes are four digit hex numbers,
>   but those will need to be split.

What's not specified here is that the opcodes are written to the file
as big-endian 16-bit numbers.  That is, most significant digit first.
The file represents a memory dump of a simple chip-8 processor that
begins at memory address 0000.

> 2. Set up the registers and other assorted things so they can be modified.

I'll note that the spec. nowhere tells us what the initial, power-on
values of the registers are.  My personal recommendation is that
people intialize the registers with random values, so that bad chip-8
programs would be caught.  As an addition, it might be nice to accept
command line arguments to initialize the registers.

> 3. Interpret the function of the opcode in Ruby.
> 4. Dump all the registers so you can check and make sure everything went well.

I'd really like some more I/O than this.  I'm tempted to add an
extension that does memory mapped IO, or, looking at the chip-8 page,
implement the graphics through ASCII-graphics.

<snip>

> While I'm on the subject, let's talk about addresses in detail. Your
> current address in the file is how many bytes you are from the
> beginning of the file. So if I am at address 008 in the file, I am
> eight bytes away from the beginning of the file, and therefore the
> next byte I read will be byte nine. Say we had the opcode 100F, that
> means we would jump to after byte 16 (it is a hex remember).

I'm not sure you mean this.  I think you mean either "jump to before
the 16th byte" or meant to use opcode 1010.

Looking at your program, I see an easy way to make this explanation
easier:

  Opcode 0100 will send you back to the beginning, so that the next
  instruction read and executed is the first instruction of the file.
  Opcode 0102 will send you back to the second instruction in the file
  (remember that instructions are four hex digits - or two bytes -
  long).  Other addresses follow.

> Be sure to start reading the attached program from the beginning. To
> my understanding in a real Chip-8 game up to address 200 was
> reserved for machine code which we wont worry about.

In case people are looking at this in an environment where they can't
get online and grab the program, here's a short ruby program that
recreates the file:

File.open("Chip8Test","wb") { |f|
  x = "x"
  %w{ 61 77 62 45 71 01 83 20 81 21 81 22 82 33 81 34
      82 35 81 06 83 27 83 0e 64 ff c4 11 32 bb 10 00
      00 00 }.each {|b| x[0] = b.hex; f.write(x)}
}