From 84075f7a1709b2d05858dc5f866fb4e4eb385ce0 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sun, 17 Nov 2013 14:03:12 -0500 Subject: [PATCH] Move PSW bit manipulation functions to psw.c --- src/Makefile.am | 1 + src/memory.c | 40 ------------------------------- src/memory.h | 12 ---------- src/opcode2c.pl | 1 + src/psw.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ src/psw.h | 38 +++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 52 deletions(-) create mode 100644 src/psw.c create mode 100644 src/psw.h diff --git a/src/Makefile.am b/src/Makefile.am index 05c56da..4e1d98c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,7 @@ common_SOURCES = \ cpu8051.h \ memory.c \ memory.h \ + psw.c psw.h \ common.h \ reg8051.h diff --git a/src/memory.c b/src/memory.c index 44a2118..ac8bca5 100644 --- a/src/memory.c +++ b/src/memory.c @@ -183,46 +183,6 @@ stack_pop16(void) return value; } -void -psw_write_cy(int cy) -{ - u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_); - - if (cy) - psw |= 0x80; /* Set */ - else - psw &= ~0x80; /* Clear */ - - memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */ -} - -void -psw_set_cy(void) -{ - u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_); - - psw |= 0x80; - - memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */ -} - -void -psw_clr_cy(void) -{ - u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_); - - psw &= ~0x80; - - memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */ -} - -/* Returns 0 or 1 */ -int -psw_read_cy(void) -{ - return memory_read8(INT_MEM_ID, _PSW_) >> 7; -} - /* Dump memory */ void DumpMem(char *Address, char *Asize, int memory_id) diff --git a/src/memory.h b/src/memory.h index 451a5c3..c8761e9 100644 --- a/src/memory.h +++ b/src/memory.h @@ -79,18 +79,6 @@ stack_pop8(void); uint16_t stack_pop16(void); -void -psw_set_cy(void); - -void -psw_clr_cy(void); - -void -psw_write_cy(int cy); - -int -psw_read_cy(void); - void DumpMem(char *Address, char *Asize, int memory_id); diff --git a/src/opcode2c.pl b/src/opcode2c.pl index bbd1d7a..50c3794 100755 --- a/src/opcode2c.pl +++ b/src/opcode2c.pl @@ -51,6 +51,7 @@ print INST_IMP "#define INSTRUCTIONS_8051_M 1\n\n\n"; print INST_IMP "#include \"reg8051.h\"\n"; print INST_IMP "#include \"cpu8051.h\"\n"; print INST_IMP "#include \"memory.h\"\n"; +print INST_IMP "#include \"psw.h\"\n"; print INST_IMP "#include \"instructions_8051.h\"\n\n\n"; # Header for disasm.h diff --git a/src/psw.c b/src/psw.c new file mode 100644 index 0000000..2210d85 --- /dev/null +++ b/src/psw.c @@ -0,0 +1,63 @@ +/* + * psw.c + * + * Copyright (C) 2013 Hugo Villeneuve + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "common.h" +#include "reg8051.h" +#include "memory.h" + +void +psw_write_cy(int cy) +{ + u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_); + + if (cy) + psw |= 0x80; /* Set */ + else + psw &= ~0x80; /* Clear */ + + memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */ +} + +void +psw_set_cy(void) +{ + u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_); + + psw |= 0x80; + + memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */ +} + +void +psw_clr_cy(void) +{ + u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_); + + psw &= ~0x80; + + memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */ +} + +/* Returns 0 or 1 */ +int +psw_read_cy(void) +{ + return memory_read8(INT_MEM_ID, _PSW_) >> 7; +} diff --git a/src/psw.h b/src/psw.h new file mode 100644 index 0000000..78d700f --- /dev/null +++ b/src/psw.h @@ -0,0 +1,38 @@ +/* + * psw.h + * + * Copyright (C) 2013 Hugo Villeneuve + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef PSW_H +#define PSW_H 1 + +#include + +void +psw_set_cy(void); + +void +psw_clr_cy(void); + +void +psw_write_cy(int cy); + +int +psw_read_cy(void); + +#endif /* PSW_H */ -- 2.20.1