1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Bindings to perfect6502.

#![no_std]

include!("./bindings.rs");

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn reset_and_lda() {
        unsafe {
            let state = initAndResetChip();

            assert_eq!(readA(state), 0x00);

            // Write 0x3000 to the reset vector.
            memory[0xfffc] = 0x00;
            memory[0xfffd] = 0x30;

            // Write lda #$ef to 0x3000.
            memory[0x3000] = 0xa9;
            memory[0x3001] = 0xef;

            // Execute the 9-cycle reset sequence.
            for _ in 0..9 {
                step(state);
                step(state);
            }

            assert_eq!(readPC(state), 0x3000);

            // Execute lda #$ef.
            step(state);
            step(state);
            step(state);
            step(state);

            assert_eq!(readA(state), 0xef);

            destroyChip(state);
        }
    }
}