Skip to content

Commit

Permalink
Add 7 addressing modes of lea
Browse files Browse the repository at this point in the history
  • Loading branch information
marhel committed Feb 15, 2016
1 parent 1b04274 commit 3ce3eb0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/cpu/ops/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const OP_EXG : u32 = 0b1100_0001_0000_0000;
const OP_EXT : u32 = 0b0100_1000_0000_0000;
const OP_JMP : u32 = 0b0100_1110_1100_0000;
const OP_JSR : u32 = 0b0100_1110_1000_0000;

const OP_LEA : u32 = 0b0100_0001_1100_0000;
const OP_SUB : u32 = 0b1001_0000_0000_0000;
const OP_SUBI : u32 = 0b0000_0100_0000_0000;
const OP_SUBQ : u32 = 0b0101_0001_0000_0000;
Expand Down Expand Up @@ -768,6 +768,14 @@ pub const OP_JSR_32_PCDI : u32 = OP_JSR | OPER_PCDI;
pub const OP_JSR_32_PCIX : u32 = OP_JSR | OPER_PCIX;

// Put constants for LEA here
pub const OP_LEA_32_AI : u32 = OP_LEA | OPER_AI;
pub const OP_LEA_32_AL : u32 = OP_LEA | OPER_AL;
pub const OP_LEA_32_AW : u32 = OP_LEA | OPER_AW;
pub const OP_LEA_32_DI : u32 = OP_LEA | OPER_DI;
pub const OP_LEA_32_IX : u32 = OP_LEA | OPER_IX;
pub const OP_LEA_32_PCDI : u32 = OP_LEA | OPER_PCDI;
pub const OP_LEA_32_PCIX : u32 = OP_LEA | OPER_PCIX;

// Put constants for LINK here
// Put constants for LSL, LSR here
// Put constants for MOVE here
Expand Down Expand Up @@ -1614,6 +1622,14 @@ pub fn generate() -> InstructionSet {
op_entry!(MASK_EXACT, OP_JSR_32_PCIX, jsr_32_pcix),

// Put op-entries for LEA here
op_entry!(MASK_OUT_Y, OP_LEA_32_AI, lea_32_ai),
op_entry!(MASK_EXACT, OP_LEA_32_AL, lea_32_al),
op_entry!(MASK_EXACT, OP_LEA_32_AW, lea_32_aw),
op_entry!(MASK_OUT_Y, OP_LEA_32_DI, lea_32_di),
op_entry!(MASK_OUT_Y, OP_LEA_32_IX, lea_32_ix),
op_entry!(MASK_EXACT, OP_LEA_32_PCDI, lea_32_pcdi),
op_entry!(MASK_EXACT, OP_LEA_32_PCIX, lea_32_pcix),

// Put op-entries for LINK here
// Put op-entries for LSL, LSR here
// Put op-entries for MOVE here
Expand Down Expand Up @@ -1939,4 +1955,8 @@ mod tests {
fn correctly_defined_op_jsr_32_ix() {
assert_eq!(0x4eb0, OP_JSR_32_IX);
}
#[test]
fn correctly_defined_op_lea_32_ai() {
assert_eq!(0x41d0, OP_LEA_32_AI);
}
}
16 changes: 16 additions & 0 deletions src/cpu/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,22 @@ jump_try!(jsr_32_pcdi, displacement_pc, true, 18);
jump_try!(jsr_32_pcix, index_pc, true, 22);

// Put implementation of LEA ops here
macro_rules! lea {
($name:ident, $dst:ident, $cycles:expr) => (
pub fn $name(core: &mut Core) -> Result<Cycles> {
let ea = try!(effective_address::$dst(core));
ax!(core) = ea;
Ok(Cycles($cycles))
})
}
lea!(lea_32_ai, address_indirect_ay, 4);
lea!(lea_32_di, displacement_ay, 8);
lea!(lea_32_ix, index_ay, 12);
lea!(lea_32_aw, absolute_word, 8);
lea!(lea_32_al, absolute_long, 12);
lea!(lea_32_pcdi, displacement_pc, 8);
lea!(lea_32_pcix, index_pc, 12);

// Put implementation of LINK ops here
// Put implementation of LSL, LSR ops here
// Put implementation of MOVE ops here
Expand Down
7 changes: 7 additions & 0 deletions src/musashi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,13 @@ mod tests {
qc!(OP_JSR_32_PCIX, MASK_EXACT, qc_jsr_32_pcix);

// Put qc for LEA here
qc!(OP_LEA_32_AI, MASK_OUT_Y, lea_32_ai);
qc!(OP_LEA_32_AL, MASK_EXACT, lea_32_al);
qc!(OP_LEA_32_AW, MASK_EXACT, lea_32_aw);
qc!(OP_LEA_32_DI, MASK_OUT_Y, lea_32_di);
qc!(OP_LEA_32_IX, MASK_OUT_Y, lea_32_ix);
qc!(OP_LEA_32_PCDI, MASK_EXACT, lea_32_pcdi);
qc!(OP_LEA_32_PCIX, MASK_EXACT, lea_32_pcix);
// Put qc for LINK here
// Put qc for LSL, LSR here
// Put qc for MOVE here
Expand Down

0 comments on commit 3ce3eb0

Please sign in to comment.