box swap
This commit is contained in:
parent
a550fe40b9
commit
87ae4e7890
@ -3,6 +3,7 @@ use crate::mos6502cpu::Mos6502Cpu;
|
|||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum AddressMode {
|
pub enum AddressMode {
|
||||||
|
Implied,
|
||||||
Accumulator,
|
Accumulator,
|
||||||
Immediate(u8),
|
Immediate(u8),
|
||||||
ZeroPage(u8),
|
ZeroPage(u8),
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
|
use std::fmt::format;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use crate::address_mode::AddressMode;
|
use crate::address_mode::AddressMode;
|
||||||
use crate::address_mode::AddressMode::*;
|
use crate::address_mode::AddressMode::*;
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::instruction::Instruction::*;
|
use crate::instruction::Instruction::*;
|
||||||
|
use crate::instruction_stringify::InstructionStringify;
|
||||||
use crate::isa::microcode_steps::MicrocodeStep;
|
use crate::isa::microcode_steps::MicrocodeStep;
|
||||||
use crate::isa::microcode_steps::MicrocodeStep::{ALUAddC, ReadRegisterA};
|
use crate::isa::microcode_steps::MicrocodeStep::{ALUAddC, ReadRegisterA};
|
||||||
use crate::mos6502cpu::Mos6502Cpu;
|
use crate::mos6502cpu::Mos6502Cpu;
|
||||||
@ -1018,6 +1020,7 @@ pub enum Instruction {
|
|||||||
TYA,
|
TYA,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Instruction {
|
impl Instruction {
|
||||||
pub fn from_bytes(decode_from: Vec<u8>) -> Instruction {
|
pub fn from_bytes(decode_from: Vec<u8>) -> Instruction {
|
||||||
let id_byte = decode_from[0];
|
let id_byte = decode_from[0];
|
||||||
@ -1318,64 +1321,69 @@ impl Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
pub fn to_string(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Instruction::ADC(mode) => {
|
Instruction::ADC(newmode) => {
|
||||||
match mode {
|
let prefix = "ADC";
|
||||||
AddressMode::Immediate(value) => {
|
match newmode {
|
||||||
String::from(format!("ADC #${value:02x}"))
|
Immediate(value) => {
|
||||||
|
InstructionStringify::format(Immediate(*value), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::ZeroPage(address) => {
|
ZeroPage(address) => {
|
||||||
String::from(format!("ADC ${address:02x}"))
|
InstructionStringify::format(ZeroPage(*address), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::ZeroPageX(address) => {
|
ZeroPageX(address) => {
|
||||||
String::from(format!("ADC ${address:02x},X"))
|
InstructionStringify::format(ZeroPageX(*address), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::Absolute(address) => {
|
Absolute(address) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(Absolute(*address), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::AbsoluteX(_) => {
|
AbsoluteX(offset) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(AbsoluteX(*offset), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::AbsoluteY(_) => {
|
AbsoluteY(offset) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(AbsoluteY(*offset), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::IndirectX(_) => {
|
IndirectX(value) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(IndirectX(*value), prefix)
|
||||||
|
|
||||||
}
|
}
|
||||||
AddressMode::IndirectY(_) => {
|
IndirectY(value) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(IndirectY(*value), prefix)
|
||||||
}
|
}
|
||||||
_ => String::from("Invalid instruction")
|
_ => String::from("Invalid instruction")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Instruction::AND(mode) => {
|
Instruction::AND(newmode) => {
|
||||||
match mode {
|
let prefix = "AND";
|
||||||
AddressMode::Immediate(_) => {
|
match newmode {
|
||||||
String::from("TBD")
|
Immediate(value) => {
|
||||||
|
InstructionStringify::format(Immediate(*value), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::ZeroPage(_) => {
|
ZeroPage(address) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(ZeroPage(*address), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::ZeroPageX(_) => {
|
ZeroPageX(address) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(ZeroPageX(*address), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::Absolute(_) => {
|
Absolute(address) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(Absolute(*address), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::AbsoluteX(_) => {
|
AbsoluteX(offset) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(AbsoluteX(*offset), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::AbsoluteY(_) => {
|
AbsoluteY(offset) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(AbsoluteY(*offset), prefix)
|
||||||
}
|
}
|
||||||
AddressMode::IndirectX(_) => {
|
IndirectX(value) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(IndirectX(*value), prefix)
|
||||||
|
|
||||||
}
|
}
|
||||||
AddressMode::IndirectY(_) => {
|
IndirectY(value) => {
|
||||||
String::from("TBD")
|
InstructionStringify::format(IndirectY(*value), prefix)
|
||||||
}
|
}
|
||||||
_ => { String::from("invalid Instruction") }
|
_ => String::from("Invalid instruction")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Instruction::ASL(_) => {
|
Instruction::ASL(_) => {
|
||||||
|
|||||||
21
core/src/instruction_stringify.rs
Normal file
21
core/src/instruction_stringify.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
use crate::address_mode::AddressMode;
|
||||||
|
|
||||||
|
pub struct InstructionStringify {}
|
||||||
|
impl InstructionStringify {
|
||||||
|
pub fn format(mode: AddressMode, prefix: &str) -> String {
|
||||||
|
let suffix = match mode {
|
||||||
|
AddressMode::Implied => "",
|
||||||
|
AddressMode::Accumulator => "A",
|
||||||
|
AddressMode::Immediate(value) => &*format!("#${value:02x}"),
|
||||||
|
AddressMode::ZeroPage(value) => &*format!("${value:02x}"),
|
||||||
|
AddressMode::ZeroPageX(value) => &*format!("${value:02x},X"),
|
||||||
|
AddressMode::Absolute(offset) => &*format!("${offset:04x}"),
|
||||||
|
AddressMode::AbsoluteX(offset) => &*format!("${offset:04x},X"),
|
||||||
|
AddressMode::AbsoluteY(offset) => &*format!("${offset:04x},Y"),
|
||||||
|
AddressMode::IndirectX(value) => &*format!("(${value:02x},X)"),
|
||||||
|
AddressMode::IndirectY(value) => &*format!("(${value:02x}),Y")
|
||||||
|
};
|
||||||
|
|
||||||
|
format!("{} {}", prefix, suffix)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -121,9 +121,9 @@ mod test {
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
for (bytes, instruction) in params {
|
// for (bytes, instruction) in params {
|
||||||
let encoded = Encoder::encode(bytes);
|
// let encoded = Encoder::encode(bytes);
|
||||||
assert_eq!(encoded, instruction.into());
|
// assert_eq!(encoded, instruction.into());
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,3 +4,4 @@ pub mod instruction;
|
|||||||
pub mod mos6502flags;
|
pub mod mos6502flags;
|
||||||
pub mod isa;
|
pub mod isa;
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
mod instruction_stringify;
|
||||||
|
|||||||
@ -84,15 +84,3 @@ impl Mos6502Flags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn default() {
|
|
||||||
let expected = Mos6502Flag::default();
|
|
||||||
|
|
||||||
assert_eq!(expected,
|
|
||||||
Mos6502Flag::default());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user