1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-28 22:51:26 +00:00

fetch, decode, execute loop

This commit is contained in:
Alex Weisberger 2014-10-01 18:02:45 -04:00
parent 54fd9aa72f
commit be65550525
2 changed files with 32 additions and 5 deletions

View File

@ -31,10 +31,13 @@ use emu6502::machine;
fn main() {
let mut machine = machine::Machine::new();
println!("A: {}", machine.registers.accumulator);
println!("add_with_carry(1)");
machine.add_with_carry(1);
println!("A: {}", machine.registers.accumulator);
for _ in range(0u, 2u) {
let raw_instruction = machine.fetch_instruction();
let instruction = machine.decode_instruction(raw_instruction);
machine.execute_instruction(instruction);
}
println!("Ran program, output of Accum is {}", machine.registers.accumulator);
}

View File

@ -25,6 +25,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
use address::Address;
use address::AddressDiff;
use instruction::Instruction;
use instruction::ADC;
use memory::Memory;
use registers::{ Registers, Status, StatusArgs };
use registers::{ ps_negative, ps_overflow, ps_zero, ps_carry };
@ -45,6 +49,26 @@ impl Machine {
pub fn reset(&mut self) {
*self = Machine::new();
}
pub fn fetch_instruction(&mut self) -> u8 {
let instr = self.memory.get_byte(&self.registers.program_counter);
self.registers.program_counter.add(&AddressDiff(1));
instr
}
pub fn decode_instruction(&mut self, raw_instruction: u8) -> Instruction {
ADC
}
pub fn execute_instruction(&mut self, instruction: Instruction) {
match instruction {
ADC => {
println!("executing add with carry");
self.add_with_carry(1);
}
_ => println!("attempting to execute unimplemented instruction")
};
}
// TODO akeeton: Implement binary-coded decimal.
pub fn add_with_carry(&mut self, value: i8) {