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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CartMC.hxx,v 1.8 2007/01/14 16:17:55 stephena Exp $
//============================================================================
;
;
;
/**
This is the cartridge class for Chris Wilkson's Megacart. It does not
handle battery-backed RAM at this time and the code could use some serious
speed improvements. It is based on the following Megacart specification:
Megacart Specification, Rev1.1
(c) 1997 Chris Wilkson
cwilkson@mit.edu
Description
-----------
The Megacart is an external memory cartridge for the Atari 2600 and compatible
home video game consoles. It plugs into the standard cartridge port, and
contains a total of 128K bytes of ROM storage and 32K bytes of battery-backed
RAM storage.
General Operation
-----------------
The Megacart uses "bank switching" to fit the 160K bytes of physical memory
into the console's available 4K address space. Physical memory is divided
into 64 RAM blocks of 512 bytes each, and 128 ROM blocks of 1K bytes each.
RAM blocks are numbered $00 through $3F, and ROM blocks are numbered $80
through $FF.
The console's address space is divided into 4 slots of 1K each. Any physical
memory block can be switched into any memory slot by writing its block number
to the "hot address" for the desired slot. Memory locations $3C through $3F
serve as "hot addresses" for memory slots 0 through 3, respectively.
Example:
To make ROM addresses $1A400-$1A7FF (block $E9) available to the console at
memory locations $F800-$FBFF (slot 2), write $E9 to memory location $3e.
Caution:
Note that these memory locations are write only. Trying to read the contents
of memory locations $3C through $3F will not only return invalid data, but
will also corrupt the contents causing the software to crash. Reading these
addresses should not be attempted.
Special Case - RAM
-------------------
RAM blocks differ from ROM blocks in that one of the console's address lines,
A9 in this case, must be used as a read/write select. Because of this, RAM
blocks are limited to 512 bytes each, yet still occupy an entire 1K slot.
To store a value A9 must be low. To retrieve a value A9 must high.
Example:
First, let's set slot 0 (console addresses $F000-$F3FF) to point to RAM
block $9 (RAM $1200-$13ff). To do this, write $9 to console address $3c.
To store the value $69 in RAM location $1234, write $69 to console address
$F034 (A9=0). To retrieve the value of RAM location $1234, read from console
address $F234 (A9=1).
Special Case - Powerup
-----------------------
Because the console's memory is randomized at powerup, there is no way to
predict the data initially contained in the "hot addresses". Therefore,
hardware will force slot 3 to always point to ROM block $FF immediately
after any read or write to the RESET vector at $FFFC-$FFFD. Block $FF
must contain code to initialize the 4 memory slots to point to the desired
physical memory blocks before any other code can be executed. After program
execution jumps out of the boot code, the hardware will release slot 3 and
it will function just like any other slot.
Example (the first column is the physical ROM address):
$00C00 JUNK ... ; random code and data
...
...
...
...
$1F400 START ... ; program starts here
... ; slot 3 now points to rom block $83
...
...
...
$1FFDD BOOT SEI ; disable interrupts
$1FFDE CLD ; set hexadecimal arithmetic mode
$1FFDF LDX #$FF ;
$1FFE1 TXS ; set stack pointer to $ff
$1FFE2 LDA #$00
$1FFE4 ZERO STA 00,X ; clear RIOT and TIA -BEFORE- setting
$1FFE6 DEX ; up banks
$1FFE7 BNE ZERO
$1FFE9 BANKS LDA #$00 ; ram block 0 ($0000-$01ff)
$1FFEB STA SLOT0 ; slot 0 points to ram block 0
$1FFED LDA #$34 ; ram block $34 ($6800-$69ff)
$1FFEF STA SLOT1 ; slot 1 points to ram block $34
$1FFF1 LDA #$FD ; rom block $fd ($1f400-$1f7ff)
$1FFF3 STA SLOT2 ; slot 2 points to rom block $fd
$1FFF5 LDA #$83 ; rom block $83 ($00C00-$01000)
$1FFF7 STA SLOT3 ; slot 3 points to bootcode
; (rom block $ff)
; until jumping out of slot 3
$1FFF9 JMP $F800 ; jump to slot 2
$1FFFC RESET .WORD $FFDD ; powerup reset vector
$1FFFE SWI .WORD $FFDD ; software interrupt vector (BRK)
@author Bradford W. Mott
@version $Id: CartMC.hxx,v 1.8 2007/01/14 16:17:55 stephena Exp $
*/
;