mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 22:51:26 +00:00
program loading
This commit is contained in:
parent
f2a47f4b00
commit
f590b2d90c
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user