registers.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "../../emulator.h"
  22. enum {
  23. P1_0_ON_PACKET = 0x00,
  24. P1_0_OFF_PACKET = 0x01,
  25. P1_0_PULLU_PACKET = 0x30,
  26. P1_0_PULLD_PACKET = 0x31,
  27. P1_0_HIGHZ_PACKET = 0x32,
  28. P1_1_ON_PACKET = 0x02,
  29. P1_1_OFF_PACKET = 0x03,
  30. P1_1_PULLU_PACKET = 0x33,
  31. P1_1_PULLD_PACKET = 0x34,
  32. P1_1_HIGHZ_PACKET = 0x35,
  33. P1_2_ON_PACKET = 0x04,
  34. P1_2_OFF_PACKET = 0x05,
  35. P1_2_PULLU_PACKET = 0x36,
  36. P1_2_PULLD_PACKET = 0x37,
  37. P1_2_HIGHZ_PACKET = 0x38,
  38. P1_3_ON_PACKET = 0x06,
  39. P1_3_OFF_PACKET = 0x07,
  40. P1_3_PULLU_PACKET = 0x39,
  41. P1_3_PULLD_PACKET = 0x3A,
  42. P1_3_HIGHZ_PACKET = 0x3B,
  43. P1_4_ON_PACKET = 0x08,
  44. P1_4_OFF_PACKET = 0x09,
  45. P1_4_PULLU_PACKET = 0x3C,
  46. P1_4_PULLD_PACKET = 0x3D,
  47. P1_4_HIGHZ_PACKET = 0x3E,
  48. P1_5_ON_PACKET = 0x0A,
  49. P1_5_OFF_PACKET = 0x0B,
  50. P1_5_PULLU_PACKET = 0x3F,
  51. P1_5_PULLD_PACKET = 0x40,
  52. P1_5_HIGHZ_PACKET = 0x41,
  53. P1_6_ON_PACKET = 0x0C,
  54. P1_6_OFF_PACKET = 0x0D,
  55. P1_6_PULLU_PACKET = 0x42,
  56. P1_6_PULLD_PACKET = 0x43,
  57. P1_6_HIGHZ_PACKET = 0x44,
  58. P1_7_ON_PACKET = 0x0E,
  59. P1_7_OFF_PACKET = 0x0F,
  60. P1_7_PULLU_PACKET = 0x45,
  61. P1_7_PULLD_PACKET = 0x46,
  62. P1_7_HIGHZ_PACKET = 0x47,
  63. UPDATE_REG_R0_PACKET = 0x10,
  64. UPDATE_REG_R1_PACKET = 0x11,
  65. UPDATE_REG_R2_PACKET = 0x12,
  66. UPDATE_REG_R3_PACKET = 0x13,
  67. UPDATE_REG_R4_PACKET = 0x14,
  68. UPDATE_REG_R5_PACKET = 0x15,
  69. UPDATE_REG_R6_PACKET = 0x16,
  70. UPDATE_REG_R7_PACKET = 0x17,
  71. UPDATE_REG_R8_PACKET = 0x18,
  72. UPDATE_REG_R9_PACKET = 0x19,
  73. UPDATE_REG_R10_PACKET = 0x1A,
  74. UPDATE_REG_R11_PACKET = 0x1B,
  75. UPDATE_REG_R12_PACKET = 0x1C,
  76. UPDATE_REG_R13_PACKET = 0x1D,
  77. UPDATE_REG_R14_PACKET = 0x1E,
  78. UPDATE_REG_R15_PACKET = 0x1F,
  79. UPDATE_ALL_REGS_PACKET = 0x20,
  80. SERVO_MOTOR = 0x21,
  81. };
  82. /* r2 or SR, the status register */
  83. typedef struct Status_reg {
  84. uint8_t reserved : 7; // Reserved bits
  85. uint8_t overflow : 1; // Overflow flag
  86. uint8_t SCG1 : 1; // System Clock Generator SMCLK; ON = 0; OFF = 1;
  87. uint8_t SCG0 : 1; // System Clock Generator DCOCLK DCO ON = 0; DCO OFF = 1;
  88. uint8_t OSCOFF : 1; // Oscillator Off. LFXT1CLK ON = 0; LFXT1CLK OFF = 1;
  89. uint8_t CPUOFF : 1; // CPU off; CPU OFF = 1; CPU ON = 0;
  90. uint8_t GIE : 1; // General Inter enabl; Enbl maskable ints = 1; 0 = dont
  91. uint8_t negative : 1; // Negative flag
  92. uint8_t zero : 1; // Zero flag
  93. uint8_t carry : 1; // Carry flag; Set when result produces a carry
  94. } Status_reg;
  95. // Main CPU structure //
  96. typedef struct Cpu {
  97. bool running; /* CPU running or not */
  98. uint16_t pc, sp; /* R0 and R1 respectively */
  99. Status_reg sr; /* Status register fields */
  100. int16_t cg2; /* R3 or Constant Generator #2 */
  101. int16_t r4, r5, r6, r7; /* R4-R15 General Purpose Registers */
  102. int16_t r8, r9, r10, r11;
  103. int16_t r12, r13, r14, r15;
  104. Port_1 *p1;
  105. //Port_2 *p2;
  106. Usci *usci;
  107. Bcm *bcm;
  108. Timer_a *timer_a;
  109. uint16_t interrupt;
  110. uint64_t nsecs; // nanoseconds since emulator started;
  111. } Cpu;
  112. uint16_t sr_to_value (Emulator *emu);
  113. void set_sr_value (Emulator *emu, uint16_t value);
  114. void initialize_msp_registers (Emulator *emu);
  115. void update_register_display (Emulator *emu);
  116. void cpu_step (Emulator *emu);
  117. void cpu_reset (Emulator *emu);
  118. #endif