0a5636c86788ac6760632199854120421d0ec495
[fw/sdcc] / sim / ucsim / sim.src / itsrc.cc
1 /*
2  * Simulator of microcontrollers (itsrc.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 #include <stdlib.h>
32 #include "i_string.h"
33
34 #include "itsrccl.h"
35 #include "pobjcl.h"
36 #include "stypes.h"
37
38
39 /*
40  * Interrupt source
41  ******************************************************************************
42  */
43
44 cl_it_src::cl_it_src(uchar Iie_mask,
45                      uchar Isrc_reg,
46                      uchar Isrc_mask,
47                      uint  Iaddr,
48                      bool  Iclr_bit,
49                      char  *Iname,
50                      int   apoll_priority):
51   cl_base()
52 {
53   poll_priority= apoll_priority;
54   ie_mask = Iie_mask;
55   src_reg = Isrc_reg;
56   src_mask= Isrc_mask;
57   addr    = Iaddr;
58   clr_bit = Iclr_bit;
59   if (Iname != NULL)
60     name= strdup(Iname);
61   else
62     name= strdup("unknown");
63   active= DD_TRUE;
64 }
65
66 cl_it_src::~cl_it_src(void)
67 {
68   free(name);
69 }
70
71 bool
72 cl_it_src::is_active(void)
73 {
74   return(active);
75 }
76
77 void
78 cl_it_src::set_active_status(bool Aactive)
79 {
80   active= Aactive;
81 }
82
83 void
84 cl_it_src::activate(void)
85 {
86   set_active_status(DD_TRUE);
87 }
88
89 void
90 cl_it_src::deactivate(void)
91 {
92   set_active_status(DD_FALSE);
93 }
94
95
96 /*
97  */
98
99 cl_irqs::cl_irqs(t_index alimit, t_index adelta):
100   cl_sorted_list(alimit, adelta)
101 {
102   Duplicates= DD_TRUE;
103 }
104
105 void *
106 cl_irqs::key_of(void *item)
107 {
108   class cl_it_src *itsrc= (class cl_it_src *)item;
109   return(&itsrc->poll_priority);
110 }
111
112 int
113 cl_irqs::compare(void *key1, void *key2)
114 {
115   int *k1= (int*)key1, *k2= (int*)key2;
116
117   if (*k1 == *k2)
118     return(0);
119   else if (*k1 < *k2)
120     return(-1);
121   return(1);
122 }
123
124
125 /*
126  * Interrupt level
127  ******************************************************************************
128  */
129
130 it_level::it_level(int alevel, uint aaddr, uint aPC, class cl_it_src *is):
131   cl_base()
132 {
133   level = alevel;
134   addr  = aaddr;
135   PC    = aPC;
136   source= is;
137 }
138
139
140
141 /* End of itsrc.cc */