Hack memory writes to use longjmp if a page fault occurs
This commit is contained in:
parent
8259e5787e
commit
3ce3af511e
254
src/cpu.rs
254
src/cpu.rs
|
@ -168,7 +168,7 @@ impl Cpu {
|
||||||
pub fn push_stack_8(&mut self, byte: u8) {
|
pub fn push_stack_8(&mut self, byte: u8) {
|
||||||
let decremented_stack_pointer = self.stack_pointer.overflowing_sub(1);
|
let decremented_stack_pointer = self.stack_pointer.overflowing_sub(1);
|
||||||
self.stack_pointer = decremented_stack_pointer.0;
|
self.stack_pointer = decremented_stack_pointer.0;
|
||||||
self.bus.memory.write_8(self.stack_pointer, byte);
|
self.bus.memory.write_8(&self.onfault, self.stack_pointer, byte);
|
||||||
}
|
}
|
||||||
pub fn pop_stack_8(&mut self) -> u8 {
|
pub fn pop_stack_8(&mut self) -> u8 {
|
||||||
let byte = self.bus.memory.read_8(&self.onfault, self.stack_pointer);
|
let byte = self.bus.memory.read_8(&self.onfault, self.stack_pointer);
|
||||||
|
@ -179,7 +179,7 @@ impl Cpu {
|
||||||
pub fn push_stack_16(&mut self, half: u16) {
|
pub fn push_stack_16(&mut self, half: u16) {
|
||||||
let decremented_stack_pointer = self.stack_pointer.overflowing_sub(2);
|
let decremented_stack_pointer = self.stack_pointer.overflowing_sub(2);
|
||||||
self.stack_pointer = decremented_stack_pointer.0;
|
self.stack_pointer = decremented_stack_pointer.0;
|
||||||
self.bus.memory.write_16(self.stack_pointer, half);
|
self.bus.memory.write_16(&self.onfault, self.stack_pointer, half);
|
||||||
}
|
}
|
||||||
pub fn pop_stack_16(&mut self) -> u16 {
|
pub fn pop_stack_16(&mut self) -> u16 {
|
||||||
let half = self.bus.memory.read_16(&self.onfault, self.stack_pointer);
|
let half = self.bus.memory.read_16(&self.onfault, self.stack_pointer);
|
||||||
|
@ -190,7 +190,7 @@ impl Cpu {
|
||||||
pub fn push_stack_32(&mut self, word: u32) {
|
pub fn push_stack_32(&mut self, word: u32) {
|
||||||
let decremented_stack_pointer = self.stack_pointer.overflowing_sub(4);
|
let decremented_stack_pointer = self.stack_pointer.overflowing_sub(4);
|
||||||
self.stack_pointer = decremented_stack_pointer.0;
|
self.stack_pointer = decremented_stack_pointer.0;
|
||||||
self.bus.memory.write_32(self.stack_pointer, word);
|
self.bus.memory.write_32(&self.onfault, self.stack_pointer, word);
|
||||||
}
|
}
|
||||||
pub fn pop_stack_32(&mut self) -> u32 {
|
pub fn pop_stack_32(&mut self) -> u32 {
|
||||||
let word = self.bus.memory.read_32(&self.onfault, self.stack_pointer);
|
let word = self.bus.memory.read_32(&self.onfault, self.stack_pointer);
|
||||||
|
@ -345,7 +345,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(1);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(1);
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -452,7 +452,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(1);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(1);
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -460,7 +460,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(1);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(1);
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(1);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_add(1);
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(1);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_add(1);
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -490,7 +490,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(1);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_add(1);
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -543,7 +543,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -551,7 +551,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -559,7 +559,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -573,7 +573,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -581,7 +581,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -589,7 +589,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -642,7 +642,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(1);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(1);
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -650,7 +650,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(1);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(1);
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -658,7 +658,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(1);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(1);
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -672,7 +672,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(1);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_sub(1);
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -680,7 +680,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(1);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_sub(1);
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -688,7 +688,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(1);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_sub(1);
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -741,7 +741,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_mul(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_mul(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -749,7 +749,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_mul(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_mul(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_mul(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_mul(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -771,7 +771,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_mul(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_mul(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -779,7 +779,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_mul(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_mul(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -787,7 +787,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_mul(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_mul(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
self.flag.carry = result.1;
|
self.flag.carry = result.1;
|
||||||
}
|
}
|
||||||
|
@ -837,21 +837,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_div(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_div(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_div(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_div(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_div(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_div(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -864,21 +864,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_div(source_value as u8);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).overflowing_div(source_value as u8);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result.0);
|
self.bus.memory.write_8(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_div(source_value as u16);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).overflowing_div(source_value as u16);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result.0);
|
self.bus.memory.write_16(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_div(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).overflowing_div(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result.0);
|
self.bus.memory.write_32(&self.onfault, pointer, result.0);
|
||||||
self.flag.zero = result.0 == 0;
|
self.flag.zero = result.0 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -927,21 +927,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) % source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) % source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) % source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) % source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) % source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) % source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -954,21 +954,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) % source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) % source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) % source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) % source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) % source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) % source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1018,21 +1018,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) & source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) & source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) & source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) & source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) & source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) & source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1045,21 +1045,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) & source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) & source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) & source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) & source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) & source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) & source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1108,21 +1108,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) | source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) | source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) | source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) | source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) | source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) | source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1135,21 +1135,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) | source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) | source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) | source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) | source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) | source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) | source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1198,21 +1198,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) ^ source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) ^ source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) ^ source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) ^ source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) ^ source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) ^ source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1225,21 +1225,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) ^ source_value as u8;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) ^ source_value as u8;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) ^ source_value as u16;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) ^ source_value as u16;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) ^ source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) ^ source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1288,21 +1288,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result =!self.bus.memory.read_8(&self.onfault, pointer);
|
let result =!self.bus.memory.read_8(&self.onfault, pointer);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = !self.bus.memory.read_16(&self.onfault, pointer);
|
let result = !self.bus.memory.read_16(&self.onfault, pointer);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = !self.bus.memory.read_32(&self.onfault, pointer);
|
let result = !self.bus.memory.read_32(&self.onfault, pointer);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1315,21 +1315,21 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = !self.bus.memory.read_8(&self.onfault, pointer);
|
let result = !self.bus.memory.read_8(&self.onfault, pointer);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = !self.bus.memory.read_16(&self.onfault, pointer);
|
let result = !self.bus.memory.read_16(&self.onfault, pointer);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = !self.bus.memory.read_32(&self.onfault, pointer);
|
let result = !self.bus.memory.read_32(&self.onfault, pointer);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1381,7 +1381,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) << source_value;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) << source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 7) != 0;
|
self.flag.carry = source_value & (1 << 7) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1389,7 +1389,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) << source_value;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) << source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 15) != 0;
|
self.flag.carry = source_value & (1 << 15) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1397,7 +1397,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) << source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) << source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 31) != 0;
|
self.flag.carry = source_value & (1 << 31) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1411,7 +1411,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) << source_value;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) << source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 7) != 0;
|
self.flag.carry = source_value & (1 << 7) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1419,7 +1419,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) << source_value;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) << source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 15) != 0;
|
self.flag.carry = source_value & (1 << 15) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1427,7 +1427,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) << source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) << source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 31) != 0;
|
self.flag.carry = source_value & (1 << 31) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1480,7 +1480,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value as i32;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value as i32;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1488,7 +1488,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value as i32;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value as i32;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1496,7 +1496,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value as i32;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value as i32;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1510,7 +1510,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value as i32;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value as i32;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1518,7 +1518,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value as i32;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value as i32;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1526,7 +1526,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value as i32;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value as i32;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1579,7 +1579,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1587,7 +1587,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1595,7 +1595,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1609,7 +1609,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value;
|
let result = self.bus.memory.read_8(&self.onfault, pointer) >> source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1617,7 +1617,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value;
|
let result = self.bus.memory.read_16(&self.onfault, pointer) >> source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1625,7 +1625,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value;
|
let result = self.bus.memory.read_32(&self.onfault, pointer) >> source_value;
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1678,7 +1678,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_left(source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_left(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 7) != 0;
|
self.flag.carry = source_value & (1 << 7) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1686,7 +1686,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_left(source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_left(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 15) != 0;
|
self.flag.carry = source_value & (1 << 15) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1694,7 +1694,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_left(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_left(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 31) != 0;
|
self.flag.carry = source_value & (1 << 31) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1708,7 +1708,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_left(source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_left(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 7) != 0;
|
self.flag.carry = source_value & (1 << 7) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1716,7 +1716,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_left(source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_left(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 15) != 0;
|
self.flag.carry = source_value & (1 << 15) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1724,7 +1724,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_left(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_left(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 31) != 0;
|
self.flag.carry = source_value & (1 << 31) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1777,7 +1777,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_right(source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_right(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1785,7 +1785,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_right(source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_right(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1793,7 +1793,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_right(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_right(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1807,7 +1807,7 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_right(source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer).rotate_right(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1815,7 +1815,7 @@ impl Cpu {
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_right(source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer).rotate_right(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1823,7 +1823,7 @@ impl Cpu {
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_right(source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer).rotate_right(source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
self.flag.zero = result == 0;
|
self.flag.zero = result == 0;
|
||||||
self.flag.carry = source_value & (1 << 0) != 0;
|
self.flag.carry = source_value & (1 << 0) != 0;
|
||||||
}
|
}
|
||||||
|
@ -1871,19 +1871,19 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) | (1 << source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer) | (1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) | (1 << source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer) | (1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) | (1 << source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer) | (1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1895,19 +1895,19 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) | (1 << source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer) | (1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) | (1 << source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer) | (1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) | (1 << source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer) | (1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1952,19 +1952,19 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) & !(1 << source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer) & !(1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) & !(1 << source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer) & !(1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) & !(1 << source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer) & !(1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1976,19 +1976,19 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
let result = self.bus.memory.read_8(&self.onfault, pointer) & !(1 << source_value);
|
let result = self.bus.memory.read_8(&self.onfault, pointer) & !(1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, result);
|
self.bus.memory.write_8(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
let result = self.bus.memory.read_16(&self.onfault, pointer) & !(1 << source_value);
|
let result = self.bus.memory.read_16(&self.onfault, pointer) & !(1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, result);
|
self.bus.memory.write_16(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
let result = self.bus.memory.read_32(&self.onfault, pointer) & !(1 << source_value);
|
let result = self.bus.memory.read_32(&self.onfault, pointer) & !(1 << source_value);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, result);
|
self.bus.memory.write_32(&self.onfault, pointer, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2201,17 +2201,17 @@ impl Cpu {
|
||||||
match size {
|
match size {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, source_value as u8);
|
self.bus.memory.write_8(&self.onfault, pointer, source_value as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, source_value as u16);
|
self.bus.memory.write_16(&self.onfault, pointer, source_value as u16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, source_value);
|
self.bus.memory.write_32(&self.onfault, pointer, source_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2222,17 +2222,17 @@ impl Cpu {
|
||||||
match size {
|
match size {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_8(pointer, source_value as u8);
|
self.bus.memory.write_8(&self.onfault, pointer, source_value as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_16(pointer, source_value as u16);
|
self.bus.memory.write_16(&self.onfault, pointer, source_value as u16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, source_value);
|
self.bus.memory.write_32(&self.onfault, pointer, source_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2357,7 +2357,7 @@ impl Cpu {
|
||||||
let pointer = self.relative_to_absolute(self.read_register(register));
|
let pointer = self.relative_to_absolute(self.read_register(register));
|
||||||
if should_run {
|
if should_run {
|
||||||
// INFO: register contains a relative address instead of an absolute address
|
// INFO: register contains a relative address instead of an absolute address
|
||||||
self.bus.memory.write_32(pointer, self.relative_to_absolute(source_value));
|
self.bus.memory.write_32(&self.onfault, pointer, self.relative_to_absolute(source_value));
|
||||||
}
|
}
|
||||||
instruction_pointer_offset += 1; // increment past 8 bit register number
|
instruction_pointer_offset += 1; // increment past 8 bit register number
|
||||||
}
|
}
|
||||||
|
@ -2365,7 +2365,7 @@ impl Cpu {
|
||||||
let word = self.bus.memory.read_32(&self.onfault, self.instruction_pointer + instruction_pointer_offset);
|
let word = self.bus.memory.read_32(&self.onfault, self.instruction_pointer + instruction_pointer_offset);
|
||||||
let pointer = self.relative_to_absolute(word);
|
let pointer = self.relative_to_absolute(word);
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, self.relative_to_absolute(source_value));
|
self.bus.memory.write_32(&self.onfault, pointer, self.relative_to_absolute(source_value));
|
||||||
}
|
}
|
||||||
instruction_pointer_offset += 4; // increment past 32 bit pointer
|
instruction_pointer_offset += 4; // increment past 32 bit pointer
|
||||||
}
|
}
|
||||||
|
@ -2431,19 +2431,19 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_8();
|
let value = self.pop_stack_8();
|
||||||
self.bus.memory.write_8(pointer, value);
|
self.bus.memory.write_8(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_16();
|
let value = self.pop_stack_16();
|
||||||
self.bus.memory.write_16(pointer, value);
|
self.bus.memory.write_16(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_32();
|
let value = self.pop_stack_32();
|
||||||
self.bus.memory.write_32(pointer, value);
|
self.bus.memory.write_32(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2455,19 +2455,19 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_8();
|
let value = self.pop_stack_8();
|
||||||
self.bus.memory.write_8(pointer, value);
|
self.bus.memory.write_8(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_16();
|
let value = self.pop_stack_16();
|
||||||
self.bus.memory.write_16(pointer, value);
|
self.bus.memory.write_16(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_32();
|
let value = self.pop_stack_32();
|
||||||
self.bus.memory.write_32(pointer, value);
|
self.bus.memory.write_32(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2515,7 +2515,7 @@ impl Cpu {
|
||||||
let value = self.bus.read_io(source_value);
|
let value = self.bus.read_io(source_value);
|
||||||
instruction_pointer_offset += 1; // increment past 8 bit register number
|
instruction_pointer_offset += 1; // increment past 8 bit register number
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, value);
|
self.bus.memory.write_32(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Operand::ImmediatePtr(_) => {
|
Operand::ImmediatePtr(_) => {
|
||||||
|
@ -2523,7 +2523,7 @@ impl Cpu {
|
||||||
let value = self.bus.read_io(source_value);
|
let value = self.bus.read_io(source_value);
|
||||||
instruction_pointer_offset += 4; // increment past 32 bit pointer
|
instruction_pointer_offset += 4; // increment past 32 bit pointer
|
||||||
if should_run {
|
if should_run {
|
||||||
self.bus.memory.write_32(pointer, value);
|
self.bus.memory.write_32(&self.onfault, pointer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => panic!("Attempting to use an immediate value as a destination"),
|
_ => panic!("Attempting to use an immediate value as a destination"),
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -11,7 +11,7 @@ pub mod setjmp;
|
||||||
|
|
||||||
use audio::AudioChannel;
|
use audio::AudioChannel;
|
||||||
use bus::Bus;
|
use bus::Bus;
|
||||||
use cpu::{Cpu, Exception, Interrupt};
|
use cpu::{Cpu, Interrupt};
|
||||||
use keyboard::Keyboard;
|
use keyboard::Keyboard;
|
||||||
use mouse::Mouse;
|
use mouse::Mouse;
|
||||||
use disk::DiskController;
|
use disk::DiskController;
|
||||||
|
@ -86,9 +86,9 @@ fn main() {
|
||||||
let audio_channel_2 = Arc::new(Mutex::new(AudioChannel::new(2)));
|
let audio_channel_2 = Arc::new(Mutex::new(AudioChannel::new(2)));
|
||||||
let audio_channel_3 = Arc::new(Mutex::new(AudioChannel::new(3)));
|
let audio_channel_3 = Arc::new(Mutex::new(AudioChannel::new(3)));
|
||||||
|
|
||||||
let (exception_sender, exception_receiver) = mpsc::channel::<Exception>();
|
//let (exception_sender, exception_receiver) = mpsc::channel::<Exception>();
|
||||||
|
|
||||||
let memory = Memory::new(read_rom().as_slice(), exception_sender);
|
let memory = Memory::new(read_rom().as_slice());
|
||||||
let mut bus = Bus {
|
let mut bus = Bus {
|
||||||
memory: memory.clone(),
|
memory: memory.clone(),
|
||||||
audio_channel_0: audio_channel_0.clone(),
|
audio_channel_0: audio_channel_0.clone(),
|
||||||
|
@ -116,12 +116,12 @@ fn main() {
|
||||||
let ram_size = memory_cpu.ram().len();
|
let ram_size = memory_cpu.ram().len();
|
||||||
let ram_bottom_address = MEMORY_RAM_START;
|
let ram_bottom_address = MEMORY_RAM_START;
|
||||||
let ram_top_address = ram_bottom_address + ram_size - 1;
|
let ram_top_address = ram_bottom_address + ram_size - 1;
|
||||||
println!("RAM: {:.2} MiB mapped at {:#010X}-{:#010X}", ram_size / 1048576, ram_bottom_address, ram_top_address);
|
println!("RAM: {:.2} MiB mapped at physical {:#010X}-{:#010X}", ram_size / 1048576, ram_bottom_address, ram_top_address);
|
||||||
|
|
||||||
let rom_size = memory_cpu.rom().len();
|
let rom_size = memory_cpu.rom().len();
|
||||||
let rom_bottom_address = MEMORY_ROM_START;
|
let rom_bottom_address = MEMORY_ROM_START;
|
||||||
let rom_top_address = rom_bottom_address + rom_size - 1;
|
let rom_top_address = rom_bottom_address + rom_size - 1;
|
||||||
println!("ROM: {:.2} KiB mapped at {:#010X}-{:#010X}", rom_size / 1024, rom_bottom_address, rom_top_address);
|
println!("ROM: {:.2} KiB mapped at physical {:#010X}-{:#010X}", rom_size / 1024, rom_bottom_address, rom_top_address);
|
||||||
|
|
||||||
let mut cpu = Cpu::new(bus);
|
let mut cpu = Cpu::new(bus);
|
||||||
|
|
||||||
|
@ -163,9 +163,9 @@ fn main() {
|
||||||
cpu.interrupt(Interrupt::Exception(exception));
|
cpu.interrupt(Interrupt::Exception(exception));
|
||||||
}
|
}
|
||||||
while !cpu.halted {
|
while !cpu.halted {
|
||||||
if let Ok(exception) = exception_receiver.try_recv() {
|
/*if let Ok(exception) = exception_receiver.try_recv() {
|
||||||
cpu.interrupt(Interrupt::Exception(exception));
|
cpu.interrupt(Interrupt::Exception(exception));
|
||||||
}
|
}*/
|
||||||
if let Ok(interrupt) = interrupt_receiver.try_recv() {
|
if let Ok(interrupt) = interrupt_receiver.try_recv() {
|
||||||
cpu.interrupt(interrupt);
|
cpu.interrupt(interrupt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::setjmp::{JumpEnv, longjmp};
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
|
@ -33,11 +32,10 @@ struct MemoryInner {
|
||||||
mmu_enabled: Box<bool>,
|
mmu_enabled: Box<bool>,
|
||||||
tlb: Box<HashMap<u32, MemoryPage>>,
|
tlb: Box<HashMap<u32, MemoryPage>>,
|
||||||
paging_directory_address: Box<u32>,
|
paging_directory_address: Box<u32>,
|
||||||
exception_sender: Sender<Exception>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryInner {
|
impl MemoryInner {
|
||||||
pub fn new(rom: &[u8], exception_sender: Sender<Exception>) -> Self {
|
pub fn new(rom: &[u8]) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
// HACK: allocate directly on the heap to avoid a stack overflow
|
// HACK: allocate directly on the heap to avoid a stack overflow
|
||||||
// at runtime while trying to move around a 64MB array
|
// at runtime while trying to move around a 64MB array
|
||||||
|
@ -46,7 +44,6 @@ impl MemoryInner {
|
||||||
mmu_enabled: Box::from(false),
|
mmu_enabled: Box::from(false),
|
||||||
tlb: Box::from(HashMap::with_capacity(1024)),
|
tlb: Box::from(HashMap::with_capacity(1024)),
|
||||||
paging_directory_address: Box::from(0x00000000),
|
paging_directory_address: Box::from(0x00000000),
|
||||||
exception_sender,
|
|
||||||
};
|
};
|
||||||
this.rom.as_mut_slice().write(rom).expect("failed to copy ROM to memory");
|
this.rom.as_mut_slice().write(rom).expect("failed to copy ROM to memory");
|
||||||
this
|
this
|
||||||
|
@ -63,8 +60,8 @@ unsafe impl Send for Memory {}
|
||||||
unsafe impl Sync for Memory {}
|
unsafe impl Sync for Memory {}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
pub fn new(rom: &[u8], exception_sender: Sender<Exception>) -> Self {
|
pub fn new(rom: &[u8]) -> Self {
|
||||||
Self(Arc::new(UnsafeCell::new(MemoryInner::new(rom, exception_sender))))
|
Self(Arc::new(UnsafeCell::new(MemoryInner::new(rom))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inner(&self) -> &mut MemoryInner {
|
fn inner(&self) -> &mut MemoryInner {
|
||||||
|
@ -76,7 +73,6 @@ impl Memory {
|
||||||
pub fn mmu_enabled(&self) -> &mut bool { &mut self.inner().mmu_enabled }
|
pub fn mmu_enabled(&self) -> &mut bool { &mut self.inner().mmu_enabled }
|
||||||
pub fn tlb(&self) -> &mut HashMap<u32, MemoryPage> { &mut self.inner().tlb }
|
pub fn tlb(&self) -> &mut HashMap<u32, MemoryPage> { &mut self.inner().tlb }
|
||||||
pub fn paging_directory_address(&self) -> &mut u32 { &mut self.inner().paging_directory_address }
|
pub fn paging_directory_address(&self) -> &mut u32 { &mut self.inner().paging_directory_address }
|
||||||
pub fn exception_sender(&self) -> &mut Sender<Exception> { &mut self.inner().exception_sender }
|
|
||||||
|
|
||||||
pub fn dump(&self) {
|
pub fn dump(&self) {
|
||||||
let mut file = File::create("memory.dump").expect("failed to open memory dump file");
|
let mut file = File::create("memory.dump").expect("failed to open memory dump file");
|
||||||
|
@ -230,19 +226,15 @@ impl Memory {
|
||||||
(self.read_opt_8(address + 3).unwrap_or_else(|| unsafe { longjmp(onfault, Exception::PageFaultRead(address + 3)) }) as u32) << 24
|
(self.read_opt_8(address + 3).unwrap_or_else(|| unsafe { longjmp(onfault, Exception::PageFaultRead(address + 3)) }) as u32) << 24
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_8(&mut self, mut address: u32, byte: u8) {
|
pub fn write_8(&mut self, onfault: &JumpEnv<Exception>, mut address: u32, byte: u8) {
|
||||||
let original_address = address;
|
let original_address = address;
|
||||||
let mut writable = true;
|
let mut writable = true;
|
||||||
let mut ok = true;
|
|
||||||
if *self.mmu_enabled() {
|
if *self.mmu_enabled() {
|
||||||
(address, writable) = self.virtual_to_physical(address as u32).unwrap_or_else(|| {
|
(address, writable) = self.virtual_to_physical(address as u32).unwrap_or_else(|| {
|
||||||
self.exception_sender().send(Exception::PageFaultWrite(original_address)).unwrap();
|
unsafe { longjmp(onfault, Exception::PageFaultWrite(original_address)) }
|
||||||
ok = false;
|
|
||||||
(0, false)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok {
|
|
||||||
if writable {
|
if writable {
|
||||||
let address = address as usize;
|
let address = address as usize;
|
||||||
|
|
||||||
|
@ -255,22 +247,21 @@ impl Memory {
|
||||||
*value = byte;
|
*value = byte;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.exception_sender().send(Exception::PageFaultWrite(original_address)).unwrap();
|
unsafe { longjmp(onfault, Exception::PageFaultWrite(original_address)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.exception_sender().send(Exception::PageFaultWrite(original_address)).unwrap();
|
unsafe { longjmp(onfault, Exception::PageFaultWrite(original_address)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn write_16(&mut self, onfault: &JumpEnv<Exception>, address: u32, half: u16) {
|
||||||
|
self.write_8(onfault, address, (half & 0x00FF) as u8);
|
||||||
|
self.write_8(onfault, address + 1, (half >> 8) as u8);
|
||||||
}
|
}
|
||||||
pub fn write_16(&mut self, address: u32, half: u16) {
|
pub fn write_32(&mut self, onfault: &JumpEnv<Exception>, address: u32, word: u32) {
|
||||||
self.write_8(address, (half & 0x00FF) as u8);
|
self.write_8(onfault, address, (word & 0x000000FF) as u8);
|
||||||
self.write_8(address + 1, (half >> 8) as u8);
|
self.write_8(onfault, address + 1, ((word & 0x0000FF00) >> 8) as u8);
|
||||||
}
|
self.write_8(onfault, address + 2, ((word & 0x00FF0000) >> 16) as u8);
|
||||||
pub fn write_32(&mut self, address: u32, word: u32) {
|
self.write_8(onfault, address + 3, ((word & 0xFF000000) >> 24) as u8);
|
||||||
self.write_8(address, (word & 0x000000FF) as u8);
|
|
||||||
self.write_8(address + 1, ((word & 0x0000FF00) >> 8) as u8);
|
|
||||||
self.write_8(address + 2, ((word & 0x00FF0000) >> 16) as u8);
|
|
||||||
self.write_8(address + 3, ((word & 0xFF000000) >> 24) as u8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user