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:
parent
54fd9aa72f
commit
be65550525
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user