Skip to content

Commit b0c42f0

Browse files
authored
MBC6: Fix Flash Write Enable description (#573)
* The Flash Write Enable bit doesn't influence the /WE signal of the flash. It directly controls the /WP (/write protect; pin 12) signal. * It is not true that the Flash Enable register can only be changed when the Flash Write Enable register is set to 1. Both registers are in fact independent of each other. * The Flash Write Enable register does not protect the whole flash from being erased and programmed. It only protects sector 0 and the hidden 256 byte region. Sectors 1 to 7 can always be modified. * The status bytes are not exactly $80 or $10. Only a few of the bits are driven by the flash when reading status bytes. The undriven bits are random.
1 parent 9bd5bdb commit b0c42f0

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/MBC6.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,20 @@ Select the active RAM Bank B (B000-BFFF)
5555
### 0C00-0FFF — Flash Enable (Write Only)
5656

5757
Enable or disable access to the flash chip. Only the lowest bit (0 for
58-
disable, 1 for enable) is used. Flash Write Enable must be active to
59-
change this.
58+
disable, 1 for enable) is used. If disabled, then the /CE (chip enable)
59+
signal from the MBC6 chip to the flash will stay disabled.
6060

6161
### 1000 — Flash Write Enable (Write Only)
6262

63-
Enable or disable write mode for the flash chip. Only the lowest bit (0
64-
for disable, 1 for enable) is used. Note that this maps to the /WE pin
65-
on the flash chip, not whether writing to the bus is enabled;
66-
some flash commands (e.g. JEDEC ID query) still work with this off so
67-
long as Flash Enable is on.
63+
Enable or disable write mode for flash sector 0 and the hidden region.
64+
Only the lowest bit (0 for disable, 1 for enable) is used. Note that
65+
this maps to the /WP pin (write protect) on the flash chip, not whether
66+
writing to the bus is enabled; most flash commands still work with this
67+
off so long as Flash Enable is on (see table below). If this register
68+
is set to 0 (disabled), which is the default value after power up, then
69+
neither flash sector 0 nor the hidden flash region can be erased or
70+
programmed. Flash sectors 1 to 7 are not affected by this and can
71+
always be erased and programmed as long as Flash Enable is on.
6872

6973
### 2000-27FF — ROM/Flash Bank A Number (Write Only)
7074

@@ -98,23 +102,26 @@ either 4 or 6 and Y to 5 or 7, depending on the bank region:
98102

99103
```
100104
------------- ------------- ------------- ------------- ------------- ------------- ---------------------------------------------------
101-
2:Y555=$AA 1:XAAA=$55 2:Y555=$80 2:Y555=$AA 1:XAAA=$55 ?:????=$30 Erase sector* (set 128 KiB region to $FFs)
102-
2:Y555=$AA 1:XAAA=$55 2:Y555=$80 2:Y555=$AA 1:XAAA=$55 2:Y555=$10 Erase chip* (set entire 1 MiB to $FFs)
105+
2:Y555=$AA 1:XAAA=$55 2:Y555=$80 2:Y555=$AA 1:XAAA=$55 ?:????=$30 Erase sector (set 128 KiB region to $FFs)
106+
2:Y555=$AA 1:XAAA=$55 2:Y555=$80 2:Y555=$AA 1:XAAA=$55 2:Y555=$10 Erase chip (set entire 1 MiB to $FFs)
103107
2:Y555=$AA 1:XAAA=$55 2:Y555=$60 2:Y555=$AA 1:XAAA=$55 2:Y555=$04 Erase hidden region* (set hidden 256 bytes to $FFs)
104108
2:Y555=$AA 1:XAAA=$55 2:Y555=$90 ID mode (reads out JEDEC ID (C2,81) at $XXX0,$XXX1)
105109
2:Y555=$AA 1:XAAA=$55 2:Y555=$77 2:Y555=$AA 1:XAAA=$55 2:Y555=$77 Read hidden region
106-
2:Y555=$AA 1:XAAA=$55 2:Y555=$A0 Program mode*
110+
2:Y555=$AA 1:XAAA=$55 2:Y555=$A0 Program mode
107111
2:Y555=$AA 1:XAAA=$55 2:Y555=$60 2:Y555=$AA 1:XAAA=$55 2:Y555=$E0 Program mode for hidden region*
108112
2:Y555=$AA 1:XAAA=$55 2:Y555=$60 2:Y555=$AA 1:XAAA=$55 2:Y555=$40 Unprotect sector 0*
109113
2:Y555=$AA 1:XAAA=$55 2:Y555=$60 2:Y555=$AA 1:XAAA=$55 2:Y555=$20 Protect sector 0*
110114
?:????=$F0 Exit any of the commands above
111115
------------- ------------- ------------- ------------- ------------- ------------- ---------------------------------------------------
112116
```
113117

114-
Commands marked with \* require the Write Enable bit to be 1. These will
115-
make the flash read out status bytes instead of values. A status of $80
116-
means the operation has finished and you should exit the mode using the
117-
$F0 command. A status of $10 indicates a timeout.
118+
Commands marked with \* require the Flash Write Enable bit to be 1. The
119+
erase, program and (un-)protect flash commands will make the flash read
120+
out status bytes instead of values. If status bit 7 is set (mask $80) the
121+
operation has finished and you should exit the mode using the $F0
122+
command. Status bit 4 (mask $10) indicates a timeout. Status bit 1 (mask
123+
$02) is set when the sector 0 protection was enabled by the Protect Sector
124+
0 command.
118125

119126
Programming must be done by first erasing a sector, activating program
120127
mode, writing out 128 bytes (aligned), then writing any value (except
@@ -149,11 +156,18 @@ are not relevant.
149156

150157
The erase chip command erases the whole 1 MiB flash. The 256 byte hidden
151158
region is **not** erased by the erase chip command. If sector 0 is
152-
protected, only sectors 1 to 7 are erased.
159+
protected, either by the Flash Write Enable bit in MBC6 register 0x1000
160+
or by the Protect Sector 0 flash command (or both), only sectors 1 to 7
161+
are erased.
153162

154163
Sector 0 (the first 128 KiB of the flash) can be protected from erasure
155-
and programming, using the protect/unprotect sector 0 commands. The state
156-
of the protection is stored non-volatile.
164+
and programming, using the Protect/Unprotect Sector 0 flash commands.
165+
The state of the protection is stored non-volatile. This acts as a second
166+
layer of protection in addition to the Flash Write Enable bit. The Flash
167+
Write Enable bit protects both, sector 0 and the hidden region. The
168+
Protect Sector 0 command only protects sector 0. If you want to make sure
169+
that you can erase and program sector 0, you first have to set the Flash
170+
Write Enable bit to 1, then issue the Unprotect Sector 0 flash command.
157171

158172
## External links
159173

0 commit comments

Comments
 (0)