From 463d26375e281cfd57a36cc6e2350ae3a9f479e0 Mon Sep 17 00:00:00 2001 From: Madeline Cronin Date: Fri, 27 Sep 2024 16:26:24 +0100 Subject: [PATCH] Write tests for memory access instructions. --- src/processor.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/processor.rs b/src/processor.rs index e852cbf..62ad2d9 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -639,4 +639,51 @@ mod tests { if counter > 30 {panic!()}; } } + #[test] + fn mem_stack() { + let mut memory = [0x06F0, 17, 0x0600, 5, 0x0580, 0x0000, 0x0600, 3, 0x0580, 0x0000, 0x0500, 0x0800, 0x0500, 0x1000, 0, 0, 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], 3); + assert_eq!(processor.reg[2], 5); + } + #[test] + fn mem_main() { + let mut memory = [0x0600, 5, 0x0608, 10, 0x0590, 0x0040, 0x0510, 0x1040, 0, 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], 5); + } + #[test] + fn mem_disk() { + let mut memory = [0x0600, 5, 0x0608, 3, 0x06E8, 1, 0x05A0, 0x0040, 0x0520, 0x1040, 0x06E8, 0, 0x0520, 0x1840, 0, 0]; + let mut disk = [0;66000]; + let mut vram = [0]; + let mut processor = new(&mut memory, &mut disk, &mut vram); + loop { + if processor.run() {break}; + } + assert_eq!(processor.reg[2], 5); + assert_eq!(processor.reg[3], 0); + } + #[test] + fn mem_vram() { + let mut memory = [0x0600, 5, 0x0608, 10, 0x05B0, 0x0040, 0x0530, 0x1040, 0, 0, 0]; + let mut disk = [0]; + let mut vram = [0;30]; + let mut processor = new(&mut memory, &mut disk, &mut vram); + loop { + if processor.run() {break}; + } + assert_eq!(processor.reg[2], 5); + + } } -- 2.45.2