-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu6502.go
71 lines (57 loc) · 1011 Bytes
/
cpu6502.go
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
package main
import "fmt"
type cpu6502 struct {
a byte
x byte
y byte
pc byte
sp byte
mem [1 * 1024]byte
}
func newCPU6502() *cpu6502 {
cpu := cpu6502{}
return &cpu
}
func (cpu cpu6502) String() string {
return fmt.Sprintf("A: %x X: %x Y: %x PC: %x SP: %x MEM: %x", cpu.a, cpu.x, cpu.y, cpu.pc, cpu.sp, cpu.mem)
}
func (cpu *cpu6502) sta(value byte) error {
cpu.mem[value] = cpu.a
return nil
}
func (cpu *cpu6502) lda(value byte) error {
cpu.a = value
return nil
}
func (cpu *cpu6502) ldx(value byte) error {
cpu.x = value
return nil
}
func (cpu *cpu6502) ldy(value byte) error {
cpu.y = value
return nil
}
func (cpu *cpu6502) inx() error {
cpu.x++
return nil
}
func (cpu *cpu6502) iny() error {
cpu.y++
return nil
}
func (cpu *cpu6502) txa() error {
cpu.a = cpu.x
return nil
}
func (cpu *cpu6502) tax() error {
cpu.x = cpu.a
return nil
}
func (cpu *cpu6502) tya() error {
cpu.a = cpu.y
return nil
}
func (cpu *cpu6502) tay() error {
cpu.y = cpu.a
return nil
}