amw-zero/6502-rs — pull request #7 by amw-zero (2014-10-01 22:54:44+00:00)
Title: Controller2

Hey guys, I wanted you to take a look at this because this is as fundamental as it gets. I implemented the fetch/decode/execute loop so that we can run programs stored in memory. It's nowhere near a "complete" implementation, I'm just starting the program from memory location 0x00 and going from there. I'm not sure where program memory starts.

The main concern is, different instructions use different data and are different lengths. ADC Immediate is the only one implemented here. But as you can see, the instruction is actually 2 bytes, so when the decode logic sees the 0x69 opcode (ADC Immedidate), the immediate byte is fetched from the next location in memory. This is what gets used to add to the Accumulator register, so I'm then passing it along via the Instruction enum. I think the Instruction data type should also hold the operand, so I think this implementation is correct. Unless there's something smarter to do.

The next thing is, we need to decide on u8 vs. i8 for memory and use it everywhere. I had to cast the raw instruction to an i8 because that's what add_with_carry() operates on, but Memory holds u8's.

I also implemented the Show trait for Machine, so you can now just println!("{}", machine) which is nice. It only prints out the value of the accumulator, but we can obviously extend that. I'll probably merge this later tonight unless there are strong objections on what's going on here. We can always talk tomorrow.