small fixes
[fw/sdcc] / sim / ucsim / xa.src / inst.cc
1 /*
2  * Simulator of microcontrollers (inst.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  *
6  * Written by Karl Bongers karl@turbobit.com
7  * 
8  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
9  *
10  */
11
12 /* This file is part of microcontroller simulator: ucsim.
13
14 UCSIM is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 UCSIM is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with UCSIM; see the file COPYING.  If not, write to the Free
26 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 02111-1307, USA. */
28 /*@1@*/
29
30 #include "ddconfig.h"
31
32 // local
33 #include "glob.h"
34 #include "xacl.h"
35 #include "regsxa.h"
36
37 int
38 cl_xa::get_reg(int word_flag, unsigned int index)
39 {
40   //if (index < 3) { /* banked */
41   //  if (word_flag)
42   //    return get_word_direct(0x400+index);
43   //  else
44   //    return mem_direct[0x400+index];
45   //} else { /* non-banked */
46     if (word_flag)
47       return get_word_direct(0x400+index);
48     else
49       return mem_direct[0x400+index];
50   //}
51 }
52
53 int
54 cl_xa::inst_NOP(uint code, int operands)
55 {
56   return(resGO);
57 }
58
59 #define RI_F0 ((code >> 4) & 0xf)
60 #define RI_70 ((code >> 4) & 0x7)
61 #define RI_0F (code & 0xf)
62 #define RI_07 (code & 0x7)
63
64 int
65 cl_xa::inst_ADD(uint code, int operands)
66 {
67 #undef FUNC1
68 #define FUNC1 add1
69 #undef FUNC2
70 #define FUNC2 add2
71 #include "inst_gen.cc"
72
73   return(resGO);
74 }
75
76 int
77 cl_xa::inst_ADDC(uint code, int operands)
78 {
79 #undef FUNC1
80 #define FUNC1 addc1
81 #undef FUNC2
82 #define FUNC2 addc2
83 #include "inst_gen.cc"
84
85   return(resGO);
86 }
87
88 int
89 cl_xa::inst_SUB(uint code, int operands)
90 {
91 #undef FUNC1
92 #define FUNC1 sub1
93 #undef FUNC2
94 #define FUNC2 sub2
95 #include "inst_gen.cc"
96   return(resGO);
97 }
98
99 int
100 cl_xa::inst_SUBB(uint code, int operands)
101 {
102 #undef FUNC1
103 #define FUNC1 subb1
104 #undef FUNC2
105 #define FUNC2 subb2
106 #include "inst_gen.cc"
107   return(resGO);
108 }
109
110 int
111 cl_xa::inst_CMP(uint code, int operands)
112 {
113 #undef FUNC1
114 #define FUNC1 cmp1
115 #undef FUNC2
116 #define FUNC2 cmp2
117 #include "inst_gen.cc"
118   return(resGO);
119 }
120 int
121 cl_xa::inst_AND(uint code, int operands)
122 {
123 #undef FUNC1
124 #define FUNC1 and1
125 #undef FUNC2
126 #define FUNC2 and2
127 #include "inst_gen.cc"
128   return(resGO);
129 }
130 int
131 cl_xa::inst_OR(uint code, int operands)
132 {
133 #undef FUNC1
134 #define FUNC1 or1
135 #undef FUNC2
136 #define FUNC2 or2
137 #include "inst_gen.cc"
138   return(resGO);
139 }
140 int
141 cl_xa::inst_XOR(uint code, int operands)
142 {
143 #undef FUNC1
144 #define FUNC1 xor1
145 #undef FUNC2
146 #define FUNC2 xor2
147 #include "inst_gen.cc"
148   return(resGO);
149 }
150 int
151 cl_xa::inst_ADDS(uint code, int operands)
152 {
153   return(resGO);
154 }
155 int
156 cl_xa::inst_NEG(uint code, int operands)
157 {
158   return(resGO);
159 }
160 int
161 cl_xa::inst_SEXT(uint code, int operands)
162 {
163   return(resGO);
164 }
165 int
166 cl_xa::inst_MUL(uint code, int operands)
167 {
168   return(resGO);
169 }
170 int
171 cl_xa::inst_DIV(uint code, int operands)
172 {
173   return(resGO);
174 }
175 int
176 cl_xa::inst_DA(uint code, int operands)
177 {
178   return(resGO);
179 }
180 int
181 cl_xa::inst_ASL(uint code, int operands)
182 {
183   return(resGO);
184 }
185 int
186 cl_xa::inst_ASR(uint code, int operands)
187 {
188   return(resGO);
189 }
190 int
191 cl_xa::inst_LEA(uint code, int operands)
192 {
193   return(resGO);
194 }
195 int
196 cl_xa::inst_CPL(uint code, int operands)
197 {
198   return(resGO);
199 }
200 int
201 cl_xa::inst_LSR(uint code, int operands)
202 {
203   return(resGO);
204 }
205 int
206 cl_xa::inst_NORM(uint code, int operands)
207 {
208   return(resGO);
209 }
210 int
211 cl_xa::inst_RL(uint code, int operands)
212 {
213   return(resGO);
214 }
215 int
216 cl_xa::inst_RLC(uint code, int operands)
217 {
218   return(resGO);
219 }
220 int
221 cl_xa::inst_RR(uint code, int operands)
222 {
223   return(resGO);
224 }
225 int
226 cl_xa::inst_RRC(uint code, int operands)
227 {
228   return(resGO);
229 }
230 int
231 cl_xa::inst_MOVS(uint code, int operands)
232 {
233   return(resGO);
234 }
235 int
236 cl_xa::inst_MOVC(uint code, int operands)
237 {
238   switch (operands) {
239     case REG_IREGINC:
240     {
241       short srcreg = reg2(RI_07);
242       if (code & 0x0800) {  /* word op */
243         set_reg2( RI_F0,
244                   mov2( reg2(RI_F0),
245                         getcode2(srcreg)
246                       )
247                 );
248       } else {
249         set_reg1( RI_F0,
250                   mov1( reg1(RI_F0),
251                         getcode1(srcreg)
252                       )
253                 );
254       }
255       if (operands == REG_IREGINC) {
256         set_reg2(RI_07,  srcreg+1);
257       }
258     }
259     break;
260     // fixme, 2 more
261   }
262   return(resGO);
263 }
264 int
265 cl_xa::inst_MOVX(uint code, int operands)
266 {
267   return(resGO);
268 }
269 int
270 cl_xa::inst_PUSH(uint code, int operands)
271 {
272   switch(operands) {
273     case DIRECT_ALONE:
274     {
275       unsigned short sp;
276       unsigned short direct_addr = ((operands & 0x7) << 8) | fetch();
277
278       sp = get_sp()-2;
279       set_sp(sp);
280       if (code & 0x0800) {  /* word op */
281         store2( sp, get_word_direct(direct_addr));
282       } else {
283         store2( sp, get_byte_direct(direct_addr));
284       }
285     }
286     break;
287
288     case RLIST:
289       // fixme: implement
290       unsigned char rlist = fetch();
291       rlist = rlist; //shutup compiler
292     break;
293   }
294   
295   return(resGO);
296 }
297 int
298 cl_xa::inst_POP(uint code, int operands)
299 {
300   switch(operands) {
301     case DIRECT_ALONE:
302     {
303       unsigned short sp;
304       unsigned short direct_addr = ((operands & 0x7) << 8) | fetch();
305
306       sp = get_sp();
307       if (code & 0x0800) {  /* word op */
308         set_word_direct(direct_addr, get2(sp) );
309       } else {
310         set_byte_direct(direct_addr, get2(sp) & 0xff );
311       }
312       set_sp(sp+2);
313     }
314     break;
315
316     case RLIST:
317       // fixme: implement
318       unsigned char rlist = fetch();
319       rlist = rlist; //shutup compiler
320     break;
321   }
322   return(resGO);
323 }
324 int
325 cl_xa::inst_XCH(uint code, int operands)
326 {
327   return(resGO);
328 }
329 int
330 cl_xa::inst_SETB(uint code, int operands)
331 {
332   unsigned short bitAddr = (code&0x03 << 8) + fetch();
333   // fixme: implement
334   bitAddr=bitAddr;
335   return(resGO);
336 }
337 int
338 cl_xa::inst_CLR(uint code, int operands)
339 {
340   unsigned short bitAddr = (code&0x03 << 8) + fetch();
341   // fixme: implement
342   bitAddr=bitAddr;
343   return(resGO);
344 }
345 int
346 cl_xa::inst_MOV(uint code, int operands)
347 {
348 #undef FUNC1
349 #define FUNC1 mov1
350 #undef FUNC2
351 #define FUNC2 mov2
352 #include "inst_gen.cc"
353   return(resGO);
354 }
355 int
356 cl_xa::inst_ANL(uint code, int operands)
357 {
358   return(resGO);
359 }
360 int
361 cl_xa::inst_ORL(uint code, int operands)
362 {
363   return(resGO);
364 }
365 int
366 cl_xa::inst_BEQ(uint code, int operands)
367 {
368   short jmpAddr = fetch1()*2;
369   if (get_psw() & BIT_Z) {
370     PC=(PC+jmpAddr)&0xfffffffe;
371   }
372   return(resGO);
373 }
374 int
375 cl_xa::inst_BR(uint code, int operands)
376 {
377   short jmpAddr = fetch1()*2;
378   PC=(PC+jmpAddr)&0xfffffffe;
379   return(resGO);
380 }
381 int
382 cl_xa::inst_JMP(uint code, int operands)
383 {
384   unsigned int jmpaddr;
385   short saddr;
386
387   switch(operands) {
388     case REL16:
389     {
390       saddr = fetch2();
391       jmpaddr = saddr;
392       jmpaddr *= 2;
393       PC = (PC + jmpaddr) & 0xfffffffe;
394     }
395     break;
396     case IREG:
397       PC &= 0xffff0000;
398       PC |= (reg2(RI_07) & 0xfffe);  /* word aligned */
399     break;
400     /* fixme 2 more... */
401   }
402   return(resGO);
403 }
404 int
405 cl_xa::inst_CALL(uint code, int operands)
406 {
407   unsigned int jmpaddr;
408   unsigned int sp;
409
410   switch(operands) {
411     case REL16:
412     {
413       jmpaddr = fetch2();
414       sp = get_sp() - 4;
415       set_sp(sp);
416       store2(sp, PC);
417       store2(sp+2, 0);  /* segment(not sure about ordering...) */
418       jmpaddr *= 2;
419       PC = (PC + jmpaddr) & 0xfffffffe;
420     }
421     break;
422     case IREG:
423     {
424       sp = get_sp() - 4;
425       set_sp(sp);
426       store2(sp, PC);
427       store2(sp+2, 0);  /* segment(not sure about ordering...) */
428       jmpaddr = reg2(RI_07);
429       jmpaddr *= 2;
430       PC = (PC + jmpaddr) & 0xfffffffe;
431     }
432     break;
433     /* fixme 2 more... */
434   }
435   return(resGO);
436 }
437 int
438 cl_xa::inst_RET(uint code, int operands)
439 {
440   unsigned int retaddr;
441   unsigned short sp;
442   sp = get_sp();
443   retaddr = get2(sp);
444   //retaddr |= get2(sp+2) << 16);
445   PC = retaddr;
446   return(resGO);
447 }
448 int
449 cl_xa::inst_Bcc(uint code, int operands)
450 {
451   return(resGO);
452 }
453 int
454 cl_xa::inst_JB(uint code, int operands)
455 {
456   return(resGO);
457 }
458 int
459 cl_xa::inst_JNB(uint code, int operands)
460 {
461   return(resGO);
462 }
463 int
464 cl_xa::inst_CJNE(uint code, int operands)
465 {
466   return(resGO);
467 }
468 int
469 cl_xa::inst_DJNZ(uint code, int operands)
470 {
471   return(resGO);
472 }
473 int
474 cl_xa::inst_JZ(uint code, int operands)
475 {
476   short saddr = (fetch1() * 2);
477   if (reg1(8)==0) {
478       PC += saddr;
479   }
480   return(resGO);
481 }
482 int
483 cl_xa::inst_JNZ(uint code, int operands)
484 {
485   short saddr = (fetch1() * 2);
486   if (reg1(8)!=0) {
487     PC = (PC + saddr) & 0xfffffe;
488   }
489   return(resGO);
490 }
491 int
492 cl_xa::inst_BKPT(uint code, int operands)
493 {
494   return(resGO);
495 }
496 int
497 cl_xa::inst_TRAP(uint code, int operands)
498 {
499   return(resGO);
500 }
501 int
502 cl_xa::inst_RESET(uint code, int operands)
503 {
504   return(resGO);
505 }
506
507
508 /* End of xa.src/inst.cc */