mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 22:51:26 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
bba4ded34d
11
Cargo.toml
11
Cargo.toml
@ -32,16 +32,19 @@ description = "A MOS 6502 Emulator"
|
||||
license = "BSD-3-Clause"
|
||||
version = "0.0.1"
|
||||
authors = ["The 6502-rs Developers"]
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
# This will look in src/lib.rs
|
||||
name = "mos6502"
|
||||
|
||||
[[bin]]
|
||||
# This will look in src/bin/mos6502.rs
|
||||
name = "mos6502"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "0.9.1"
|
||||
log = "0.3.8"
|
||||
num = "0.1"
|
||||
|
||||
[build-dependencies]
|
||||
skeptic = "0.13"
|
||||
|
||||
[dev-dependencies]
|
||||
skeptic = "0.13"
|
||||
|
110
README.md
110
README.md
@ -7,3 +7,113 @@ This started off as a fork of [6502-rs](https://github.com/amw-zero/6502-rs),
|
||||
which seems to be unmaintained at this point.
|
||||
|
||||
It builds with the latest stable Rust.
|
||||
|
||||
## Usage example
|
||||
|
||||
```rust
|
||||
extern crate mos6502;
|
||||
|
||||
use mos6502::cpu;
|
||||
use mos6502::address::Address;
|
||||
|
||||
fn main() {
|
||||
let mut cpu = cpu::CPU::new();
|
||||
|
||||
let zero_page_data = [
|
||||
// ZeroPage data start
|
||||
0x00,
|
||||
0x02, // ADC ZeroPage target
|
||||
0x00,
|
||||
0x04, // ADC ZeroPageX target
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x10, // ADC IndexedIndirectX address
|
||||
0x80, // ADC IndexedIndirectX address
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x08, // ADC IndirectIndexedY address
|
||||
0x80, // ADC IndirectIndexedY address
|
||||
];
|
||||
|
||||
let program = [
|
||||
// Code start
|
||||
0xA9, // LDA Immediate
|
||||
0x01, // Immediate operand
|
||||
0x69, // ADC Immediate
|
||||
0x07, // Immediate operand
|
||||
0x65, // ADC ZeroPage
|
||||
0x01, // ZeroPage operand
|
||||
0xA2, // LDX Immediate
|
||||
0x01, // Immediate operand
|
||||
0x75, // ADC ZeroPageX
|
||||
0x02, // ZeroPageX operand
|
||||
0x6D, // ADC Absolute
|
||||
0x01, // Absolute operand
|
||||
0x80, // Absolute operand
|
||||
0xA2, // LDX immediate
|
||||
0x08, // Immediate operand
|
||||
0x7D, // ADC AbsoluteX
|
||||
0x00, // AbsoluteX operand
|
||||
0x80, // AbsoluteX operand
|
||||
0xA0, // LDY immediate
|
||||
0x04, // Immediate operand
|
||||
0x79, // ADC AbsoluteY
|
||||
0x00, // AbsoluteY operand
|
||||
0x80, // AbsoluteY operand
|
||||
0xA2, // LDX immediate
|
||||
0x05, // Immediate operand
|
||||
0x61, // ADC IndexedIndirectX
|
||||
0x03, // IndexedIndirectX operand
|
||||
0xA0, // LDY immediate
|
||||
0x10, // Immediate operand
|
||||
0x71, // ADC IndirectIndexedY
|
||||
0x0F, // IndirectIndexedY operand
|
||||
0xEA, // NOP :)
|
||||
0xFF, // Something invalid -- the end!
|
||||
];
|
||||
|
||||
let data: [u8; 25] = [
|
||||
0x00,
|
||||
0x09, // ADC Absolute target
|
||||
0x00,
|
||||
0x00,
|
||||
0x40, // ADC AbsoluteY target
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x11, // ADC AbsoluteX target
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x12, // ADC IndexedIndirectX target
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x06, // ADC IndirectIndexedY target
|
||||
];
|
||||
|
||||
// "Load" a program
|
||||
cpu.memory.set_bytes(Address(0x0000), &zero_page_data);
|
||||
cpu.memory.set_bytes(Address(0x4000), &program);
|
||||
cpu.memory.set_bytes(Address(0x8000), &data);
|
||||
|
||||
cpu.registers.program_counter = Address(0x4000);
|
||||
|
||||
cpu.run();
|
||||
|
||||
println!("{:?}", cpu);
|
||||
}
|
||||
```
|
||||
|
5
build.rs
Normal file
5
build.rs
Normal file
@ -0,0 +1,5 @@
|
||||
extern crate skeptic;
|
||||
|
||||
fn main() {
|
||||
skeptic::generate_doc_tests(&["README.md"]);
|
||||
}
|
@ -39,10 +39,8 @@ fn main() {
|
||||
|
||||
// "Load" a program
|
||||
|
||||
// JAM: FIXME: What's the syntax for specifying the array element type,
|
||||
// but not the length? (For a fixed-size array)
|
||||
|
||||
let zero_page_data: [u8; 17] = [
|
||||
let zero_page_data = [
|
||||
// ZeroPage data start
|
||||
0x00,
|
||||
0x02, // ADC ZeroPage target
|
||||
@ -63,7 +61,7 @@ fn main() {
|
||||
0x80, // ADC IndirectIndexedY address
|
||||
];
|
||||
|
||||
let program: [u8; 33] = [
|
||||
let program = [
|
||||
// Code start
|
||||
0xA9, // LDA Immediate
|
||||
0x01, // Immediate operand
|
||||
@ -100,7 +98,7 @@ fn main() {
|
||||
0xFF, // Something invalid -- the end!
|
||||
];
|
||||
|
||||
let data: [u8; 25] = [
|
||||
let data = [
|
||||
0x00,
|
||||
0x09, // ADC Absolute target
|
||||
0x00,
|
||||
|
@ -410,13 +410,10 @@ impl CPU {
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
loop {
|
||||
if let Some(decoded_instr) = self.fetch_next_and_decode() {
|
||||
while let Some(decoded_instr) = self.fetch_next_and_decode() {
|
||||
self.execute_instruction(decoded_instr);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn set_flags_from_i8(status: &mut Status, value: i8) {
|
||||
|
@ -58,17 +58,17 @@ impl StatusArgs {
|
||||
|
||||
bitflags! {
|
||||
pub struct Status: u8 {
|
||||
const PS_NEGATIVE = 0b10000000;
|
||||
const PS_OVERFLOW = 0b01000000;
|
||||
const PS_UNUSED = 0b00100000; // JAM: Should this exist?
|
||||
const PS_NEGATIVE = 0b1000_0000;
|
||||
const PS_OVERFLOW = 0b0100_0000;
|
||||
const PS_UNUSED = 0b0010_0000; // JAM: Should this exist?
|
||||
// (note that it affects the
|
||||
// behavior of things like
|
||||
// from_bits_truncate)
|
||||
const PS_BRK = 0b00010000;
|
||||
const PS_DECIMAL_MODE = 0b00001000;
|
||||
const PS_DISABLE_INTERRUPTS = 0b00000100;
|
||||
const PS_ZERO = 0b00000010;
|
||||
const PS_CARRY = 0b00000001;
|
||||
const PS_BRK = 0b0001_0000;
|
||||
const PS_DECIMAL_MODE = 0b0000_1000;
|
||||
const PS_DISABLE_INTERRUPTS = 0b0000_0100;
|
||||
const PS_ZERO = 0b0000_0010;
|
||||
const PS_CARRY = 0b0000_0001;
|
||||
}
|
||||
}
|
||||
|
||||
|
1
tests/skeptic.rs
Normal file
1
tests/skeptic.rs
Normal file
@ -0,0 +1 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));
|
Loading…
Reference in New Issue
Block a user