From f590b2d90c648db851e8059e8f082f5c507f1c5e Mon Sep 17 00:00:00 2001 From: Alex Weisberger Date: Wed, 1 Oct 2014 18:19:28 -0400 Subject: [PATCH] program loading --- src/bin/main.rs | 13 ++++++++++--- src/machine.rs | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 5e04d33..a26caeb 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -28,18 +28,25 @@ extern crate emu6502; use emu6502::machine; +use emu6502::address::Address; fn main() { let mut machine = machine::Machine::new(); + // "Load" a program + machine.memory.set_byte(&Address(0), 5); + + + // Obviously this will run the full program, just + // executing a finite num of instructions for simplicity + // right now. 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); - println!("Machine dump: {}", machine); + + println!("{}", machine); } diff --git a/src/machine.rs b/src/machine.rs index d767ccb..cab4f3d 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -25,7 +25,6 @@ // 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 std::fmt; use instruction::Instruction; @@ -53,6 +52,9 @@ impl Machine { pub fn fetch_instruction(&mut self) -> u8 { let instr = self.memory.get_byte(&self.registers.program_counter); + + // Will need smarter logic to fetch the correct number of bytes + // for instruction self.registers.program_counter.add(&AddressDiff(1)); instr } @@ -103,7 +105,7 @@ impl Machine { impl fmt::Show for Machine { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "I am a machine") + write!(f, "Machine Dump:\n\nAccumulator: {}", self.registers.accumulator) } }