along with simavr. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef SIM_CORE_H_
-#define SIM_CORE_H_
+#ifndef __SIM_CORE_H__
+#define __SIM_CORE_H__
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ * Reconstructs the SREG value from avr->sreg into dst.
+ */
+#define READ_SREG_INTO(avr, dst) { \
+ dst = 0; \
+ for (int i = 0; i < 8; i++) \
+ if (avr->sreg[i] > 1) { \
+ printf("** Invalid SREG!!\n"); \
+ } else if (avr->sreg[i]) \
+ dst |= (1 << i); \
+ }
+
+/**
+ * Splits the SREG value from src into the avr->sreg array.
+ */
+#define SET_SREG_FROM(avr, src) { \
+ for (int i = 0; i < 8; i++) \
+ avr->sreg[i] = (src & (1 << i)) != 0; \
+ }
+
#ifdef __cplusplus
};
#endif
-#endif /* SIM_CORE_H_ */
+#endif /*__SIM_CORE_H__*/