simulavr  1.1.0
hwsreg.cpp
Go to the documentation of this file.
1  /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #include "hwsreg.h"
27 
28 #include <iostream>
29 using namespace std;
30 
31 HWSreg_bool::operator int() {
32  return C + (Z << 1) + (N << 2) + (V << 3) + (S << 4) + (H << 5) + (T << 6) + (I << 7);
33 }
34 
35 HWSreg_bool::HWSreg_bool(const int i) {
36  C = i &0x01;
37  Z = (i & 0x02) > 1;
38  N = (i & 0x04) > 2;
39  V = (i & 0x08) > 3;
40  S = (i & 0x10) > 4;
41  H = (i & 0x20) > 5;
42  T = (i & 0x40) > 6;
43  I = (i & 0x80) > 7;
44 }
45 
47  C = Z = N = V = S = H = T = I = 0;
48 }
49 
50 HWSreg::operator string() {
51  string s("SREG=[");
52  if(I) s += "I"; else s += "-";
53  if(T) s += "T"; else s += "-";
54  if(H) s += "H"; else s += "-";
55  if(S) s += "S"; else s += "-";
56  if(V) s += "V"; else s += "-";
57  if(N) s += "N"; else s += "-";
58  if(Z) s += "Z"; else s += "-";
59  if(C) s += "C"; else s += "-";
60  s += "] ";
61  return s;
62 }
63 
64 HWSreg HWSreg::operator =(const int i) {
65  C = i & 0x01;
66  Z = (i & 0x02) > 1;
67  N = (i & 0x04) > 2;
68  V = (i & 0x08) > 3;
69  S = (i & 0x10) > 4;
70  H = (i & 0x20) > 5;
71  T = (i & 0x40) > 6;
72  I = (i & 0x80) > 7;
73  return *this;
74 }
75 
76 unsigned char RWSreg::get() const {
77  return (*status);
78 }
79 
80 void RWSreg::set(unsigned char val) {
81  *status = val;
82 }
83 
84 // EOF
HWSreg_bool()
Definition: hwsreg.cpp:46
unsigned char get() const
Definition: hwsreg.cpp:76
HWSreg operator=(const int)
Definition: hwsreg.cpp:64
STL namespace.
Definition: hwsreg.h:52
void set(unsigned char)
Definition: hwsreg.cpp:80