-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbops.c
executable file
·174 lines (168 loc) · 5.35 KB
/
cbops.c
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
/* Emulations of the CB operations of the Z80 instruction set.
* Copyright (C) 1994 Ian Collier.
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define var_t unsigned char t
#define rlc(x) (x=(x<<1)|(x>>7),rflags(x,x&1))
#define rrc(x) do{var_t=x&1;x=(x>>1)|(t<<7);rflags(x,t);}while(0)
#define rl(x) do{var_t=x>>7;x=(x<<1)|(f&1);rflags(x,t);}while(0)
#define rr(x) do{var_t=x&1;x=(x>>1)|(f<<7);rflags(x,t);}while(0)
#define sla(x) do{var_t=x>>7;x<<=1;rflags(x,t);}while(0)
#define sra(x) do{var_t=x&1;x=((signed char)x)>>1;rflags(x,t);}while(0)
#define sll(x) do{var_t=x>>7;x=(x<<1)|1;rflags(x,t);}while(0)
#define srl(x) do{var_t=x&1;x>>=1;rflags(x,t);}while(0)
#define rflags(x,c) (f=(c)|(x&0xa8)|((!x)<<6)|parity(x))
#define bit(n,x) (f=(f&1)|((x&(1<<n))?0x10:0x54)|(x&0x28))
#define set(n,x) (x|=(1<<n))
#define res(n,x) (x&=~(1<<n))
{
unsigned short addr;
unsigned char op,reg,val;
if(ixoriy){
addr=(ixoriy==1?ix:iy)+(signed char)fetchpc;
pc++;
INC_TSTATES(8);
op=fetchpc;
reg=op&7;
op=(op&0xf8)|6;
}
else{
op=fetchpc;
INC_TSTATES(4);
#ifndef NO_COUNT_TSTATES
radjust++;
#endif
addr=hl;
}
pc++;
if(op<64)switch(op){
case 0: rlc(b); break;
case 1: rlc(c); break;
case 2: rlc(d); break;
case 3: rlc(e); break;
case 4: rlc(h); break;
case 5: rlc(l); break;
case 6: INC_TSTATES(7);val=load(addr);rlc(val);store(addr,val);break;
case 7: rlc(a); break;
case 8: rrc(b); break;
case 9: rrc(c); break;
case 10: rrc(d); break;
case 11: rrc(e); break;
case 12: rrc(h); break;
case 13: rrc(l); break;
case 14: INC_TSTATES(7);val=load(addr);rrc(val);store(addr,val);break;
case 15: rrc(a); break;
case 0x10: rl(b); break;
case 0x11: rl(c); break;
case 0x12: rl(d); break;
case 0x13: rl(e); break;
case 0x14: rl(h); break;
case 0x15: rl(l); break;
case 0x16: INC_TSTATES(7);val=load(addr);rl(val);store(addr,val);break;
case 0x17: rl(a); break;
case 0x18: rr(b); break;
case 0x19: rr(c); break;
case 0x1a: rr(d); break;
case 0x1b: rr(e); break;
case 0x1c: rr(h); break;
case 0x1d: rr(l); break;
case 0x1e: INC_TSTATES(7);val=load(addr);rr(val);store(addr,val);break;
case 0x1f: rr(a); break;
case 0x20: sla(b); break;
case 0x21: sla(c); break;
case 0x22: sla(d); break;
case 0x23: sla(e); break;
case 0x24: sla(h); break;
case 0x25: sla(l); break;
case 0x26: INC_TSTATES(7);val=load(addr);sla(val);store(addr,val);break;
case 0x27: sla(a); break;
case 0x28: sra(b); break;
case 0x29: sra(c); break;
case 0x2a: sra(d); break;
case 0x2b: sra(e); break;
case 0x2c: sra(h); break;
case 0x2d: sra(l); break;
case 0x2e: INC_TSTATES(7);val=load(addr);sra(val);store(addr,val);break;
case 0x2f: sra(a); break;
case 0x30: sll(b); break;
case 0x31: sll(c); break;
case 0x32: sll(d); break;
case 0x33: sll(e); break;
case 0x34: sll(h); break;
case 0x35: sll(l); break;
case 0x36: INC_TSTATES(7);val=load(addr);sll(val);store(addr,val);break;
case 0x37: sll(a); break;
case 0x38: srl(b); break;
case 0x39: srl(c); break;
case 0x3a: srl(d); break;
case 0x3b: srl(e); break;
case 0x3c: srl(h); break;
case 0x3d: srl(l); break;
case 0x3e: INC_TSTATES(7);val=load(addr);srl(val);store(addr,val);break;
case 0x3f: srl(a); break;
}
else{
unsigned char n=(op>>3)&7;
switch(op&0xc7){
case 0x40: bit(n,b); break;
case 0x41: bit(n,c); break;
case 0x42: bit(n,d); break;
case 0x43: bit(n,e); break;
case 0x44: bit(n,h); break;
case 0x45: bit(n,l); break;
case 0x46: INC_TSTATES(4);val=load(addr);bit(n,val);/*store(addr,val);*/break;
case 0x47: bit(n,a); break;
case 0x80: res(n,b); break;
case 0x81: res(n,c); break;
case 0x82: res(n,d); break;
case 0x83: res(n,e); break;
case 0x84: res(n,h); break;
case 0x85: res(n,l); break;
case 0x86: INC_TSTATES(4);val=load(addr);res(n,val);store(addr,val);break;
case 0x87: res(n,a); break;
case 0xc0: set(n,b); break;
case 0xc1: set(n,c); break;
case 0xc2: set(n,d); break;
case 0xc3: set(n,e); break;
case 0xc4: set(n,h); break;
case 0xc5: set(n,l); break;
case 0xc6: INC_TSTATES(4);val=load(addr);set(n,val);store(addr,val);break;
case 0xc7: set(n,a); break;
}
}
if(ixoriy)switch(reg){
case 0:b=val; break;
case 1:c=val; break;
case 2:d=val; break;
case 3:e=val; break;
case 4:h=val; break;
case 5:l=val; break;
case 7:a=val; break;
}
}
#undef var_t
#undef rlc
#undef rrc
#undef rl
#undef rr
#undef sla
#undef sra
#undef sll
#undef srl
#undef rflags
#undef bit
#undef set
#undef res