Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / s51.src / uc52.cc
1 /*
2  * Simulator of microcontrollers (uc52.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 #include <stdio.h>
31
32 // local
33 #include "uc52cl.h"
34 #include "regs51.h"
35 #include "timer2cl.h"
36
37
38 /*
39  * Making an 8052 CPU object
40  */
41
42 cl_uc52::cl_uc52(int Itype, int Itech, class cl_sim *asim):
43   cl_51core(Itype, Itech, asim)
44 {
45 }
46
47
48 void
49 cl_uc52::mk_hw_elements(void)
50 {
51   class cl_hw *h;
52
53   cl_51core::mk_hw_elements();
54   hws->add(h= new cl_timer2(this, 2, "timer2", t2_default|t2_down));
55   h->init();
56 }
57
58 void
59 cl_uc52::make_memories(void)
60 {
61   class cl_address_space *as;
62
63   rom= as= new cl_address_space("rom", 0, 0x10000, 8);
64   as->init();
65   address_spaces->add(as);
66   iram= as= new cl_address_space("iram", 0, 0x100, 8);
67   as->init();
68   address_spaces->add(as);
69   sfr= as= new cl_address_space("sfr", 0x80, 0x80, 8);
70   as->init();
71   address_spaces->add(as);
72   xram= as= new cl_address_space("xram", 0, 0x10000, 8);
73   as->init();
74   address_spaces->add(as);
75
76   class cl_address_decoder *ad;
77   class cl_memory_chip *chip;
78
79   chip= new cl_memory_chip("rom_chip", 0x10000, 8);
80   chip->init();
81   memchips->add(chip);
82   ad= new cl_address_decoder(as= address_space("rom"), chip, 0, 0xffff, 0);
83   ad->init();
84   as->decoders->add(ad);
85   ad->activate(0);
86
87   chip= new cl_memory_chip("iram_chip", 0x100, 8);
88   chip->init();
89   memchips->add(chip);
90   ad= new cl_address_decoder(as= address_space("iram"), chip, 0, 0xff, 0);
91   ad->init();
92   as->decoders->add(ad);
93   ad->activate(0);
94
95   chip= new cl_memory_chip("xram_chip", 0x10000, 8);
96   chip->init();
97   memchips->add(chip);
98   ad= new cl_address_decoder(as= address_space("xram"), chip, 0, 0xffff, 0);
99   ad->init();
100   as->decoders->add(ad);
101   ad->activate(0);
102
103   chip= new cl_memory_chip("sfr_chip", 0x80, 8);
104   chip->init();
105   memchips->add(chip);
106   ad= new cl_address_decoder(as= address_space("sfr"), chip, 0x80, 0xff, 0);
107   ad->init();
108   as->decoders->add(ad);
109   ad->activate(0);
110
111   acc= sfr->get_cell(ACC);
112   psw= sfr->get_cell(PSW);
113 }
114
115
116 void
117 cl_uc52::clear_sfr(void)
118 {
119   cl_51core::clear_sfr();
120   sfr->write(T2CON, 0);
121   sfr->write(TH2, 0);
122   sfr->write(TL2, 0);
123   sfr->write(RCAP2L, 0);
124   sfr->write(RCAP2H, 0);
125 }
126
127
128 /*
129  * Calculating address of indirectly addressed IRAM cell
130  *
131  */
132
133 class cl_memory_cell *
134 cl_uc52::get_indirect(uchar addr, int *res)
135 {
136   *res= resGO;
137   return(iram->get_cell(addr));
138 }
139
140
141 /* End of s51.src/uc52.cc */