mirror of
https://github.com/mre/mos6502.git
synced 2024-11-22 13:32:25 +00:00
Get some basic definitions and module structure going. Not sure whether Cargo.lock should be in .gitignore
This commit is contained in:
parent
9a81a48502
commit
b22b36bc2a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
Cargo.lock
|
||||
*.a
|
||||
*.aux
|
||||
*.bc
|
||||
|
40
Cargo.toml
Normal file
40
Cargo.toml
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2014 The 6502-rs Developers
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the names of the copyright holders nor the names of any
|
||||
# contributors may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
[package]
|
||||
|
||||
name = "6502-rs"
|
||||
version = "0.0.1"
|
||||
authors = ["The 6502-rs Developers"]
|
||||
|
||||
[[bin]]
|
||||
name = "6502-rs"
|
||||
path = "src/exe/main.rs"
|
||||
|
||||
[dependencies.defs6502]
|
||||
path="src/defs6502"
|
||||
|
36
src/defs6502/Cargo.toml
Normal file
36
src/defs6502/Cargo.toml
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright (C) 2014 The 6502-rs Developers
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the names of the copyright holders nor the names of any
|
||||
# contributors may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
[package]
|
||||
name = "defs6502"
|
||||
version = "0.0.1"
|
||||
authors = [ "The 6502-rs Developers" ]
|
||||
|
||||
[lib]
|
||||
name = "defs6502"
|
||||
path = "lib.rs"
|
||||
|
39
src/defs6502/lib.rs
Normal file
39
src/defs6502/lib.rs
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2014 The 6502-rs Developers
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the names of the copyright holders nor the names of any
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
pub use machine::ProcessorStatus;
|
||||
pub use machine::Machine;
|
||||
pub use machine::StackPointer;
|
||||
pub use machine::STACK_POINTER_IN_MEMORY_LO;
|
||||
pub use machine::STACK_POINTER_IN_MEMORY_HI;
|
||||
pub use machine::MemoryAddr;
|
||||
pub use machine::stack_pointer_to_addr;
|
||||
pub use machine::Instruction;
|
||||
pub use machine::AddressingMode;
|
||||
|
||||
mod machine;
|
||||
|
156
src/defs6502/machine/mod.rs
Normal file
156
src/defs6502/machine/mod.rs
Normal file
@ -0,0 +1,156 @@
|
||||
// Copyright (C) 2014 The 6502-rs Developers
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the names of the copyright holders nor the names of any
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Abbreviations
|
||||
//
|
||||
// Registers
|
||||
//
|
||||
// A accumulator
|
||||
// X general purpose register
|
||||
// Y general purpose register
|
||||
// SP stack pointer
|
||||
// NV-BDIZC processor status flags -- see ProcessorStatus bitflags
|
||||
// PC program counter
|
||||
//
|
||||
// M stands for `Memory location`
|
||||
|
||||
pub bitflags! {
|
||||
flags ProcessorStatus: u8 {
|
||||
static N = 0b10000000, // Negative
|
||||
static V = 0b01000000, // oVerflow
|
||||
static B = 0b00010000, // Brk
|
||||
static D = 0b00001000, // Decimal mode active?
|
||||
static I = 0b00000100, // Irq disabled?
|
||||
static Z = 0b00000010, // Zero
|
||||
static C = 0b00000001, // Carry
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Machine {
|
||||
A : u8,
|
||||
X : u8,
|
||||
Y : u8,
|
||||
SP : u8,
|
||||
P : ProcessorStatus,
|
||||
PC : u16,
|
||||
}
|
||||
|
||||
impl Machine {
|
||||
pub fn new() -> Machine {
|
||||
Machine { A: 0, X: 0, Y: 0, SP: 0, P: ProcessorStatus::empty(), PC: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StackPointer(u8);
|
||||
|
||||
pub static STACK_POINTER_IN_MEMORY_LO : u16 = 0x0100;
|
||||
pub static STACK_POINTER_IN_MEMORY_HI : u16 = 0x01FF;
|
||||
|
||||
pub struct MemoryAddr(u16);
|
||||
|
||||
pub fn stack_pointer_to_addr(StackPointer(x) : StackPointer) -> MemoryAddr
|
||||
{
|
||||
MemoryAddr(x as u16 + STACK_POINTER_IN_MEMORY_HI)
|
||||
}
|
||||
|
||||
#[deriving(Show)]
|
||||
pub enum Instruction
|
||||
// out in
|
||||
{ ADC // ADd with Carry................ A,Z,C,N = A + M + C
|
||||
, AND // logical AND................... A,Z,N = A && M
|
||||
, ASL // Arithmetic Shift Left......... A,Z,C,N = M << 1
|
||||
, BCC // Branch if Carry Clear......... _ <-
|
||||
, BCS // Branch if Carry Set...........
|
||||
, BEQ // Branch if Equal...............
|
||||
, BIT // BIT test...................... a &
|
||||
, BMI // Branch if Minus...............
|
||||
, BNE // Branch if Not Equal...........
|
||||
, BPL // Branch if Positive............
|
||||
, BRK // BReaK.........................
|
||||
, BVC // Branch if oVerflow Clear......
|
||||
, BVS // Branch if oVerflow Set........
|
||||
, CLC // CLear Carry flag..............
|
||||
, CLD // Clear Decimal Mode............
|
||||
, CLI // Clear Interrupt Disable.......
|
||||
, CLV // Clear oVerflow flag...........
|
||||
, CMP // Compare.......................
|
||||
, CPX // Compare X register............
|
||||
, CPY // Compare Y register............
|
||||
, DEC // DECrement memory..............
|
||||
, DEX // DEcrement X register..........
|
||||
, DEY // DEcrement Y register..........
|
||||
, EOR // Exclusive OR..................
|
||||
, INC // INCrement memory..............
|
||||
, INX // INcrement X register..........
|
||||
, INY // INcrement Y register..........
|
||||
, JMP // JuMP..........................
|
||||
, JSR // Jump to SubRoutine............
|
||||
, LDA // LoaD Accumulator..............
|
||||
, LDX // LoaD X register...............
|
||||
, LDY // LoaD Y register...............
|
||||
, LSR // Logical Shift Right...........
|
||||
, NOP // No OPeration..................
|
||||
, ORA // inclusive OR..................
|
||||
, PHA // PusH Accumulator..............
|
||||
, PHP // PusH Processor status.........
|
||||
, PLA // PuLl Accumulator..............
|
||||
, PLP // PuLl Processor status.........
|
||||
, ROL // ROtate Left...................
|
||||
, ROR // ROtate Right..................
|
||||
, RTI // ReTurn from Interrupt.........
|
||||
, RTS // ReTurn from Subroutine........
|
||||
, SBC // SuBtract with Carry...........
|
||||
, SEC // SEt Carry flag................
|
||||
, SED // SEt Decimal flag..............
|
||||
, SEI // SEt Interrupt disable.........
|
||||
, STA // STore Accumulator.............
|
||||
, STX // STore X register..............
|
||||
, STY // STore Y register..............
|
||||
, TAX // Transfer Accumulator to X.....
|
||||
, TAY // Transfer Accumulator to Y.....
|
||||
, TSX // Transfer Stack pointer to X...
|
||||
, TXA // Transfer X to Accumulator.....
|
||||
, TXS // Transfer X to Stack pointer...
|
||||
, TYA // Transfer Y to Accumulator.....
|
||||
}
|
||||
|
||||
pub enum AddressingMode {
|
||||
Immediate,
|
||||
Absolute,
|
||||
ZeroPage,
|
||||
Implied,
|
||||
IndirectAbsolute,
|
||||
AbsoluteIndexedX,
|
||||
AbsoluteIndexedY,
|
||||
ZeroPageIndexedX,
|
||||
ZeroageIndexedY,
|
||||
IndexedIndirect,
|
||||
IndirectIndexed,
|
||||
Relative,
|
||||
Accumulator,
|
||||
}
|
||||
|
37
src/exe/main.rs
Normal file
37
src/exe/main.rs
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2014 The 6502-rs Developers
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the names of the copyright holders nor the names of any
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
extern crate defs6502;
|
||||
|
||||
use defs6502::Machine;
|
||||
|
||||
fn main() {
|
||||
let _q = Machine::new();
|
||||
|
||||
println!("Hello, 6502?");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user