@@ 329,10 329,10 @@ mod tests {
#[test]
fn immediate() {
- let memory: &mut [u16] = &mut [0x0600, 45, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 45, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 340,10 340,10 @@ mod tests {
}
#[test]
fn conditional() {
- let memory: &mut [u16] = &mut [0x0600, 17, 0xF600, 69, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 17, 0xF600, 69, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 352,10 352,10 @@ mod tests {
#[test]
fn add() {
- let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 4, 0x0100, 0x0044, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 3, 0x0608, 4, 0x0100, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 363,10 363,10 @@ mod tests {
}
#[test]
fn overflow () {
- let memory: &mut [u16] = &mut [0x0600, u16::MAX, 0x0608, 5, 0x0140, 0x0044, 0xA618, 5, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, u16::MAX, 0x0608, 5, 0x0140, 0x0044, 0xA618, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 375,10 375,10 @@ mod tests {
}
#[test]
fn signed_overflow () {
- let memory: &mut [u16] = &mut [0x0600, i16::MAX as u16, 0x0608, 5, 0x01E0, 0x0044, 0x5618, 5, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, i16::MAX as u16, 0x0608, 5, 0x01E0, 0x0044, 0x5618, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 387,10 387,10 @@ mod tests {
}
#[test]
fn arithmetic_invert () {
- let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 4, 0x0110, 0x0044, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 3, 0x0608, 4, 0x0110, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 398,10 398,10 @@ mod tests {
}
#[test]
fn sub () {
- let memory: &mut [u16] = &mut [0x0600, 5, 0x0608, 3, 0x0101, 0x0044, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 5, 0x0608, 3, 0x0101, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 409,10 409,10 @@ mod tests {
}
#[test]
fn underflow () {
- let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 5, 0x0141, 0x0044, 0xA618, 7, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 3, 0x0608, 5, 0x0141, 0x0044, 0xA618, 7, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 421,10 421,10 @@ mod tests {
}
#[test]
fn signed_underflow () {
- let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 5, 0x01C1, 0x0044, 0x0600, i16::MIN as u16, 0x01E1, 0x0046, 0xD620, 7, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 3, 0x0608, 5, 0x01C1, 0x0044, 0x0600, i16::MIN as u16, 0x01E1, 0x0046, 0xD620, 7, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 434,10 434,10 @@ mod tests {
}
#[test]
fn mult () {
- let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 5, 0x0102, 0x0044, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 3, 0x0608, 5, 0x0102, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 445,10 445,10 @@ mod tests {
}
#[test]
fn mult_overflow () {
- let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, u16::MAX, 0x0142, 0x0044, 0xA618, 5, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 3, 0x0608, u16::MAX, 0x0142, 0x0044, 0xA618, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 457,10 457,10 @@ mod tests {
}
#[test]
fn mult_signed_overflow () {
- let memory: &mut [u16] = &mut [0x0600, 2, 0x0608, i16::MAX as u16, 0x01C2, 0x0044, 0xA618, 5, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 2, 0x0608, i16::MAX as u16, 0x01C2, 0x0044, 0xA618, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 469,10 469,10 @@ mod tests {
}
#[test]
fn div () {
- let memory: &mut [u16] = &mut [0x0600, 7, 0x0608, 3, 0x0103, 0x0044, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 7, 0x0608, 3, 0x0103, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 480,10 480,10 @@ mod tests {
}
#[test]
fn signed_div () {
- let memory: &mut [u16] = &mut [0x0600, 13, 0x0608, -4i16 as u16, 0x0183, 0x0044, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 13, 0x0608, -4i16 as u16, 0x0183, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
@@ 491,14 491,70 @@ mod tests {
}
#[test]
fn div_by_0 () {
- let memory: &mut [u16] = &mut [0x0600, 5, 0x0143, 0x0044, 0xA618, 5, 0, 0];
- let disk: &mut [u16] = &mut [0];
- let vram: &mut [u16] = &mut [0];
- let mut processor = new(memory, disk, vram);
+ let mut memory = [0x0600, 5, 0x0143, 0x0044, 0xA618, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
loop {
if processor.run() {break};
}
assert_eq!(processor.reg[2], 0);
assert_eq!(processor.reg[3], 5);
}
+ #[test]
+ fn logic_and () {
+ let mut memory = [0x0600, 0b11010, 0x0608, 0b10110, 0x0200, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
+ loop {
+ if processor.run() {break};
+ }
+ assert_eq!(processor.reg[2], 0b10010);
+ }
+ #[test]
+ fn logic_or () {
+ let mut memory = [0x0600, 0b10010, 0x0608, 0b11000, 0x0201, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
+ loop {
+ if processor.run() {break};
+ }
+ assert_eq!(processor.reg[2], 0b11010);
+ }
+ #[test]
+ fn logic_xor () {
+ let mut memory = [0x0600, 0b01101, 0x0608, 0b01011, 0x0202, 0x0044, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
+ loop {
+ if processor.run() {break};
+ }
+ assert_eq!(processor.reg[2], 0b00110);
+ }
+ #[test]
+ fn logic_zero() {
+ let mut memory = [0x0600, 5, 0x02A0, 0x0000, 0x02C0, 0x1112, 0xF608, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
+ loop {
+ if processor.run() {break};
+ }
+ assert_eq!(processor.reg[1], 5);
+ }
+ #[test]
+ fn logic_invert() {
+ let mut memory = [0x02B0, 0x0002, 0xA610, 5, 0, 0];
+ let mut disk = [0];
+ let mut vram = [0];
+ let mut processor = new(&mut memory, &mut disk, &mut vram);
+ loop {
+ if processor.run() {break};
+ }
+ assert_eq!(processor.reg[1], u16::MAX);
+ assert_eq!(processor.reg[2], 5);
+ }
}