registers.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. MSP430 Emulator
  3. Copyright (C) 2020 Rudolf Geosits (rgeosits@live.esu.edu)
  4. "MSP430 Emulator" is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. "MSP430 Emulator" is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef _REGISTERS_H_
  16. #define _REGISTERS_H_
  17. #include <stdlib.h>
  18. #include <stdint.h>
  19. #include <string.h>
  20. #include <stdbool.h>
  21. #include "../../main.h"
  22. /* r2 or SR, the status register */
  23. typedef struct Status_reg {
  24. uint8_t reserved : 7; // Reserved bits
  25. uint8_t overflow : 1; // Overflow flag
  26. uint8_t SCG1 : 1; // System Clock Generator SMCLK; ON = 0; OFF = 1;
  27. uint8_t SCG0 : 1; // System Clock Generator DCOCLK DCO ON = 0; DCO OFF = 1;
  28. uint8_t OSCOFF : 1; // Oscillator Off. LFXT1CLK ON = 0; LFXT1CLK OFF = 1;
  29. uint8_t CPUOFF : 1; // CPU off; CPU OFF = 1; CPU ON = 0;
  30. uint8_t GIE : 1; // General Inter enabl; Enbl maskable ints = 1; 0 = dont
  31. uint8_t negative : 1; // Negative flag
  32. uint8_t zero : 1; // Zero flag
  33. uint8_t carry : 1; // Carry flag; Set when result produces a carry
  34. } Status_reg;
  35. // Main CPU structure //
  36. typedef struct Cpu {
  37. bool running; /* CPU running or not */
  38. uint16_t pc, sp; /* R0 and R1 respectively */
  39. Status_reg sr; /* Status register fields */
  40. int16_t cg2; /* R3 or Constant Generator #2 */
  41. int16_t r4, r5, r6, r7; /* R4-R15 General Purpose Registers */
  42. int16_t r8, r9, r10, r11;
  43. int16_t r12, r13, r14, r15;
  44. Port_1 *p1;
  45. //Port_2 *p2;
  46. Usci *usci;
  47. Bcm *bcm;
  48. Timer_a *timer_a;
  49. } Cpu;
  50. uint16_t sr_to_value (Emulator *emu);
  51. void set_sr_value (Emulator *emu, uint16_t value);
  52. void initialize_msp_registers (Emulator *emu);
  53. void update_register_display (Emulator *emu);
  54. #endif