-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgbemu_io.inc
365 lines (296 loc) · 8.68 KB
/
gbemu_io.inc
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/************************************************************************
* gbemu_io.inc
* Emulation of the Gameboy CPU
* (Input and output)
*
************************************************************************
*
* Phoinix,
* Nintendo Gameboy(TM) emulator for the Palm OS(R) Computing Platform
*
* (c)2000-2006 Bodo Wenzel
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
************************************************************************
* History:
*
* $Log: gbemu_io.inc,v $
* Revision 1.6 2006/10/23 15:38:42 bodowenzel
* Comment to a2 corrected
*
* Revision 1.5 2005/05/03 08:39:11 bodowenzel
* Moved coldReset, ime, im and error into EmulationCpuState
*
* Revision 1.4 2005/01/30 19:34:07 bodowenzel
* Added labels for all combo parts
*
* Revision 1.3 2002/10/19 08:08:11 bodowenzel
* History cleanup, Javadoc-style header
*
* Revision 1.2 2001/12/30 18:47:11 bodowenzel
* CVS keyword Log was faulty
*
* Revision 1.1.1.1 2001/12/16 13:39:54 bodowenzel
* Import
*
************************************************************************
* Pre-CVS History (developed as PalmBoy):
*
* 2001-09-22 Bodo Wenzel Some optimization
* 2001-09-16 Bodo Wenzel Saving states now possible
* 2001-07-23 Bodo Wenzel Changed syntax to CPP + GAS
* 2001-01-28 Bodo Wenzel Dummy SC emulation
* 2000-11-16 Bodo Wenzel Better joypad emulation
* 2000-10-15 Bodo Wenzel Interrupts and timer
* 2000-09-29 Bodo Wenzel Some improvements in source text
* 2000-09-09 Bodo Wenzel Now realy full screen emulation
* 2000-06-18 Bodo Wenzel Creation
************************************************************************
*/
/* ======================================================================
* All i/o accesses are generated with:
* d0.b byte to be written
* d1.b (io_rd: must be preserved)
* d2.b (io_rd: must be preserved)
* a2 68000 base memory address (used after io_rd)
* a3 68000 memory address (used after io_rd, also as "io_lea")
* a6 68000 return address
* ======================================================================
*/
/* === Macros for generating macros... ================================ */
.macro in_std num /* standard read */
.macro in_\num
in_\num:
lea [email protected](%a5),%a2
lea 0x\num-0x0100(%a2),%a3
jmp (%a6)
.endm
.endm
.macro out_std num /* standard write */
.macro out_\num
out_\num:
move.b %d0,EmulationIo+0x\[email protected](%a5)
jmp (%a6) /* no special treatment */
.endm
.endm
.macro out_nul num
.macro out_\num /* write ignored */
out_\num:
jmp (%a6)
.endm
.endm
.macro in_jmp num
.macro in_\num
in_\num:
jmp 0.l /* jump vector to external function */
.endm
.endm
.macro out_jmp num
.macro out_\num
out_\num:
jmp 0.l /* jump vector to external function */
.endm
.endm
/* === And now the actual macros... =================================== */
.macro in_00 /* P1 joypad */
in_00:
move.l [email protected](%a5),%a3
jmp (%a6)
.endm
.macro out_00 /* P1 joypad */
out_00:
lsr.b #4,%d0
and.w #3,%d0
lea [email protected](%a5),%a3
add.w %d0,%a3
move.l %a3,[email protected](%a5)
jmp (%a6)
.endm
in_std 01 /* SB serial transfer data */
.macro out_01 /* SB serial transfer data */
out_01:
jmp (%a6)
io02m: bclr #7,%d0
bset #3,[email protected](%a5)
bra io02q
.endm
in_std 02 /* SC serial transfer control */
.macro out_02 /* SC serial transfer control */
out_02:
btst #0,%d0
bne io02m
io02q: move.b %d0,[email protected](%a5)
jmp (%a6)
.endm
in_std 03 /* 0x03 (not existing) */
out_nul 03
.macro in_04 /* DIV divider */
in_04:
lea [email protected](%a5),%a3
jmp (%a6)
.endm
.macro out_04 /* DIV divider */
out_04:
move.w #0,[email protected](%a5)
jmp (%a6)
.endm
.macro in_05 /* TIMA timer counter */
in_05:
lea [email protected](%a5),%a3
jmp (%a6)
.endm
.macro out_05 /* TIMA timer counter */
out_05:
lea [email protected](%a5),%a3
move.w #0,(%a3)
move.b %d0,(%a3)
jmp (%a6)
.endm
in_std 06 /* TMA timer modulo */
out_std 06 /* TMA timer modulo */
in_std 07 /* TAC timer control */
out_jmp 07 /* TAC timer control */
.irpc i,89abcde
in_std 0\i /* 0x08..0x0e (not existing) */
out_nul 0\i
.endr
in_std 0f /* IF interrupt flags */
out_std 0f /* IF interrupt flags */
in_std 10 /* CH1_ENT (sound) */
out_std 10 /* CH1_ENT (sound) */
in_std 11 /* CH1_WAVE (sound) */
out_std 11 /* CH1_WAVE (sound) */
in_std 12 /* CH1_ENV (sound) */
out_std 12 /* CH1_ENV (sound) */
in_std 13 /* 0x13 (not existing) */
out_nul 13 /* CH1_FREQ_LO (sound) */
in_std 14 /* CH1_FREQ_HI_KICK (sound) */
out_std 14 /* CH1_FREQ_HI_KICK (sound) */
in_std 15 /* 0x15 (not existing) */
out_nul 15
in_std 16 /* CH2_WAVE (sound) */
out_std 16 /* CH2_WAVE (sound) */
in_std 17 /* CH2_ENV (sound) */
out_std 17 /* CH2_ENV (sound) */
in_std 18 /* 0x18 (not existing) */
out_nul 18 /* CH2_FREQ_LO (sound) */
in_std 19 /* CH2_FREQ_HI_KICK (sound) */
out_std 19 /* CH2_FREQ_HI_KICK (sound) */
in_std 1a /* CH3_ONOFF (sound) */
out_std 1a /* CH3_ONOFF (sound) */
in_std 1b /* CH3_LENGTH (sound) */
out_std 1b /* CH3_LENGTH (sound) */
in_std 1c /* CH3_VOLUME (sound) */
out_std 1c /* CH3_VOLUME (sound) */
in_std 1d /* 0x1d (not existing) */
out_nul 1d /* CH3_FREQ_LO (sound) */
in_std 1e /* CH3_FREQ_HI_KICK (sound) */
out_std 1e /* CH3_FREQ_HI_KICK (sound) */
in_std 1f /* 0x1f (not existing) */
out_nul 1f
in_std 20 /* CH4_LENGTH (sound) */
out_std 20 /* CH4_LENGTH (sound) */
in_std 21 /* CH4_ENV (sound) */
out_std 21 /* CH4_ENV (sound) */
in_std 22 /* CH4_POLY (sound) */
out_std 22 /* CH4_POLY (sound) */
in_std 23 /* CH4_KICK (sound) */
out_std 23 /* CH4_KICK (sound) */
in_std 24 /* SND_VIN (sound) */
out_std 24 /* SND_VIN (sound) */
in_std 25 /* SND_STEREO (sound) */
out_std 25 /* SND_STEREO (sound) */
in_std 26 /* SND_STAT (sound) */
out_std 26 /* SND_STAT (sound) */
.irpc i,789abcdef
in_std 2\i /* 0x27..0x2f (not existing) */
out_nul 2\i
.endr
.irpc i,0123456789abcdef
in_std 3\i /* RAM wave pattern */
out_std 3\i
.endr
in_std 40 /* LCDC LCD control */
out_jmp 40 /* LCDC LCD control */
in_jmp 41 /* STAT LCD status */
out_jmp 41 /* STAT LCD status */
in_std 42 /* SCY scroll Y */
out_jmp 42 /* SCY scroll Y */
in_std 43 /* SCX scroll X */
out_jmp 43 /* SCX scroll X */
.macro in_44 /* LY LCD Y coordinate */
in_44:
moveq #143-1-0x100,%d0
sub.w [email protected](%a5),%d0
lea [email protected](%a5),%a3
move.b %d0,(%a3)
jmp (%a6)
.endm
.macro out_44 /* LY LCD Y coordinate */
out_44:
/* it's not clear if it can be reset by writing... */
jmp (%a6)
.endm
in_std 45 /* LYC LCD Y compare */
out_jmp 45 /* LYC LCD Y compare */
in_std 46
.macro out_46 /* DMA transfer and start address */
out_46:
pea (%a6)
clr.b %d1
move.l 2+indexToAddress(gbemuJmpIoWrDma),%a6
move.b %d0,jump\@+2-Gbemu(%a4)
jump\@: jmp offsetRd+dontOptHi(%a4)
.endm
in_std 47 /* BGP background palette */
out_jmp 47 /* BGP background palette */
in_std 48 /* OBP0 object palette 0 */
out_jmp 48 /* OBP0 object palette 0 */
in_std 49 /* OBP1 object palette 1 */
out_jmp 49 /* OBP1 object palette 1 */
in_std 4a /* WY window Y */
out_jmp 4a /* WY window Y */
in_std 4b /* WX window X */
out_jmp 4b /* WX window X */
.irpc i,cdef
in_std 4\i /* 0x4c..0x4f (not existing) */
out_nul 4\i
.endr
.irpc i,567
.irpc j,0123456789abcdef
in_std \i\j /* 0x50..0x7f (not existing) */
out_nul \i\j
.endr
.endr
.irpc i,89abcde
.irpc j,0123456789abcdef
in_std \i\j /* RAM in CPU */
out_std \i\j
.endr
.endr
.irpc i,0123456789abcde
in_std f\i /* RAM in CPU */
out_std f\i
.endr
in_std ff /* IE interrupt enable */
.macro out_ff /* IE interrupt enable */
out_ff:
move.b %d0,[email protected](%a5)
and.b [email protected](%a5),%d0
move.b %d0,[email protected](%a5)
pea (%a6)
jmp indexToAddress(gbemuCodeCheckInt)
.endm
/* === The end ======================================================== */