-
Notifications
You must be signed in to change notification settings - Fork 1
/
mega65-mm.scm
279 lines (239 loc) · 12.2 KB
/
mega65-mm.scm
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
;;; Memory layout breakdown:
;;; / +---------------------------+
;;; | | main_private code |
;;; | | (0xd000) |
;;; | +------+---------------------------+
;;; | | screen ram | gfx2 code |
;;; mapped | | (0x10000) | (0x11800) |
;;; | +-------------+-------+------------+
;;; | | diskio code | diskio bss |
;;; | | (0x12000) | (0x13a00) |
;;; | +---------------------+------------+
;;; | | gfx code | gfx bss |
;;; \ | (0x14000) | (0x15800) |
;;; | +-----------------+----------------+ +---------------------------------+
;;; | | sound code | | resource (room, script, ...) |
;;; \ | (0x16000) | | (64 pages from 0x18000-0x27fff) |
;;; / +-----------+--------+-------+---------+----------------------------------+-------------+------------+-------------+------+------+--------------+--------------+-------+------------+--------+--------+--------+-------+-------+-------+-------+----------------+-------------------+---------------+ +-------------------+-------------------+
;;; physical | | registers | zzpage | CPU | runtime | script | main | heap | backbuffer | backbuffer | main_private | data_sound | soft | screen ram | gfx2 | diskio | diskio | gfx | gfx | sound | sound | resource heap | gfx/char memory | music memory | | color ram | gfx |
;;; placement | | | | stack | | parser code | code | (strings, | screen ram | color ram | code | cdata_main | stack | | code | code | bss | code | bss | code | bss | 256 pages | (room, objects, | | | | helpscreen |
;;; | | | | | | (M01) | (M02) | inventory) | | | (M03) | zdata | | | (M10) | | | (M12) | | | | each 256 bytes | actors) | | | | |
;;; \ +-----------+--------+-------+---------+------+------+---+---+------------+-------------+------------+-------------+------+------+--------------+--------------+-------+------------+--------+--------+--------+-------+-------+-------+-------+----------------+-------------------+---------------+ ... +-------------------+-------------------+
;;; 0x0000 0x0080 0x0100 0x0200 0x2000 0x3000 0x3800 0x3a00 0x4000 0x8000 0xa000 0xb800 0xc000 0xd000 0xe000 0xf800 0x10000 0x11800 0x12000 0x13a80 0x14000 0x15900 0x16000 0x17800 0x18000 0x28000 0x53800 0x5ffff 0xff80800 0xff82000 0xff83fff
;;; 0x3900 | 8 kb | 6 kb | 6 kb | 4 kb | 6 kb | 2 kb | 6 kb | 2 kb | 6.5 kb | ~1.5 kb| 6 kb | ~2 kb | 6 kb | 2 kb | 64 kb | 174 kb | 50 kb | | 6 kb | 8 kb |
;;; |<---- Code Segment (CS) ---->| |<--- Data Segment (DS) ---->|
;;; | (0x2000 - 0x3fff) | | (0x8000 - 0xbfff) |
;;; | 8kb | 8 kb | 16 kb | 16 kb |
(define memories
'(
;;;; ***********************
;;;; MEMORY LAYOUT OF BANK 0
;;;; ***********************
(block stack (size #x0100))
(block cstack (size #x07fa))
(block heap (size #x2000))
(memory zeropage (address (#x2 . #xff)) (qualifier zpage)
(section (registers (#x2. #x7f)))
(section zzpage)
)
(memory stackpage (address (#x100 . #x1ff))
(section stack)
)
; Memory m0-0 for the runtime module
; The runtime code will be moved to 0x200 in startup
(memory runtime (address (#x208 . #x1fff))
(scatter-to runtime_copy)
(section
code
data
switch
cdata
)
)
; memory for boot program (autoboot.c65)
; contains copies of m00 (runtime) and m11 (diskio) and will relocate them to their final memory locations
(memory autoboot (address (#x1fff . #x7a7f))
(section
(autoboot_load_address #x1fff)
(programStart #x2001)
(startup #x200e)
data_init_table
(runtime_copy #x2200)
(init_copy #x4000)
(diskio_copy #x6000)
)
)
; memory for init program (will be discarded once executed)
(memory init (address (#x4000 . #x5fff))
; we use scatter-to but not to relocate to another memory location
; but just to group those three sections together in one block
(scatter-to init_copy)
(section
code_init
cdata_init
data_init
)
)
; temporary memory for init program (will be discarded when init is done)
(memory bssram-init (address (#x6000 . #x7fff))
(section
bss_init
)
)
; memory m0-1 for script module
(memory script (address (#x2000 . #x3fff))
(section
code_script
cdata_script
data_script
)
)
; memory m0-2 for main program (loaded after init is done)
(memory main (address (#x4000 . #x7fff))
(section
code_main
data_main
)
)
; memory for heap, bss, and soft stack in bank 0
(memory bssram-main (address (#x8000 . #xfff9))
(section
(heap (#x8000 . #x9fff))
(backbuffer-screen (#xa000 . #xb7ff))
(backbuffer-color (#xb800 . #xbfff))
(zdata (#xe380 . #xf7ff))
(cstack (#xf800 . #xfff9))
)
)
;;;; *************************************
;;;; MEMORY DEFINITIONS FOR BANKED MODULES
;;;; *************************************
;;;; **** BANKED MEMORY code_main_private ****
; memory in bank 0 for mapping private vm code
(memory main_private (address (#x3000 . #x3fff))
(scatter-to bank0_d000)
(section
code_main_private
cdata_main_private
data_main_private
)
)
;;;; **** BANKED MEMORY gfx2 ****
; memory in bank 0 for mapping screenram
(memory banked-bss-0 (address (#x2000 . #x37ff))
(scatter-to bank1_0000)
(section
bss_screenram
)
)
; memory in bank 0 for mapping additional gfx module (gfx2)
(memory banked-code-0 (address (#x3800 . #x3fff))
(scatter-to bank1_1800)
(section
code_gfx2
cdata_gfx2
data_gfx2
)
)
;;;; **** BANKED MEMORY diskio ****
; memory in bank 0 for mapping diskio module
(memory banked-code-1 (address (#x2000 . #x3a7f))
(scatter-to diskio_copy)
(section
code_diskio
cdata_diskio
data_diskio
)
)
; memory in bank 0 for mapping diskio bss section
(memory banked-bss-1 (address (#x3a80 . #x3fff))
(scatter-to bank1_3a80)
(section
bss_diskio
)
)
;;;; **** BANKED MEMORY gfx ****
; memory in bank 0 for mapping gfx module
(memory banked-code-2 (address (#x2000 . #x38ff))
(scatter-to bank1_4000)
(section
code_gfx
cdata_gfx
data_gfx
)
)
; memory in bank 0 for mapping gfx bss section
(memory banked-bss-2 (address (#x3900 . #x3fff))
(scatter-to bank1_5900)
(section
bss_gfx
)
)
; memory in colram for mapping gfx helpscreen module
(memory banked-code-3 (address (#x2000 . #x3fff))
(scatter-to bankc_2000)
(section
code_gfx_helpscreen
cdata_gfx_helpscreen
)
)
; memory in colram for mapping gfx helpscreen bss section
(memory banked-bss-3 (address (#x3f00 . #x3fff))
(scatter-to bankc_3f00)
(section
bss_gfx_helpscreen
)
)
;;;; **** BANKED MEMORY sound ****
; memory in bank 0 for mapping sound module
(memory banked-code-4 (address (#x2000 . #x3fff))
(scatter-to bank1_6000)
(section
code_sound
cdata_sound
)
)
;;;; ********************************************
;;;; MEMORY HOLDING BANKED MODULES IN UPPER BANKS
;;;; ********************************************
; memory holding code_main_private section (will be mapped to 0x3000 during execution)
(memory m0-3 (address (#xd000 . #xe37f))
(section
(bank0_d000 #xd000)
(data_sound #xe000)
cdata_main
)
)
(memory m1-0-bss (address (#x10000 . #x117ff))
(section
(bank1_0000 #x10000)
)
)
(memory m1-0 (address (#x11800 . #x11fff))
(section
(bank1_1800 #x11800)
)
)
(memory m1-1 (address (#x12000 . #x13fff))
(section
(bank1_3a80 #x13a80)
)
)
(memory m1-2 (address (#x14000 . #x15fff))
(section
(bank1_4000 #x14000)
(bank1_5900 #x15900)
)
)
(memory m1-3 (address (#x16000 . #x17fff))
(section
(bank1_6000 #x16000)
)
)
(memory mc-0 (address (#xff82000 . #xff83fff))
(section
(bankc_2000 #xff82000)
(bankc_3f00 #xff83f00)
)
)
))