cue/bin finally implemented
[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 #if CZ80_LITTLE_ENDIAN\r
52 #define READ_ARG16()            (*(UINT8 *)PC | (*(UINT8 *)(PC + 1) << 8)); PC += 2\r
53 #else\r
54 #define READ_ARG16()            (*(UINT8 *)(PC + 1) | (*(UINT8 *)PC << 8)); PC += 2\r
55 #endif\r
56 \r
57 //#ifndef BUILD_CPS1PSP\r
58 //#define READ_MEM8(A)          memory_region_cpu2[(A)]\r
59 //#else\r
60 #if PICODRIVE_HACKS\r
61 #define READ_MEM8(A)            picodrive_read(A)\r
62 #else\r
63 #define READ_MEM8(A)            CPU->Read_Byte(A)\r
64 #endif\r
65 //#endif\r
66 #if CZ80_LITTLE_ENDIAN\r
67 #define READ_MEM16(A)           (READ_MEM8(A) | (READ_MEM8((A) + 1) << 8))\r
68 #else\r
69 #define READ_MEM16(A)           ((READ_MEM8(A) << 8) | READ_MEM8((A) + 1))\r
70 #endif\r
71 \r
72 #if PICODRIVE_HACKS\r
73 #define WRITE_MEM8(A, D) { \\r
74         unsigned short a = A; \\r
75         unsigned char d = D; \\r
76         if (a < 0x4000) Pico.zram[a&0x1fff] = d; \\r
77         else z80_write(a, d); \\r
78 }\r
79 #else\r
80 #define WRITE_MEM8(A, D)        CPU->Write_Byte(A, D);\r
81 #endif\r
82 #if CZ80_LITTLE_ENDIAN\r
83 #define WRITE_MEM16(A, D)       { WRITE_MEM8(A, D); WRITE_MEM8((A) + 1, (D) >> 8); }\r
84 #else\r
85 #define WRITE_MEM16(A, D)       { WRITE_MEM8((A) + 1, D); WRITE_MEM8(A, (D) >> 8); }\r
86 #endif\r
87 \r
88 #define PUSH_16(A)                      { UINT32 sp; zSP -= 2; sp = zSP; WRITE_MEM16(sp, A); }\r
89 #define POP_16(A)                       { UINT32 sp; sp = zSP; A = READ_MEM16(sp); zSP = sp + 2; }\r
90 \r
91 #define IN(A)                           CPU->IN_Port(A)\r
92 #define OUT(A, D)                       CPU->OUT_Port(A, D)\r
93 \r
94 #define CHECK_INT                                                                                                       \\r
95         if (zIFF1)                                                                                                              \\r
96         {                                                                                                                               \\r
97                 UINT32 IntVect;                                                                                         \\r
98                                                                                                                                         \\r
99                 if (CPU->IRQState == HOLD_LINE)                                                         \\r
100                         CPU->IRQState = CLEAR_LINE;                                                             \\r
101                                                                                                                                         \\r
102                 CPU->HaltState = 0;                                                                                     \\r
103                 zIFF1 = zIFF2 = 0;                                                                                      \\r
104                 IntVect = CPU->Interrupt_Callback(CPU->IRQLine);                        \\r
105                                                                                                                                         \\r
106                 PUSH_16(zRealPC)                                                                                        \\r
107                                                                                                                                         \\r
108                 if (zIM == 2)                                                                                           \\r
109                 {                                                                                                                       \\r
110                         IntVect = (IntVect & 0xff) | (zI << 8);                                 \\r
111                         PC = READ_MEM16(IntVect);                                                               \\r
112                         CPU->ExtraCycles += 17;                                                                 \\r
113                 }                                                                                                                       \\r
114                 else if (zIM == 1)                                                                                      \\r
115                 {                                                                                                                       \\r
116                         PC = 0x38;                                                                                              \\r
117                         CPU->ExtraCycles += 13;                                                                 \\r
118                 }                                                                                                                       \\r
119                 else                                                                                                            \\r
120                 {                                                                                                                       \\r
121                         PC = IntVect & 0x38;                                                                    \\r
122                         CPU->ExtraCycles += 13;                                                                 \\r
123                 }                                                                                                                       \\r
124                                                                                                                                         \\r
125                 SET_PC(PC)                                                                                                      \\r
126         }\r