summary refs log tree commit diff
path: root/instructions/INC.ts
blob: 971abd3b464576b47639c6c374e653906a8e7349 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// deno-lint-ignore-file no-case-declarations
import type The65c02 from "../65c02.ts";

export default function (this: The65c02, mode: string) {
    switch (mode) {
        case 'zero-page':
            // set PC to where the ZP address is
            this.programCounter.increment()
            const zpa = this.readPC()
            this.io.address.set(zpa.num());
            this.read();
            let v = this.io.data.num();
            v++
            v &= 0xFF
            this.io.data.set(v)
            this.write()
            this.flagZN(v)
            this.programCounter.increment()
            break;
        
        case 'zero-page, X-indexed':
            // set PC to where the ZP address is
            this.programCounter.increment()
            const zpax = this.readPC()
            this.io.address.set(zpax.num() + this.regX.num());
            this.read();
            let vzx = this.io.data.num();
            vzx++
            vzx &= 0xFF
            this.io.data.set(vzx)
            this.write()
            this.flagZN(vzx)
            this.programCounter.increment()
            break;
        
        case 'absolute':
            // skip over the opcode
            this.programCounter.increment()
            const lo_abit = this.readPC().num()
            this.programCounter.increment()
            const hi_abit = this.readPC().num()
            this.io.address.set((hi_abit << 8) | lo_abit)
            this.read()
            let va = this.io.data.num();
            va++
            va &= 0xFF
            this.io.data.set(va)
            this.write()
            this.programCounter.increment()
            break;
        
        case 'absolute, X-indexed':
            // skip over the opcode
            this.programCounter.increment()
            const lo_axbit = this.readPC().num()
            this.programCounter.increment()
            const hi_axbit = this.readPC().num()
            this.io.address.set(((hi_axbit << 8) | lo_axbit) + this.regX.num())
            this.read()
            let vax = this.io.data.num();
            vax++
            vax &= 0xFF
            this.io.data.set(vax)
            this.write()
            this.programCounter.increment()
            break;
    
        default:
            throw 'wha';
    }
}