-
Notifications
You must be signed in to change notification settings - Fork 20
/
state.go
78 lines (63 loc) · 2.08 KB
/
state.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
72
73
74
75
76
77
78
// This file is part of Gopher2600.
//
// Gopher2600 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Gopher2600 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
package dpcplus
import (
"github.com/jetsetilly/gopher2600/hardware/memory/cartridge/arm7tdmi/callfn"
"github.com/jetsetilly/gopher2600/random"
)
type State struct {
registers Registers
// currently selected bank
bank int
// was the last instruction read the opcode for "lda <immediate>"
lda bool
// music fetchers are clocked at a fixed (slower) rate than the reference
// to the VCS's clock. see Step() function.
beats int
// parameters for next function call
parameters []uint8
// static area of the cartridge. accessible outside of the cartridge
// through GetStatic() and PutStatic()
static *Static
// the callfn process is stateful
callfn callfn.CallFn
// the MAM mode to use when called arm7tdmi.Run(). Run() returns the value
// the thumb code leaves it in so this can carry over between program
// executions
mamcr uint32
}
func newDPCPlusState() *State {
s := &State{}
s.parameters = make([]uint8, 0, 32)
return s
}
// the ideal MAMCR value given to the arm7tdmi.Run() command.
const dpcPlusMAMCR = 2
func (s *State) initialise(rand *random.Random, bank int) {
s.registers.reset(rand)
s.bank = bank
s.lda = false
s.beats = 0
s.parameters = []uint8{}
// on reset the DPC+ driver is in mode 2
s.mamcr = dpcPlusMAMCR
}
func (s *State) Snapshot() *State {
n := *s
n.static = s.static.Snapshot()
n.parameters = make([]uint8, len(s.parameters))
copy(n.parameters, s.parameters)
return &n
}