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

@ -32,9 +32,12 @@ use emu6502::machine;
fn main() { fn main() {
let mut machine = machine::Machine::new(); let mut machine = machine::Machine::new();
println!("A: {}", machine.registers.accumulator); for _ in range(0u, 2u) {
println!("add_with_carry(1)"); let raw_instruction = machine.fetch_instruction();
machine.add_with_carry(1); let instruction = machine.decode_instruction(raw_instruction);
println!("A: {}", machine.registers.accumulator); 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 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE. // POSSIBILITY OF SUCH DAMAGE.
use address::Address;
use address::AddressDiff;
use instruction::Instruction;
use instruction::ADC;
use memory::Memory; use memory::Memory;
use registers::{ Registers, Status, StatusArgs }; use registers::{ Registers, Status, StatusArgs };
use registers::{ ps_negative, ps_overflow, ps_zero, ps_carry }; use registers::{ ps_negative, ps_overflow, ps_zero, ps_carry };
@ -46,6 +50,26 @@ impl Machine {
*self = Machine::new(); *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. // TODO akeeton: Implement binary-coded decimal.
pub fn add_with_carry(&mut self, value: i8) { pub fn add_with_carry(&mut self, value: i8) {
let a_before: i8 = self.registers.accumulator; let a_before: i8 = self.registers.accumulator;