Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / emu / rrgb / cbops.c
blob80a9f1ff3ebae3dfa78f6b5a99e66921918ff072
1 /* Emulations of the CB operations of the Z80 instruction set.
2 * Copyright (C) 1994 Ian Collier.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #define var_t unsigned char t
20 #define rlc(x) (x=(x<<1)|(x>>7),rflags(x,x&1))
21 #define rrc(x) do{var_t=x&1;x=(x>>1)|(t<<7);rflags(x,t);}while(0)
22 #define rl(x) do{var_t=x>>7;x=(x<<1)|(f&1);rflags(x,t);}while(0)
23 #define rr(x) do{var_t=x&1;x=(x>>1)|(f<<7);rflags(x,t);}while(0)
24 #define sla(x) do{var_t=x>>7;x<<=1;rflags(x,t);}while(0)
25 #define sra(x) do{var_t=x&1;x=((signed char)x)>>1;rflags(x,t);}while(0)
26 #define sll(x) do{var_t=x>>7;x=(x<<1)|1;rflags(x,t);}while(0)
27 #define srl(x) do{var_t=x&1;x>>=1;rflags(x,t);}while(0)
29 #define rflags(x,c) (f=(c)|(x&0xa8)|((!x)<<6))
31 #define bit(n,x) (f=(f&1)|((x&(1<<n))?0x10:0x54)|(x&0x28))
32 #define set(n,x) (x|=(1<<n))
33 #define res(n,x) (x&=~(1<<n))
34 #define nswap(n) (n=((n&0x0f)<<4) | (n>>4))
37 unsigned short addr;
38 unsigned char op,val;
39 op=fetch(pc);
40 tstates+=0;
41 radjust++;
42 addr=hl;
43 pc++;
45 if(op<64)switch(op){
46 case 0: rlc(b); break;
47 case 1: rlc(c); break;
48 case 2: rlc(d); break;
49 case 3: rlc(e); break;
50 case 4: rlc(h); break;
51 case 5: rlc(l); break;
52 case 6: tstates+=8;val=fetch(addr);rlc(val);store(addr,val);break;
53 case 7: rlc(a); break;
54 case 8: rrc(b); break;
55 case 9: rrc(c); break;
56 case 10: rrc(d); break;
57 case 11: rrc(e); break;
58 case 12: rrc(h); break;
59 case 13: rrc(l); break;
60 case 14: tstates+=8;val=fetch(addr);rrc(val);store(addr,val);break;
61 case 15: rrc(a); break;
62 case 0x10: rl(b); break;
63 case 0x11: rl(c); break;
64 case 0x12: rl(d); break;
65 case 0x13: rl(e); break;
66 case 0x14: rl(h); break;
67 case 0x15: rl(l); break;
68 case 0x16: tstates+=8;val=fetch(addr);rl(val);store(addr,val);break;
69 case 0x17: rl(a); break;
70 case 0x18: rr(b); break;
71 case 0x19: rr(c); break;
72 case 0x1a: rr(d); break;
73 case 0x1b: rr(e); break;
74 case 0x1c: rr(h); break;
75 case 0x1d: rr(l); break;
76 case 0x1e: tstates+=8;val=fetch(addr);rr(val);store(addr,val);break;
77 case 0x1f: rr(a); break;
78 case 0x20: sla(b); break;
79 case 0x21: sla(c); break;
80 case 0x22: sla(d); break;
81 case 0x23: sla(e); break;
82 case 0x24: sla(h); break;
83 case 0x25: sla(l); break;
84 case 0x26: tstates+=8;val=fetch(addr);sla(val);store(addr,val);break;
85 case 0x27: sla(a); break;
86 case 0x28: sra(b); break;
87 case 0x29: sra(c); break;
88 case 0x2a: sra(d); break;
89 case 0x2b: sra(e); break;
90 case 0x2c: sra(h); break;
91 case 0x2d: sra(l); break;
92 case 0x2e: tstates+=8;val=fetch(addr);sra(val);store(addr,val);break;
93 case 0x2f: sra(a); break;
94 case 0x30: nswap(b); break;
95 case 0x31: nswap(c); break;
96 case 0x32: nswap(d); break;
97 case 0x33: nswap(e); break;
98 case 0x34: nswap(h); break;
99 case 0x35: nswap(l); break;
100 case 0x36: tstates+=8;val=fetch(addr);nswap(val);store(addr,val);break;
101 case 0x37: nswap(a); break;
102 case 0x38: srl(b); break;
103 case 0x39: srl(c); break;
104 case 0x3a: srl(d); break;
105 case 0x3b: srl(e); break;
106 case 0x3c: srl(h); break;
107 case 0x3d: srl(l); break;
108 case 0x3e: tstates+=8;val=fetch(addr);srl(val);store(addr,val);break;
109 case 0x3f: srl(a); break;
111 else{
112 unsigned char n=(op>>3)&7;
113 switch(op&0xc7){
114 case 0x40: bit(n,b); break;
115 case 0x41: bit(n,c); break;
116 case 0x42: bit(n,d); break;
117 case 0x43: bit(n,e); break;
118 case 0x44: bit(n,h); break;
119 case 0x45: bit(n,l); break;
120 case 0x46: tstates+=8;val=fetch(addr);bit(n,val);store(addr,val);break;
121 case 0x47: bit(n,a); break;
122 case 0x80: res(n,b); break;
123 case 0x81: res(n,c); break;
124 case 0x82: res(n,d); break;
125 case 0x83: res(n,e); break;
126 case 0x84: res(n,h); break;
127 case 0x85: res(n,l); break;
128 case 0x86: tstates+=8;val=fetch(addr);res(n,val);store(addr,val);break;
129 case 0x87: res(n,a); break;
130 case 0xc0: set(n,b); break;
131 case 0xc1: set(n,c); break;
132 case 0xc2: set(n,d); break;
133 case 0xc3: set(n,e); break;
134 case 0xc4: set(n,h); break;
135 case 0xc5: set(n,l); break;
136 case 0xc6: tstates+=8;val=fetch(addr);set(n,val);store(addr,val);break;
137 case 0xc7: set(n,a); break;
142 #undef var_t
143 #undef rlc
144 #undef rrc
145 #undef rl
146 #undef rr
147 #undef sla
148 #undef sra
149 #undef sll
150 #undef srl
151 #undef rflags
152 #undef bit
153 #undef set
154 #undef res