-
Notifications
You must be signed in to change notification settings - Fork 19
/
arm_preferences.go
141 lines (122 loc) · 3.89 KB
/
arm_preferences.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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 preferences
import (
"github.com/jetsetilly/gopher2600/prefs"
"github.com/jetsetilly/gopher2600/resources"
)
// Indicators that the ARM should put the MAM into the mode inidcated by the
// emulated driver for the cartridge mapper.
const MAMDriver = -1
type ARMPreferences struct {
dsk *prefs.Disk
// the specific model of ARM to use. this will affect things like memory
// addressing for cartridge formats that use the ARM.
//
// NOTE: this may be superceded in the future to allow for more flexibility
Model prefs.String
// speed of processor
Clock prefs.Float // Mhz
// regulator of cycle counting for the ARM. this value is multiplied with
// the number of cycles used by each instruction. therefore a value of 1.0
// is a neutral regulator
CycleRegulator prefs.Float
// whether the ARM coprocessor (as found in Harmony cartridges) executes
// instantly
Immediate prefs.Bool
// a value of MAMDriver says to use the driver supplied MAM value. any
// other value "forces" the MAM setting on Thumb program execution.
MAM prefs.Int
// abort execution on memory fault (eg. accessing memory that doesn't exist)
AbortOnMemoryFault prefs.Bool
// treat misaligned accesses as a memory fault. (ie. will be reported as a
// memory fault and will cause execution to abort if AbortOnMemoryFault is
// true)
MisalignedAccessIsFault prefs.Bool
// include disassembly and register details when logging memory faults
ExtendedMemoryFaultLogging prefs.Bool
}
func (p *ARMPreferences) String() string {
return p.dsk.String()
}
func newARMprefrences() (*ARMPreferences, error) {
p := &ARMPreferences{}
p.SetDefaults()
pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
p.dsk, err = prefs.NewDisk(pth)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.model", &p.Model)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.clock", &p.Clock)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.cycleRegulator", &p.CycleRegulator)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.immediate", &p.Immediate)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.mam", &p.MAM)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.abortOnMemoryFault", &p.AbortOnMemoryFault)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.MisalignedAccessIsFault", &p.MisalignedAccessIsFault)
if err != nil {
return nil, err
}
err = p.dsk.Add("hardware.arm7.extendedMemoryFaultLogging", &p.ExtendedMemoryFaultLogging)
if err != nil {
return nil, err
}
err = p.dsk.Load(true)
if err != nil {
return nil, err
}
return p, nil
}
// SetDefaults reverts all settings to default values.
func (p *ARMPreferences) SetDefaults() {
// initialise random number generator
p.Model.Set("AUTO")
p.Clock.Set(70.0)
p.CycleRegulator.Set(1.0)
p.Immediate.Set(false)
p.MAM.Set(-1)
p.AbortOnMemoryFault.Set(false)
p.MisalignedAccessIsFault.Set(false)
p.ExtendedMemoryFaultLogging.Set(false)
}
// Load current arm preference from disk.
func (p *ARMPreferences) Load() error {
return p.dsk.Load(false)
}
// Save current arm preferences to disk.
func (p *ARMPreferences) Save() error {
return p.dsk.Save()
}