~ubuntu-branches/ubuntu/raring/mame/raring-proposed

« back to all changes in this revision

Viewing changes to mess/src/emu/cpu/m6502/ops02.h

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 *
3
 
 *   ops02.h
4
 
 *   Addressing mode and opcode macros for 6502,65c02,65sc02,6510,n2a03 CPUs
5
 
 *
6
 
 *   Copyright Juergen Buchmueller, all rights reserved.
7
 
 *   65sc02 core Copyright Peter Trauner, all rights reserved.
8
 
 *
9
 
 *   - This source code is released as freeware for non-commercial purposes.
10
 
 *   - You are free to use and redistribute this code in modified or
11
 
 *     unmodified form, provided you list me in the credits.
12
 
 *   - If you modify this source code, you must add a notice to each modified
13
 
 *     source file that it has been changed.  If you're a nice person, you
14
 
 *     will clearly mark each change too.  :)
15
 
 *   - If you wish to use this for commercial purposes, please contact me at
16
 
 *     pullmoll@t-online.de
17
 
 *   - The author of this copywritten work reserves the right to change the
18
 
 *     terms of its usage and license at any time, including retroactively
19
 
 *   - This entire notice must remain in the source code.
20
 
 *
21
 
 *****************************************************************************/
22
 
 
23
 
 
24
 
/* 6502 flags */
25
 
#define F_C 0x01
26
 
#define F_Z 0x02
27
 
#define F_I 0x04
28
 
#define F_D 0x08
29
 
#define F_B 0x10
30
 
#define F_T 0x20
31
 
#define F_V 0x40
32
 
#define F_N 0x80
33
 
 
34
 
/* some shortcuts for improved readability */
35
 
#define A       cpustate->a
36
 
#define X       cpustate->x
37
 
#define Y       cpustate->y
38
 
#define P       cpustate->p
39
 
#define S       cpustate->sp.b.l
40
 
#define SPD cpustate->sp.d
41
 
 
42
 
#define NZ      cpustate->nz
43
 
 
44
 
#define SET_NZ(n)                               \
45
 
        if ((n) == 0) P = (P & ~F_N) | F_Z; else P = (P & ~(F_N | F_Z)) | ((n) & F_N)
46
 
 
47
 
#define SET_Z(n)                                \
48
 
        if ((n) == 0) P |= F_Z; else P &= ~F_Z
49
 
 
50
 
#define EAL cpustate->ea.b.l
51
 
#define EAH cpustate->ea.b.h
52
 
#define EAW cpustate->ea.w.l
53
 
#define EAD cpustate->ea.d
54
 
 
55
 
#define ZPL cpustate->zp.b.l
56
 
#define ZPH cpustate->zp.b.h
57
 
#define ZPW cpustate->zp.w.l
58
 
#define ZPD cpustate->zp.d
59
 
 
60
 
#define PCL cpustate->pc.b.l
61
 
#define PCH cpustate->pc.b.h
62
 
#define PCW cpustate->pc.w.l
63
 
#define PCD cpustate->pc.d
64
 
 
65
 
#define PPC cpustate->ppc.d
66
 
 
67
 
#define RDMEM_ID(a)             cpustate->rdmem_id(cpustate->space,a)
68
 
#define WRMEM_ID(a,d)   cpustate->wrmem_id(cpustate->space,a,d)
69
 
 
70
 
/***************************************************************
71
 
 *  RDOP    read an opcode
72
 
 ***************************************************************/
73
 
#define RDOP() cpustate->direct->read_decrypted_byte(PCW++); cpustate->icount -= 1
74
 
#define PEEKOP() cpustate->direct->read_decrypted_byte(PCW)
75
 
 
76
 
/***************************************************************
77
 
 *  RDOPARG read an opcode argument
78
 
 ***************************************************************/
79
 
#define RDOPARG() cpustate->direct->read_raw_byte(PCW++); cpustate->icount -= 1
80
 
 
81
 
/***************************************************************
82
 
 *  RDMEM   read memory
83
 
 ***************************************************************/
84
 
#define RDMEM(addr) cpustate->space->read_byte(addr); cpustate->icount -= 1
85
 
 
86
 
/***************************************************************
87
 
 *  WRMEM   write memory
88
 
 ***************************************************************/
89
 
#define WRMEM(addr,data) cpustate->space->write_byte(addr,data); cpustate->icount -= 1
90
 
 
91
 
/***************************************************************
92
 
 *  BRA  branch relative
93
 
 *  extra cycle if page boundary is crossed
94
 
 ***************************************************************/
95
 
#define BRA(cond)                                                                                               \
96
 
        {                                                                                                                               \
97
 
                INT8 tmp2 = RDOPARG();                                                                          \
98
 
                if (cond)                                                                                                       \
99
 
                {                                                                                                                       \
100
 
                        RDMEM(PCW);                                                                                             \
101
 
                        EAW = PCW + (signed char)tmp2;                                                  \
102
 
                        if ( EAH != PCH ) {                                                                             \
103
 
                                RDMEM( (PCH << 8 ) | EAL) ;                                                     \
104
 
                        }                                                                                                               \
105
 
                        PCD = EAD;                                                                                              \
106
 
                }                                                                                                                       \
107
 
        }
108
 
 
109
 
/***************************************************************
110
 
 *
111
 
 * Helper macros to build the effective address
112
 
 *
113
 
 ***************************************************************/
114
 
 
115
 
/***************************************************************
116
 
 *  EA = zero page address
117
 
 ***************************************************************/
118
 
#define EA_ZPG                                                                                                  \
119
 
        ZPL = RDOPARG();                                                                                        \
120
 
        EAD = ZPD
121
 
 
122
 
/***************************************************************
123
 
 *  EA = zero page address + X
124
 
 ***************************************************************/
125
 
#define EA_ZPX                                                                                                  \
126
 
        ZPL = RDOPARG();                                                                                        \
127
 
        RDMEM(ZPD);                                                                                                     \
128
 
        ZPL = X + ZPL;                                                                                          \
129
 
        EAD = ZPD
130
 
 
131
 
/***************************************************************
132
 
 *  EA = zero page address + Y
133
 
 ***************************************************************/
134
 
#define EA_ZPY                                                                                                  \
135
 
        ZPL = RDOPARG();                                                                                        \
136
 
        RDMEM(ZPD);                                                                                                     \
137
 
        ZPL = Y + ZPL;                                                                                          \
138
 
        EAD = ZPD
139
 
 
140
 
/***************************************************************
141
 
 *  EA = absolute address
142
 
 ***************************************************************/
143
 
#define EA_ABS                                                                                                  \
144
 
        EAL = RDOPARG();                                                                                        \
145
 
        EAH = RDOPARG()
146
 
 
147
 
/***************************************************************
148
 
 *  EA = absolute address + X
149
 
 * one additional read if page boundary is crossed
150
 
 ***************************************************************/
151
 
#define EA_ABX_P                                                                                                \
152
 
        EA_ABS;                                                                                                         \
153
 
        if ( EAL + X > 0xff ) {                                                                         \
154
 
                RDMEM( ( EAH << 8 ) | ( ( EAL + X ) & 0xff ) );                 \
155
 
        }                                                                                                                       \
156
 
        EAW += X;
157
 
 
158
 
/***************************************************************
159
 
 *  EA = absolute address + X
160
 
 ***************************************************************/
161
 
#define EA_ABX_NP                                                                                               \
162
 
        EA_ABS;                                                                                                         \
163
 
        RDMEM( ( EAH << 8 ) | ( ( EAL + X ) & 0xff ) );                         \
164
 
        EAW += X
165
 
 
166
 
/***************************************************************
167
 
 *  EA = absolute address + Y
168
 
 * one additional read if page boundary is crossed
169
 
 ***************************************************************/
170
 
#define EA_ABY_P                                                                                                \
171
 
        EA_ABS;                                                                                                         \
172
 
        if ( EAL + Y > 0xff ) {                                                                         \
173
 
                RDMEM( ( EAH << 8 ) | ( ( EAL + Y ) & 0xff ) );                 \
174
 
        }                                                                                                                       \
175
 
        EAW += Y;
176
 
 
177
 
/***************************************************************
178
 
 *  EA = absolute address + Y
179
 
 ***************************************************************/
180
 
#define EA_ABY_NP                                                                                               \
181
 
        EA_ABS;                                                                                                         \
182
 
        RDMEM( ( EAH << 8 ) | ( ( EAL + Y ) & 0xff ) );                         \
183
 
        EAW += Y
184
 
 
185
 
/***************************************************************
186
 
 *  EA = zero page + X indirect (pre indexed)
187
 
 ***************************************************************/
188
 
#define EA_IDX                                                                                                  \
189
 
        ZPL = RDOPARG();                                                                                        \
190
 
        RDMEM(ZPD);                                                                                                     \
191
 
        ZPL = ZPL + X;                                                                                          \
192
 
        EAL = RDMEM(ZPD);                                                                                       \
193
 
        ZPL++;                                                                                                          \
194
 
        EAH = RDMEM(ZPD)
195
 
 
196
 
/***************************************************************
197
 
 *  EA = zero page indirect + Y (post indexed)
198
 
 *  subtract 1 cycle if page boundary is crossed
199
 
 ***************************************************************/
200
 
#define EA_IDY_P                                                                                                \
201
 
        ZPL = RDOPARG();                                                                                        \
202
 
        EAL = RDMEM(ZPD);                                                                                       \
203
 
        ZPL++;                                                                                                          \
204
 
        EAH = RDMEM(ZPD);                                                                                       \
205
 
        if (EAL + Y > 0xff) {                                                                           \
206
 
                RDMEM( ( EAH << 8 ) | ( ( EAL + Y ) & 0xff ) );                 \
207
 
        }                                                                                                                       \
208
 
        EAW += Y;
209
 
 
210
 
/***************************************************************
211
 
 *  EA = zero page indirect + Y
212
 
 ***************************************************************/
213
 
#define EA_IDY_NP                                                                                               \
214
 
        ZPL = RDOPARG();                                                                                        \
215
 
        EAL = RDMEM(ZPD);                                                                                       \
216
 
        ZPL++;                                                                                                          \
217
 
        EAH = RDMEM(ZPD);                                                                                       \
218
 
        RDMEM( ( EAH << 8 ) | ( ( EAL + Y ) & 0xff ) );                         \
219
 
        EAW += Y
220
 
 
221
 
/***************************************************************
222
 
 *  EA = zero page indirect (65c02 pre indexed w/o X)
223
 
 ***************************************************************/
224
 
#define EA_ZPI                                                                                                  \
225
 
        ZPL = RDOPARG();                                                                                \
226
 
        EAL = RDMEM(ZPD);                                                                               \
227
 
        ZPL++;                                                                                                  \
228
 
        EAH = RDMEM(ZPD)
229
 
 
230
 
/***************************************************************
231
 
 *  EA = indirect (only used by JMP)
232
 
 ***************************************************************/
233
 
#define EA_IND                                                                                                  \
234
 
        EA_ABS;                                                                                                         \
235
 
        tmp = RDMEM(EAD);                                                                                       \
236
 
        EAL++;  /* booby trap: stay in same page! ;-) */                        \
237
 
        EAH = RDMEM(EAD);                                                                                       \
238
 
        EAL = tmp
239
 
 
240
 
 
241
 
/* read a value into tmp */
242
 
/* Base number of cycles taken for each mode (including reading of opcode):
243
 
   RD_IMM       2
244
 
   RD_DUM       2
245
 
   RD_ACC       0
246
 
   RD_ZPG/WR_ZPG    3
247
 
   RD_ZPX/WR_ZPX    4
248
 
   RD_ZPY/WR_ZPY    4
249
 
   RD_ABS/WR_ABS    4
250
 
   RD_ABX_P     4/5
251
 
   RD_ABX_NP/WR_ABX_NP  5
252
 
   RD_ABY_P     4/5
253
 
   RD_ABY_NP/WR_ABY_NP  5
254
 
   RD_IDX/WR_IDX    6
255
 
   RD_IDY_P     5/6
256
 
   RD_IDY_NP/WR_IDY_NP  6
257
 
   RD_ZPI/WR_ZPI    5
258
 
 */
259
 
#define RD_IMM          tmp = RDOPARG()
260
 
#define RD_IMM_DISCARD RDOPARG()
261
 
#define RD_DUM          RDMEM(PCW)
262
 
#define RD_ACC          tmp = A
263
 
#define RD_ZPG          EA_ZPG; tmp = RDMEM(EAD)
264
 
#define RD_ZPG_DISCARD          EA_ZPG; RDMEM(EAD)
265
 
#define RD_ZPX          EA_ZPX; tmp = RDMEM(EAD)
266
 
#define RD_ZPX_DISCARD          EA_ZPX; RDMEM(EAD)
267
 
#define RD_ZPY          EA_ZPY; tmp = RDMEM(EAD)
268
 
#define RD_ABS          EA_ABS; tmp = RDMEM(EAD)
269
 
#define RD_ABS_DISCARD          EA_ABS; RDMEM(EAD)
270
 
#define RD_ABX_P        EA_ABX_P; tmp = RDMEM(EAD)
271
 
#define RD_ABX_P_DISCARD        EA_ABX_P; RDMEM(EAD);
272
 
#define RD_ABX_NP       EA_ABX_NP; tmp = RDMEM(EAD)
273
 
#define RD_ABY_P        EA_ABY_P; tmp = RDMEM(EAD)
274
 
#define RD_ABY_NP       EA_ABY_NP; tmp = RDMEM(EAD)
275
 
#define RD_IDX          EA_IDX; tmp = RDMEM_ID(EAD); cpustate->icount -= 1
276
 
#define RD_IDY_P        EA_IDY_P; tmp = RDMEM_ID(EAD); cpustate->icount -= 1
277
 
#define RD_IDY_NP       EA_IDY_NP; tmp = RDMEM_ID(EAD); cpustate->icount -= 1
278
 
#define RD_ZPI          EA_ZPI; tmp = RDMEM(EAD)
279
 
 
280
 
/* write a value from tmp */
281
 
#define WR_ZPG          EA_ZPG; WRMEM(EAD, tmp)
282
 
#define WR_ZPX          EA_ZPX; WRMEM(EAD, tmp)
283
 
#define WR_ZPY          EA_ZPY; WRMEM(EAD, tmp)
284
 
#define WR_ABS          EA_ABS; WRMEM(EAD, tmp)
285
 
#define WR_ABX_NP       EA_ABX_NP; WRMEM(EAD, tmp)
286
 
#define WR_ABY_NP       EA_ABY_NP; WRMEM(EAD, tmp)
287
 
#define WR_IDX          EA_IDX; WRMEM_ID(EAD, tmp); cpustate->icount -= 1
288
 
#define WR_IDY_NP       EA_IDY_NP; WRMEM_ID(EAD, tmp); cpustate->icount -= 1
289
 
#define WR_ZPI          EA_ZPI; WRMEM(EAD, tmp)
290
 
 
291
 
/* dummy read from the last EA */
292
 
#define RD_EA   RDMEM(EAD)
293
 
 
294
 
/* write back a value from tmp to the last EA */
295
 
#define WB_ACC  A = (UINT8)tmp;
296
 
#define WB_EA   WRMEM(EAD, tmp)
297
 
 
298
 
/***************************************************************
299
 
 ***************************************************************
300
 
 *          Macros to emulate the plain 6502 opcodes
301
 
 ***************************************************************
302
 
 ***************************************************************/
303
 
 
304
 
/***************************************************************
305
 
 * push a register onto the stack
306
 
 ***************************************************************/
307
 
#define PUSH(Rg) WRMEM(SPD, Rg); S--
308
 
 
309
 
/***************************************************************
310
 
 * pull a register from the stack
311
 
 ***************************************************************/
312
 
#define PULL(Rg) S++; Rg = RDMEM(SPD)
313
 
 
314
 
/* 6502 ********************************************************
315
 
 *  ADC Add with carry
316
 
 ***************************************************************/
317
 
#define ADC                                                                                                     \
318
 
        if (P & F_D) {                                                                                          \
319
 
        int c = (P & F_C);                                                                                      \
320
 
        int lo = (A & 0x0f) + (tmp & 0x0f) + c;                                         \
321
 
        int hi = (A & 0xf0) + (tmp & 0xf0);                                             \
322
 
                P &= ~(F_V | F_C|F_N|F_Z);                                                              \
323
 
                if (!((lo+hi)&0xff)) P|=F_Z;                                                    \
324
 
                if (lo > 0x09) {                                                                                \
325
 
                        hi += 0x10;                                                                             \
326
 
                        lo += 0x06;                                                                             \
327
 
                }                                                                                                               \
328
 
                if (hi&0x80) P|=F_N;                                                                    \
329
 
                if (~(A^tmp) & (A^hi) & F_N)                                                    \
330
 
                        P |= F_V;                                                                                       \
331
 
                if (hi > 0x90)                                                                                  \
332
 
                        hi += 0x60;                                                                             \
333
 
                if (hi & 0xff00)                                                                                \
334
 
                        P |= F_C;                                                                                       \
335
 
                A = (lo & 0x0f) + (hi & 0xf0);                                                  \
336
 
        } else {                                                                                                        \
337
 
                int c = (P & F_C);                                                                              \
338
 
                int sum = A + tmp + c;                                                                  \
339
 
                P &= ~(F_V | F_C);                                                                              \
340
 
                if (~(A^tmp) & (A^sum) & F_N)                                                   \
341
 
                        P |= F_V;                                                                                       \
342
 
                if (sum & 0xff00)                                                                               \
343
 
                        P |= F_C;                                                                                       \
344
 
                A = (UINT8) sum;                                                                                \
345
 
                SET_NZ(A);                                                                                              \
346
 
        }
347
 
 
348
 
/* 6502 ********************************************************
349
 
 *  AND Logical and
350
 
 ***************************************************************/
351
 
#define AND                                                                                                     \
352
 
        A = (UINT8)(A & tmp);                                                                           \
353
 
        SET_NZ(A)
354
 
 
355
 
/* 6502 ********************************************************
356
 
 *  ASL Arithmetic shift left
357
 
 ***************************************************************/
358
 
#define ASL                                                                                                     \
359
 
        P = (P & ~F_C) | ((tmp >> 7) & F_C);                                            \
360
 
        tmp = (UINT8)(tmp << 1);                                                                        \
361
 
        SET_NZ(tmp)
362
 
 
363
 
/* 6502 ********************************************************
364
 
 *  BCC Branch if carry clear
365
 
 ***************************************************************/
366
 
#define BCC BRA(!(P & F_C))
367
 
 
368
 
/* 6502 ********************************************************
369
 
 *  BCS Branch if carry set
370
 
 ***************************************************************/
371
 
#define BCS BRA(P & F_C)
372
 
 
373
 
/* 6502 ********************************************************
374
 
 *  BEQ Branch if equal
375
 
 ***************************************************************/
376
 
#define BEQ BRA(P & F_Z)
377
 
 
378
 
/* 6502 ********************************************************
379
 
 *  BIT Bit test
380
 
 ***************************************************************/
381
 
#undef BIT
382
 
#define BIT                                                                                                     \
383
 
        P &= ~(F_N|F_V|F_Z);                                                                            \
384
 
        P |= tmp & (F_N|F_V);                                                                           \
385
 
        if ((tmp & A) == 0)                                                                             \
386
 
                P |= F_Z
387
 
 
388
 
/* 6502 ********************************************************
389
 
 *  BMI Branch if minus
390
 
 ***************************************************************/
391
 
#define BMI BRA(P & F_N)
392
 
 
393
 
/* 6502 ********************************************************
394
 
 *  BNE Branch if not equal
395
 
 ***************************************************************/
396
 
#define BNE BRA(!(P & F_Z))
397
 
 
398
 
/* 6502 ********************************************************
399
 
 *  BPL Branch if plus
400
 
 ***************************************************************/
401
 
#define BPL BRA(!(P & F_N))
402
 
 
403
 
/* 6502 ********************************************************
404
 
 *  BRK Break
405
 
 *  increment PC, push PC hi, PC lo, flags (with B bit set),
406
 
 *  set I flag, jump via IRQ vector
407
 
 ***************************************************************/
408
 
#define BRK                                                                                                     \
409
 
        RDOPARG();                                                                                                      \
410
 
        PUSH(PCH);                                                                                                      \
411
 
        PUSH(PCL);                                                                                                      \
412
 
        PUSH(P | F_B);                                                                                          \
413
 
        P = (P | F_I);                                                                                          \
414
 
        PCL = RDMEM(M6502_IRQ_VEC);                                                             \
415
 
        PCH = RDMEM(M6502_IRQ_VEC+1)
416
 
 
417
 
/* 6502 ********************************************************
418
 
 * BVC  Branch if overflow clear
419
 
 ***************************************************************/
420
 
#define BVC BRA(!(P & F_V))
421
 
 
422
 
/* 6502 ********************************************************
423
 
 * BVS  Branch if overflow set
424
 
 ***************************************************************/
425
 
#define BVS BRA(P & F_V)
426
 
 
427
 
/* 6502 ********************************************************
428
 
 * CLC  Clear carry flag
429
 
 ***************************************************************/
430
 
#define CLC                                                                                                     \
431
 
        P &= ~F_C
432
 
 
433
 
/* 6502 ********************************************************
434
 
 * CLD  Clear decimal flag
435
 
 ***************************************************************/
436
 
#define CLD                                                                                                     \
437
 
        P &= ~F_D
438
 
 
439
 
/* 6502 ********************************************************
440
 
 * CLI  Clear interrupt flag
441
 
 ***************************************************************/
442
 
#define CLI                                                                                                     \
443
 
        if ((cpustate->irq_state != CLEAR_LINE) && (P & F_I)) {                 \
444
 
                /* kludge for now until IRQ rewrite: ignore if RTI follows */ \
445
 
                if (PEEKOP() != 0x40) \
446
 
                        cpustate->after_cli = 1;                                                                        \
447
 
        }                                                                                                                       \
448
 
        P &= ~F_I
449
 
 
450
 
/* 6502 ********************************************************
451
 
 * CLV  Clear overflow flag
452
 
 ***************************************************************/
453
 
#define CLV                                                                                                     \
454
 
        P &= ~F_V
455
 
 
456
 
/* 6502 ********************************************************
457
 
 *  CMP Compare accumulator
458
 
 ***************************************************************/
459
 
#define CMP                                                                                                     \
460
 
        P &= ~F_C;                                                                                                      \
461
 
        if (A >= tmp)                                                                                           \
462
 
                P |= F_C;                                                                                               \
463
 
        SET_NZ((UINT8)(A - tmp))
464
 
 
465
 
/* 6502 ********************************************************
466
 
 *  CPX Compare index X
467
 
 ***************************************************************/
468
 
#define CPX                                                                                                     \
469
 
        P &= ~F_C;                                                                                                      \
470
 
        if (X >= tmp)                                                                                           \
471
 
                P |= F_C;                                                                                               \
472
 
        SET_NZ((UINT8)(X - tmp))
473
 
 
474
 
/* 6502 ********************************************************
475
 
 *  CPY Compare index Y
476
 
 ***************************************************************/
477
 
#define CPY                                                                                                     \
478
 
        P &= ~F_C;                                                                                                      \
479
 
        if (Y >= tmp)                                                                                           \
480
 
                P |= F_C;                                                                                               \
481
 
        SET_NZ((UINT8)(Y - tmp))
482
 
 
483
 
/* 6502 ********************************************************
484
 
 *  DEC Decrement memory
485
 
 ***************************************************************/
486
 
#define DEC                                                                                                     \
487
 
        tmp = (UINT8)(tmp-1);                                                                           \
488
 
        SET_NZ(tmp)
489
 
 
490
 
/* 6502 ********************************************************
491
 
 *  DEX Decrement index X
492
 
 ***************************************************************/
493
 
#define DEX                                                                                                     \
494
 
        X = (UINT8)(X-1);                                                                                       \
495
 
        SET_NZ(X)
496
 
 
497
 
/* 6502 ********************************************************
498
 
 *  DEY Decrement index Y
499
 
 ***************************************************************/
500
 
#define DEY                                                                                                     \
501
 
        Y = (UINT8)(Y-1);                                                                                       \
502
 
        SET_NZ(Y)
503
 
 
504
 
/* 6502 ********************************************************
505
 
 *  EOR Logical exclusive or
506
 
 ***************************************************************/
507
 
#define EOR                                                                                                     \
508
 
        A = (UINT8)(A ^ tmp);                                                                           \
509
 
        SET_NZ(A)
510
 
 
511
 
/* 6502 ********************************************************
512
 
 *  ILL Illegal opcode
513
 
 ***************************************************************/
514
 
#define ILL                                                                                                     \
515
 
        logerror("M6502 illegal opcode %04x: %02x\n",(PCW-1)&0xffff, cpustate->direct->read_decrypted_byte((PCW-1)&0xffff))
516
 
 
517
 
/* 6502 ********************************************************
518
 
 *  INC Increment memory
519
 
 ***************************************************************/
520
 
#define INC                                                                                                     \
521
 
        tmp = (UINT8)(tmp+1);                                                                           \
522
 
        SET_NZ(tmp)
523
 
 
524
 
/* 6502 ********************************************************
525
 
 *  INX Increment index X
526
 
 ***************************************************************/
527
 
#define INX                                                                                                     \
528
 
        X = (UINT8)(X+1);                                                                                       \
529
 
        SET_NZ(X)
530
 
 
531
 
/* 6502 ********************************************************
532
 
 *  INY Increment index Y
533
 
 ***************************************************************/
534
 
#define INY                                                                                                     \
535
 
        Y = (UINT8)(Y+1);                                                                                       \
536
 
        SET_NZ(Y)
537
 
 
538
 
/* 6502 ********************************************************
539
 
 *  JMP Jump to address
540
 
 *  set PC to the effective address
541
 
 ***************************************************************/
542
 
#define JMP                                                                                                     \
543
 
        if( EAD == PPC && !cpustate->pending_irq && !cpustate->after_cli )      \
544
 
                if( cpustate->icount > 0 ) cpustate->icount = 0;                                \
545
 
        PCD = EAD
546
 
 
547
 
/* 6502 ********************************************************
548
 
 *  JSR Jump to subroutine
549
 
 *  decrement PC (sic!) push PC hi, push PC lo and set
550
 
 *  PC to the effective address
551
 
 ***************************************************************/
552
 
#define JSR                                                                                                     \
553
 
        EAL = RDOPARG();                                                                                        \
554
 
        RDMEM(SPD);                                                                                                     \
555
 
        PUSH(PCH);                                                                                                      \
556
 
        PUSH(PCL);                                                                                                      \
557
 
        EAH = RDOPARG();                                                                                        \
558
 
        PCD = EAD
559
 
 
560
 
/* 6502 ********************************************************
561
 
 *  LDA Load accumulator
562
 
 ***************************************************************/
563
 
#define LDA                                                                                                     \
564
 
        A = (UINT8)tmp;                                                                                         \
565
 
        SET_NZ(A)
566
 
 
567
 
/* 6502 ********************************************************
568
 
 *  LDX Load index X
569
 
 ***************************************************************/
570
 
#define LDX                                                                                                     \
571
 
        X = (UINT8)tmp;                                                                                         \
572
 
        SET_NZ(X)
573
 
 
574
 
/* 6502 ********************************************************
575
 
 *  LDY Load index Y
576
 
 ***************************************************************/
577
 
#define LDY                                                                                                     \
578
 
        Y = (UINT8)tmp;                                                                                         \
579
 
        SET_NZ(Y)
580
 
 
581
 
/* 6502 ********************************************************
582
 
 *  LSR Logic shift right
583
 
 *  0 -> [7][6][5][4][3][2][1][0] -> C
584
 
 ***************************************************************/
585
 
#define LSR                                                                                                     \
586
 
        P = (P & ~F_C) | (tmp & F_C);                                                           \
587
 
        tmp = (UINT8)tmp >> 1;                                                                          \
588
 
        SET_NZ(tmp)
589
 
 
590
 
/* 6502 ********************************************************
591
 
 *  NOP No operation
592
 
 ***************************************************************/
593
 
#define NOP
594
 
 
595
 
/* 6502 ********************************************************
596
 
 *  ORA Logical inclusive or
597
 
 ***************************************************************/
598
 
#define ORA                                                                                                     \
599
 
        A = (UINT8)(A | tmp);                                                                           \
600
 
        SET_NZ(A)
601
 
 
602
 
/* 6502 ********************************************************
603
 
 *  PHA Push accumulator
604
 
 ***************************************************************/
605
 
#define PHA                                                                                                     \
606
 
        PUSH(A)
607
 
 
608
 
/* 6502 ********************************************************
609
 
 *  PHP Push processor status (flags)
610
 
 ***************************************************************/
611
 
#define PHP                                                                                                     \
612
 
        PUSH(P)
613
 
 
614
 
/* 6502 ********************************************************
615
 
 *  PLA Pull accumulator
616
 
 ***************************************************************/
617
 
#define PLA                                                                                                     \
618
 
        RDMEM(SPD);                                                                                                     \
619
 
        PULL(A);                                                                                                        \
620
 
        SET_NZ(A)
621
 
 
622
 
 
623
 
/* 6502 ********************************************************
624
 
 *  PLP Pull processor status (flags)
625
 
 ***************************************************************/
626
 
#define PLP                                                                                                     \
627
 
        RDMEM(SPD);                                                                                                     \
628
 
        if ( P & F_I ) {                                                                                        \
629
 
                PULL(P);                                                                                                \
630
 
                if ((cpustate->irq_state != CLEAR_LINE) && !(P & F_I)) {        \
631
 
                        LOG(("M6502 '%s' PLP sets after_cli\n",cpustate->device->tag()));       \
632
 
                        cpustate->after_cli = 1;                                                                \
633
 
                }                                                                                                               \
634
 
        } else {                                                                                                        \
635
 
                PULL(P);                                                                                                \
636
 
        }                                                                                                                       \
637
 
        P |= (F_T|F_B);
638
 
 
639
 
/* 6502 ********************************************************
640
 
 * ROL  Rotate left
641
 
 *  new C <- [7][6][5][4][3][2][1][0] <- C
642
 
 ***************************************************************/
643
 
#define ROL                                                                                                     \
644
 
        tmp = (tmp << 1) | (P & F_C);                                                           \
645
 
        P = (P & ~F_C) | ((tmp >> 8) & F_C);                                            \
646
 
        tmp = (UINT8)tmp;                                                                                       \
647
 
        SET_NZ(tmp)
648
 
 
649
 
/* 6502 ********************************************************
650
 
 * ROR  Rotate right
651
 
 *  C -> [7][6][5][4][3][2][1][0] -> new C
652
 
 ***************************************************************/
653
 
#define ROR                                                                                                     \
654
 
        tmp |= (P & F_C) << 8;                                                                          \
655
 
        P = (P & ~F_C) | (tmp & F_C);                                                           \
656
 
        tmp = (UINT8)(tmp >> 1);                                                                        \
657
 
        SET_NZ(tmp)
658
 
 
659
 
/* 6502 ********************************************************
660
 
 * RTI  Return from interrupt
661
 
 * pull flags, pull PC lo, pull PC hi and increment PC
662
 
 *  PCW++;
663
 
 ***************************************************************/
664
 
#define RTI                                                                                                     \
665
 
        RDOPARG();                                                                                                      \
666
 
        RDMEM(SPD);                                                                                                     \
667
 
        PULL(P);                                                                                                        \
668
 
        PULL(PCL);                                                                                                      \
669
 
        PULL(PCH);                                                                                                      \
670
 
        P |= F_T | F_B;                                                                                         \
671
 
        if( (cpustate->irq_state != CLEAR_LINE) && !(P & F_I) )                 \
672
 
        {                                                                                                                       \
673
 
                LOG(("M6502 '%s' RTI sets after_cli\n",cpustate->device->tag()));       \
674
 
                cpustate->after_cli = 1;                                                                        \
675
 
        }
676
 
 
677
 
/* 6502 ********************************************************
678
 
 *  RTS Return from subroutine
679
 
 *  pull PC lo, PC hi and increment PC
680
 
 ***************************************************************/
681
 
#define RTS                                                                                                     \
682
 
        RDOPARG();                                                                                                      \
683
 
        RDMEM(SPD);                                                                                                     \
684
 
        PULL(PCL);                                                                                                      \
685
 
        PULL(PCH);                                                                                                      \
686
 
        RDMEM(PCW); PCW++
687
 
 
688
 
/* 6502 ********************************************************
689
 
 *  SBC Subtract with carry
690
 
 ***************************************************************/
691
 
#define SBC                                                                                                     \
692
 
        if (P & F_D)                                                                                            \
693
 
        {                                                                                                                       \
694
 
                int c = (P & F_C) ^ F_C;                                                                \
695
 
                int sum = A - tmp - c;                                                                  \
696
 
                int lo = (A & 0x0f) - (tmp & 0x0f) - c;                                 \
697
 
                int hi = (A & 0xf0) - (tmp & 0xf0);                                     \
698
 
                if (lo & 0x10)                                                                                  \
699
 
                {                                                                                                               \
700
 
                        lo -= 6;                                                                                        \
701
 
                        hi--;                                                                                           \
702
 
                }                                                                                                               \
703
 
                P &= ~(F_V | F_C|F_Z|F_N);                                                              \
704
 
                if( (A^tmp) & (A^sum) & F_N )                                                   \
705
 
                        P |= F_V;                                                                                       \
706
 
                if( hi & 0x0100 )                                                                               \
707
 
                        hi -= 0x60;                                                                             \
708
 
                if( (sum & 0xff00) == 0 )                                                               \
709
 
                        P |= F_C;                                                                                       \
710
 
                if( !((A-tmp-c) & 0xff) )                                                               \
711
 
                        P |= F_Z;                                                                                       \
712
 
                if( (A-tmp-c) & 0x80 )                                                                  \
713
 
                        P |= F_N;                                                                                       \
714
 
                A = (lo & 0x0f) | (hi & 0xf0);                                                  \
715
 
        }                                                                                                                       \
716
 
        else                                                                                                            \
717
 
        {                                                                                                                       \
718
 
                int c = (P & F_C) ^ F_C;                                                                \
719
 
                int sum = A - tmp - c;                                                                  \
720
 
                P &= ~(F_V | F_C);                                                                              \
721
 
                if( (A^tmp) & (A^sum) & F_N )                                                   \
722
 
                        P |= F_V;                                                                                       \
723
 
                if( (sum & 0xff00) == 0 )                                                               \
724
 
                        P |= F_C;                                                                                       \
725
 
                A = (UINT8) sum;                                                                                \
726
 
                SET_NZ(A);                                                                                              \
727
 
        }
728
 
 
729
 
/* 6502 ********************************************************
730
 
 *  SEC Set carry flag
731
 
 ***************************************************************/
732
 
#if defined(SEC)
733
 
#undef SEC
734
 
#endif
735
 
#define SEC                                                                                                     \
736
 
        P |= F_C
737
 
 
738
 
/* 6502 ********************************************************
739
 
 *  SED Set decimal flag
740
 
 ***************************************************************/
741
 
#define SED                                                                                                     \
742
 
        P |= F_D
743
 
 
744
 
/* 6502 ********************************************************
745
 
 *  SEI Set interrupt flag
746
 
 ***************************************************************/
747
 
#define SEI                                                                                                     \
748
 
        P |= F_I
749
 
 
750
 
/* 6502 ********************************************************
751
 
 * STA  Store accumulator
752
 
 ***************************************************************/
753
 
#define STA                                                                                                     \
754
 
        tmp = A
755
 
 
756
 
/* 6502 ********************************************************
757
 
 * STX  Store index X
758
 
 ***************************************************************/
759
 
#define STX                                                                                                     \
760
 
        tmp = X
761
 
 
762
 
/* 6502 ********************************************************
763
 
 * STY  Store index Y
764
 
 ***************************************************************/
765
 
#define STY                                                                                                     \
766
 
        tmp = Y
767
 
 
768
 
/* 6502 ********************************************************
769
 
 * TAX  Transfer accumulator to index X
770
 
 ***************************************************************/
771
 
#define TAX                                                                                                     \
772
 
        X = A;                                                                                                          \
773
 
        SET_NZ(X)
774
 
 
775
 
/* 6502 ********************************************************
776
 
 * TAY  Transfer accumulator to index Y
777
 
 ***************************************************************/
778
 
#define TAY                                                                                                     \
779
 
        Y = A;                                                                                                          \
780
 
        SET_NZ(Y)
781
 
 
782
 
/* 6502 ********************************************************
783
 
 * TSX  Transfer stack LSB to index X
784
 
 ***************************************************************/
785
 
#define TSX                                                                                                     \
786
 
        X = S;                                                                                                          \
787
 
        SET_NZ(X)
788
 
 
789
 
/* 6502 ********************************************************
790
 
 * TXA  Transfer index X to accumulator
791
 
 ***************************************************************/
792
 
#define TXA                                                                                                     \
793
 
        A = X;                                                                                                          \
794
 
        SET_NZ(A)
795
 
 
796
 
/* 6502 ********************************************************
797
 
 * TXS  Transfer index X to stack LSB
798
 
 * no flags changed (sic!)
799
 
 ***************************************************************/
800
 
#define TXS                                                                                                     \
801
 
        S = X
802
 
 
803
 
/* 6502 ********************************************************
804
 
 * TYA  Transfer index Y to accumulator
805
 
 ***************************************************************/
806
 
#define TYA                                                                                                     \
807
 
        A = Y;                                                                                                          \
808
 
        SET_NZ(A)