edd6d9ddbcc6d05228e3fb41faa43cf1d88b797b
[picodrive.git] / cpu / cz80 / cz80macro.h
1 /******************************************************************************\r
2 \r
3         cz80macro.h\r
4 \r
5         CZ80 \8ae\8eí\83}\83N\83\8d\r
6 \r
7 ******************************************************************************/\r
8 \r
9 #if CZ80_USE_JUMPTABLE\r
10 #define _SSOP(A,B)                      A##B\r
11 #define OP(A)                           _SSOP(OP,A)\r
12 #define OPCB(A)                         _SSOP(OPCB,A)\r
13 #define OPED(A)                         _SSOP(OPED,A)\r
14 #define OPXY(A)                         _SSOP(OPXY,A)\r
15 #define OPXYCB(A)                       _SSOP(OPXYCB,A)\r
16 #else\r
17 #define OP(A)                           case A\r
18 #define OPCB(A)                         case A\r
19 #define OPED(A)                         case A\r
20 #define OPXY(A)                         case A\r
21 #define OPXYCB(A)                       case A\r
22 #endif\r
23 \r
24 #define USE_CYCLES(A)           CPU->ICount -= (A);\r
25 #define ADD_CYCLES(A)           CPU->ICount += (A);\r
26 \r
27 #define RET(A)                          { USE_CYCLES(A) goto Cz80_Exec; }\r
28 \r
29 #if CZ80_ENCRYPTED_ROM\r
30 \r
31 #define SET_PC(A)                                                                                       \\r
32         CPU->BasePC = CPU->Fetch[(A) >> CZ80_FETCH_SFT];                \\r
33         OPBase = CPU->OPFetch[(A) >> CZ80_FETCH_SFT];                   \\r
34         PC = (A) + CPU->BasePC;\r
35 \r
36 #define GET_OP()                        (*(UINT8 *)(OPBase + PC))\r
37 \r
38 #else\r
39 \r
40 #define SET_PC(A)                                                                                       \\r
41         CPU->BasePC = CPU->Fetch[(A) >> CZ80_FETCH_SFT];                \\r
42         PC = (A) + CPU->BasePC;\r
43 \r
44 #define GET_OP()                        (*(UINT8 *)PC)\r
45 \r
46 #endif\r
47 \r
48 #define READ_OP()                       GET_OP(); PC++\r
49 \r
50 #define READ_ARG()                      (*(UINT8 *)PC++)\r
51 #define READ_ARG16()            (*(UINT8 *)PC | (*(UINT8 *)(PC + 1) << 8)); PC += 2\r
52 \r
53 //#ifndef BUILD_CPS1PSP\r
54 //#define READ_MEM8(A)          memory_region_cpu2[(A)]\r
55 //#else\r
56 #if PICODRIVE_HACKS\r
57 #define READ_MEM8(A)            picodrive_read(A)\r
58 #else\r
59 #define READ_MEM8(A)            CPU->Read_Byte(A)\r
60 #endif\r
61 //#endif\r
62 #define READ_MEM16(A)           (READ_MEM8(A) | (READ_MEM8((A) + 1) << 8))\r
63 \r
64 #if PICODRIVE_HACKS\r
65 #define WRITE_MEM8(A, D) { \\r
66         unsigned short a = A; \\r
67         unsigned char d = D; \\r
68         uptr v = z80_write_map[a >> Z80_MEM_SHIFT]; \\r
69         if (map_flag_set(v)) \\r
70                 ((z80_write_f *)(v << 1))(a, d); \\r
71         else \\r
72                 *(unsigned char *)((v << 1) + a) = d; \\r
73 }\r
74 #else\r
75 #define WRITE_MEM8(A, D)        CPU->Write_Byte(A, D);\r
76 #endif\r
77 #define WRITE_MEM16(A, D)       { WRITE_MEM8(A, D); WRITE_MEM8((A) + 1, (D) >> 8); }\r
78 \r
79 #define PUSH_16(A)                      { UINT32 sp; zSP -= 2; sp = zSP; WRITE_MEM16(sp, A); }\r
80 #define POP_16(A)                       { UINT32 sp; sp = zSP; A = READ_MEM16(sp); zSP = sp + 2; }\r
81 \r
82 #define IN(A)                           CPU->IN_Port(A)\r
83 #define OUT(A, D)                       CPU->OUT_Port(A, D)\r
84 \r
85 #define CHECK_INT                                                       \\r
86         if (zIFF1)                                                      \\r
87         {                                                               \\r
88                 UINT32 IntVect;                                         \\r
89                                                                         \\r
90                 if (CPU->IRQState == HOLD_LINE)                         \\r
91                         CPU->IRQState = CLEAR_LINE;                     \\r
92                                                                         \\r
93                 CPU->Status &= ~(CZ80_HALTED|CZ80_HAS_INT);             \\r
94                 zIFF1 = zIFF2 = 0;                                      \\r
95                 IntVect = CPU->Interrupt_Callback(CPU->IRQLine);        \\r
96                                                                         \\r
97                 PUSH_16(zRealPC)                                        \\r
98                                                                         \\r
99                 if (zIM == 2)                                           \\r
100                 {                                                       \\r
101                         IntVect = (IntVect & 0xff) | (zI << 8);         \\r
102                         PC = READ_MEM16(IntVect);                       \\r
103                         CPU->ExtraCycles += 17;                         \\r
104                 }                                                       \\r
105                 else if (zIM == 1)                                      \\r
106                 {                                                       \\r
107                         PC = 0x38;                                      \\r
108                         CPU->ExtraCycles += 13;                         \\r
109                 }                                                       \\r
110                 else                                                    \\r
111                 {                                                       \\r
112                         PC = IntVect & 0x38;                            \\r
113                         CPU->ExtraCycles += 13;                         \\r
114                 }                                                       \\r
115                                                                         \\r
116                 SET_PC(PC)                                              \\r
117         }\r