Skip to content

Commit

Permalink
Add rte instruction
Browse files Browse the repository at this point in the history
Resets ProcessingState back to Normal

Closes #41
  • Loading branch information
marhel committed Apr 19, 2016
1 parent 3bde099 commit 7e928b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cpu/ops/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,8 @@ pub const OP_ROXR_16_AW : u32 = OP_SHIFT | SHIFT_RIGHT | WORD_SIZED | ROTX_
pub const OP_ROXR_16_AL : u32 = OP_SHIFT | SHIFT_RIGHT | WORD_SIZED | ROTX_MEM_SHIFT | OPER_AL;

// Put constants for RTE here
pub const OP_RTE_32 : u32 = 0b0100111001110011;

// Put constants for RTR here
// Put constants for RTS here

Expand Down Expand Up @@ -3270,6 +3272,8 @@ fn generate_optable() -> Vec<OpcodeHandler> {
op_entry!(MASK_EXACT, OP_ROXR_16_AL, roxr_16_al),

// Put op-entries for RTE here
op_entry!(MASK_EXACT, OP_RTE_32, rte_32),

// Put op-entries for RTR here
// Put op-entries for RTS here
//
Expand Down Expand Up @@ -4184,4 +4188,8 @@ mod tests {
fn correctly_defined_op_stop() {
assert_eq!(0x4e72, OP_STOP);
}
#[test]
fn correctly_defined_op_rte_32() {
assert_eq!(0x4e73, OP_RTE_32);
}
}
17 changes: 16 additions & 1 deletion src/cpu/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![macro_use]
use super::{Core, Cycles, Result, EXCEPTION_CHK, EXCEPTION_ZERO_DIVIDE};
use super::{Core, Cycles, Result, ProcessingState, EXCEPTION_CHK, EXCEPTION_ZERO_DIVIDE};
use super::Exception::*;

mod common;
Expand Down Expand Up @@ -2816,6 +2816,21 @@ roxr_16!(roxr_16_aw, ea_aw_16, 16);
roxr_16!(roxr_16_al, ea_al_16, 20);

// Put implementation of RTE ops here
pub fn rte_32(core: &mut Core) -> Result<Cycles> {
if core.s_flag != 0 {
let new_sr = core.pop_16();
let new_pc = core.pop_32();
core.jump(new_pc);
core.sr_to_flags(new_sr);

core.processing_state = ProcessingState::Normal;

Ok(Cycles(20))
} else {
Err(PrivilegeViolation(core.ir, core.pc.wrapping_sub(2)))
}
}

// Put implementation of RTR ops here
// Put implementation of RTS ops here

Expand Down
2 changes: 2 additions & 0 deletions src/musashi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,8 @@ mod tests {
qc!(MASK_EXACT, OP_ROXR_16_AL, qc_roxr_16_al);

// Put qc for RTE here
qc8!(MASK_EXACT, OP_RTE_32, qc_rte_32);

// Put qc for RTR here
// Put qc for RTS here

Expand Down

0 comments on commit 7e928b6

Please sign in to comment.