From 4b506f3e658f119755717e4237a92f34bf0fbab1 Mon Sep 17 00:00:00 2001 From: Ry Date: Tue, 9 Aug 2022 01:41:13 -0700 Subject: [PATCH] Add `int` instruction, bump version to 0.2.0 --- Cargo.toml | 4 +--- docs/encoding.md | 2 +- src/cpu.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47e8401..9d5ed31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,10 @@ [package] name = "fox32" -version = "0.1.0" +version = "0.2.0" authors = ["ry"] edition = "2021" build = "build.rs" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] image = "0.24" log = "0.4" diff --git a/docs/encoding.md b/docs/encoding.md index 804a493..5f72aea 100644 --- a/docs/encoding.md +++ b/docs/encoding.md @@ -18,7 +18,7 @@ If the instruction doesn't allow variable sizes or a size was not specified, set | :-: | ---- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | -------------- | ---- | ----- | -------------- | --- | --- | --- | --- | --- | | 0- | NOP | ADD[.8,16,32] | MUL[.8,16,32] | AND[.8,16,32] | SLA[.8,16,32] | SRA[.8,16,32] | BSE[.8,16,32] | CMP[.8,16,32] | JMP | RJMP | PUSH[.8,16,32] | IN | ISE | | | | | 1- | HALT | INC[.8,16,32] | | OR[.8,16,32] | | SRL[.8,16,32] | BCL[.8,16,32] | MOV[.8,16,32] | CALL | RCALL | POP[.8,16,32] | OUT | ICL | | | | -| 2- | BRK | SUB[.8,16,32] | DIV[.8,16,32] | XOR[.8,16,32] | ROL[.8,16,32] | ROR[.8,16,32] | BTS[.8,16,32] | MOVZ[.8,16,32] | LOOP | RLOOP | RET | | | | | | +| 2- | BRK | SUB[.8,16,32] | DIV[.8,16,32] | XOR[.8,16,32] | ROL[.8,16,32] | ROR[.8,16,32] | BTS[.8,16,32] | MOVZ[.8,16,32] | LOOP | RLOOP | RET | | INT | | | | | 3- | | DEC[.8,16,32] | REM[.8,16,32] | NOT[.8,16,32] | | | | | | RTA | RETI | | | | | | # Condition table diff --git a/src/cpu.rs b/src/cpu.rs index 9fec1a6..0e91522 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -2571,6 +2571,17 @@ impl Cpu { } self.instruction_pointer + instruction_pointer_offset } + Instruction::Int(condition, source) => { + let (source_value, instruction_pointer_offset) = self.read_source(source); + let should_run = self.check_condition(condition); + if should_run { + self.instruction_pointer += instruction_pointer_offset; + self.handle_interrupt(source_value as u16); + self.instruction_pointer + } else { + self.instruction_pointer + instruction_pointer_offset + } + } } } } @@ -2660,6 +2671,7 @@ enum Instruction { Ise(Condition), Icl(Condition), + Int(Condition, Operand), } impl Instruction { @@ -2754,6 +2766,7 @@ impl Instruction { 0x0C => Some(Instruction::Ise(condition)), 0x1C => Some(Instruction::Icl(condition)), + 0x2C => Some(Instruction::Int(condition, source)), _ => None, }