-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcardBrainBoard.go
159 lines (128 loc) · 4 KB
/
cardBrainBoard.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package izapple2
import "fmt"
/*
Brain board card for Apple II
See:
http://www.willegal.net/appleii/brainboard.htm
http://www.willegal.net/appleii/bb-v5_3.1.pdf
The Brain Board card has 2 banks of ROM to replace the main ROM
A 27c256 ROM (32k) is used, with the following mapping:
0x0000-0x00ff: lower card rom maps to $Csxx
0x1000-0x37ff: lower bank rom maps to $D000 to $F7FF
0x3800-0x3fff: F8 lower bank rom maps to $F800 to $FFFF
0x4000-0x40ff: upper card rom maps to $Csxx
0x5000-0x77ff: upper bank rom maps to $D000 to $F7FF
0x7800-0x7fff: F8 upper bank rom maps to $F800 to $FFFF
DIP SWitches_
1-ON : The range F8 can be replaced
1-OFF: The range F8 is not replaced
3-ON ,4-OFF: The motherboard ROM can be used
3-OFF,4-ON : The motherboard ROM is always replaced
5-ON ,6-OFF: The lower bank is used and mapped to Bank A
5-OFF,6-ON : The lower bank is not used (A can be motherboards or uppers)
7-ON ,8-OFF: The upper bank is used and mapper to bank B
7-OFF,8-ON : The upper bank is not used (B can be motherboards or lowers)
Switches and softswitches:
Up, $COsO - SS clear: A bank selected
Down, $COs1 - SS set: B bank selected
*/
// CardBrainBoard represents a Brain Board card
type CardBrainBoard struct {
cardBase
isBankB bool
isMotherboardRomEnabled bool
dip1_replaceF8 bool
dip34_useMotherboardRom bool
dip56_lowerInA bool
dip78_upperInB bool
rom []uint8
}
func newCardBrainBoardBuilder() *cardBuilder {
return &cardBuilder{
name: "Brain Board",
description: "Firmware card. It has two ROM banks",
defaultParams: &[]paramSpec{
{"rom", "ROM file to load", "<internal>/wozaniam_integer.rom"},
{"dips", "DIP switches, leftmost is DIP 1", "1-011010"},
{"switch", "Bank selected at boot, 'up' or 'down'", "up"},
},
buildFunc: func(params map[string]string) (Card, error) {
var c CardBrainBoard
var err error
bank := paramsGetString(params, "switch")
if bank == "up" {
c.isBankB = false
} else if bank == "down" {
c.isBankB = true
} else {
return nil, fmt.Errorf("invalid bank '%s', must be up or down", bank)
}
dips, err := paramsGetDIPs(params, "dips", 8)
if err != nil {
return nil, err
}
c.dip1_replaceF8 = dips[1]
if dips[3] == dips[4] {
return nil, fmt.Errorf("DIP switches 3 and 4 must be different")
}
if dips[5] == dips[6] {
return nil, fmt.Errorf("DIP switches 5 and 6 must be different")
}
if dips[7] == dips[8] {
return nil, fmt.Errorf("DIP switches 7 and 8 must be different")
}
c.dip34_useMotherboardRom = dips[3]
c.dip56_lowerInA = dips[5]
c.dip78_upperInB = dips[7]
romFile := paramsGetPath(params, "rom")
data, _, err := LoadResource(romFile)
if err != nil {
return nil, err
}
if len(data) != 0x8000 {
return nil, fmt.Errorf("the ROM file for the Brainboard must be 32k")
}
c.isMotherboardRomEnabled = true
c.rom = data
c.romCxxx = &c
return &c, nil
},
}
}
func (c *CardBrainBoard) updateState() {
isMotherboardRomEnabled := c.dip34_useMotherboardRom &&
((!c.dip56_lowerInA && !c.isBankB) || (!c.dip78_upperInB && c.isBankB))
if isMotherboardRomEnabled && !c.isMotherboardRomEnabled {
c.a.mmu.inhibitROM(nil)
} else if !isMotherboardRomEnabled && c.isMotherboardRomEnabled {
c.a.mmu.inhibitROM(c)
}
c.isMotherboardRomEnabled = isMotherboardRomEnabled
}
func (c *CardBrainBoard) assign(a *Apple2, slot int) {
c.addCardSoftSwitchRW(0, func() uint8 {
c.isBankB = false
c.updateState()
return 0x55
}, "BRAINCLEAR")
c.addCardSoftSwitchRW(1, func() uint8 {
c.isBankB = true
c.updateState()
return 0x55
}, "BRAINSET")
c.cardBase.assign(a, slot)
c.updateState()
}
func (c *CardBrainBoard) translateAddress(address uint16) uint16 {
if c.isBankB {
return address - 0xc000 + 0x4000
} else {
return address - 0xc000
}
}
func (c *CardBrainBoard) peek(address uint16) uint8 {
return c.rom[c.translateAddress(address)]
}
func (c *CardBrainBoard) poke(address uint16, value uint8) {
// Nothing
}