Min před 4 roky
rodič
revize
e169d04c1f

+ 1 - 1
emulator/Makefile

@@ -18,7 +18,7 @@ _msp430emu.so: py_functions.o py_interface.o utilities.o registers.o memspace.o
 	usci.o port1.o bcm.o timer_a.o
 	$(CC) $(LLFLAGS) py_functions.o py_interface.o utilities.o registers.o memspace.o debugger.o disassembler.o \
 	register_display.o decoder.o flag_handler.o formatI.o formatII.o formatIII.o usci.o port1.o bcm.o timer_a.o \
-	-lreadline -lrt -lpthread -o _msp430emu.so -shared
+	-o _msp430emu.so -shared
 
 
 main.o : main.c

+ 24 - 0
emulator/devices/cpu/registers.h

@@ -29,27 +29,51 @@
 enum {
   P1_0_ON_PACKET  = 0x00,
   P1_0_OFF_PACKET = 0x01,
+  P1_0_PULLU_PACKET = 0x30,
+  P1_0_PULLD_PACKET = 0x31,
+  P1_0_HIGHZ_PACKET = 0x32,
 
   P1_1_ON_PACKET  = 0x02,
   P1_1_OFF_PACKET = 0x03,
+  P1_1_PULLU_PACKET = 0x33,
+  P1_1_PULLD_PACKET = 0x34,
+  P1_1_HIGHZ_PACKET = 0x35,
 
   P1_2_ON_PACKET  = 0x04,
   P1_2_OFF_PACKET = 0x05,
+  P1_2_PULLU_PACKET = 0x36,
+  P1_2_PULLD_PACKET = 0x37,
+  P1_2_HIGHZ_PACKET = 0x38,
 
   P1_3_ON_PACKET  = 0x06,
   P1_3_OFF_PACKET = 0x07,
+  P1_3_PULLU_PACKET = 0x39,
+  P1_3_PULLD_PACKET = 0x3A,
+  P1_3_HIGHZ_PACKET = 0x3B,
 
   P1_4_ON_PACKET  = 0x08,
   P1_4_OFF_PACKET = 0x09,
+  P1_4_PULLU_PACKET = 0x3C,
+  P1_4_PULLD_PACKET = 0x3D,
+  P1_4_HIGHZ_PACKET = 0x3E,
 
   P1_5_ON_PACKET  = 0x0A,
   P1_5_OFF_PACKET = 0x0B,
+  P1_5_PULLU_PACKET = 0x3F,
+  P1_5_PULLD_PACKET = 0x40,
+  P1_5_HIGHZ_PACKET = 0x41,
 
   P1_6_ON_PACKET  = 0x0C,
   P1_6_OFF_PACKET = 0x0D,
+  P1_6_PULLU_PACKET = 0x42,
+  P1_6_PULLD_PACKET = 0x43,
+  P1_6_HIGHZ_PACKET = 0x44,
 
   P1_7_ON_PACKET  = 0x0E,
   P1_7_OFF_PACKET = 0x0F,
+  P1_7_PULLU_PACKET = 0x45,
+  P1_7_PULLD_PACKET = 0x46,
+  P1_7_HIGHZ_PACKET = 0x47,
 
   UPDATE_REG_R0_PACKET = 0x10,
   UPDATE_REG_R1_PACKET = 0x11,

+ 1 - 1
emulator/devices/peripherals/bcm.c

@@ -31,7 +31,7 @@ uint64_t getnano() {
     LARGE_INTEGER now;
     QueryPerformanceCounter(&now);
     double x = (double)now.QuadPart / (double)frequency.QuadPart;
-    return (uint64_t)(x * 1.0e9);
+    return (uint64_t)(x * 1000000000.0);
 #else
     struct timespec now;
     clock_gettime(CLOCK_MONOTONIC, &now);

+ 60 - 27
emulator/devices/peripherals/port1.c

@@ -40,16 +40,28 @@ void handle_port_1 (Emulator *emu)
 {
     Cpu *cpu = emu->cpu;
     Port_1 *p = cpu->p1;
+    uint8_t flag = 0;
 
     //////////////////// P1.0 ////////////////////////
 
     // Check Direction
     if (*p->_DIR & 0x01) {
         p->DIR_0 = true;           // Set P1DIR.0 flag
-        if (*p->_OUT & 0x01)        // Check OUTPUT
-            p->OUT_0 = true;       // Set P1OUT.0 flag
-        else
-            p->OUT_0 = false;      // Reset P1OUT.0 flag
+
+        if(*p->_OUT & 0x01) {
+            if(p->OUT_0 == false) send_control(emu, P1_0_ON_PACKET, NULL, 0);
+            p->OUT_0 = true;  // Set P1OUT.0 flag
+        } else {
+            if(p->OUT_0 == true) send_control(emu, P1_0_OFF_PACKET, NULL, 0);
+            p->OUT_0 = false;// Reset P1OUT.0 flag
+        }
+
+
+
+//        if(((p->DIR_0 == false) && (*p->_DIR & 0x01)) || ((*p->_OUT & 0x01) != p->OUT_0)) {
+//            if (*p->_OUT & 0x01) send_control(emu, P1_0_ON_PACKET, NULL, 0);
+//            else send_control(emu, P1_0_OFF_PACKET, NULL, 0);
+//        }
     }
     // Check INPUT 
     else {
@@ -64,7 +76,7 @@ void handle_port_1 (Emulator *emu)
         // Check For Interrupt Pending 
         if (*p->_IFG & 0x01)
         {    
-            // Set p->IFG.0 flag indicating INT 
+            // Set p->IFG.0 flag indicating INT
             p->IFG_0 = true;
         }
         else
@@ -75,19 +87,22 @@ void handle_port_1 (Emulator *emu)
     else
     {
         p->IE_0 = false;
-    }    
+    }
+
+    if (*p->_REN & 0x01) p->REN_0 = true;
+    else p->REN_0 = false;
     
     // Check primary select
     if (*p->_SEL & 0x01) {
         if (p->SEL_0 == false) {
-            puts("P1_SEL_0 = 1");
+//            puts("P1_SEL_0 = 1");
         }
         
         p->SEL_0 = true;
     }
     else {
         if (p->SEL_0 == true) {
-            puts("P1_SEL_0 = 0");
+//            puts("P1_SEL_0 = 0");
         }
 
         p->SEL_0 = false;
@@ -96,19 +111,36 @@ void handle_port_1 (Emulator *emu)
     // Check secondary select
     if (*p->_SEL2 & 0x01) {
         if (p->SEL2_0 == false) {
-            puts("P1_SEL2_0 = 1");
+//            puts("P1_SEL2_0 = 1");
         }
-        
         p->SEL2_0 = true;
     }
     else {
         if (p->SEL2_0 == true) {
-            puts("P1_SEL2_0 = 0");
+//            puts("P1_SEL2_0 = 0");
         }
 
         p->SEL2_0 = false;        
     }
 
+//    if ((p->SEL2_0 == false) && (p->SEL_0 == false)) {
+//         // Output
+//         if(p->DIR_0 == false) {
+//            if(p->OUT_0 == true) flag = P1_0_ON_PACKET;
+//            else flag = P1_0_ON_PACKET;
+//         // Pull up/down enabled
+//         } else if(p->REN_0 == true) {
+//            if(p->OUT_0 == true) flag = P1_0_PULLU_PACKET;
+//            else flag = P1_0_PULLD_PACKET;
+//         } else {
+//            flag = P1_0_HIGHZ_PACKET;
+//         }
+//         if(flag != p->PIN0F) {
+//            p->PIN0F = flag;
+//            send_control(emu, flag, NULL, 0);
+//         }
+//    }
+
     //////////////////// P1.1 ////////////////////////
 
     // Check Direction and IN/OUT
@@ -143,14 +175,14 @@ void handle_port_1 (Emulator *emu)
     // Check primary select
     if (*p->_SEL & 0x02) {
         if (p->SEL_1 == false) {
-            puts("P1_SEL_1 = 1");
+//            puts("P1_SEL_1 = 1");
         }
 
         p->SEL_1 = true;
     }
     else {
         if (p->SEL_1 == true) {
-            puts("P1_SEL_1 = 0");
+//            puts("P1_SEL_1 = 0");
         }
 
         p->SEL_1 = false;
@@ -160,13 +192,13 @@ void handle_port_1 (Emulator *emu)
     if (*p->_SEL2 & 0x02) {
         if (p->SEL2_1 == false) {
             p->SEL2_1 = true;
-            puts("P1_SEL2_1 = 1");
+//            puts("P1_SEL2_1 = 1");
         }
     }
     else {
         if (p->SEL2_1 == true) {
             p->SEL2_1 = false;        
-            puts("P1_SEL2_1 = 0");
+//            puts("P1_SEL2_1 = 0");
         }
     }
 
@@ -213,7 +245,7 @@ void handle_port_1 (Emulator *emu)
     {
         if (p->SEL_2 == false) 
         {
-            puts("P1_SEL_2 = 1");
+//            puts("P1_SEL_2 = 1");
         }
         
         p->SEL_2 = true;
@@ -222,7 +254,7 @@ void handle_port_1 (Emulator *emu)
     {
         if (p->SEL_2 == true)
         {
-            puts("P1_SEL_2 = 0");
+//            puts("P1_SEL_2 = 0");
         }
 
         p->SEL_2 = false;
@@ -231,14 +263,14 @@ void handle_port_1 (Emulator *emu)
     // Check secondary select
     if (*p->_SEL2 & 0x04) {
         if (p->SEL2_2 == false) {
-            puts("P1_SEL2_2 = 1");
+//            puts("P1_SEL2_2 = 1");
         }
         
         p->SEL2_2 = true;
     }
     else {
         if (p->SEL2_2 == true) {
-            puts("P1_SEL2_2 = 0");
+//            puts("P1_SEL2_2 = 0");
         }
 
         p->SEL2_2 = false;        
@@ -339,15 +371,14 @@ void handle_port_1 (Emulator *emu)
     // Handler P1.6 
     if (*p->_DIR & 0x40)
     {
-        p->DIR_6 = true;
-        if (*p->_OUT & 0x40)
-        {
-            p->OUT_6 = true;
-        }
-        else
-        {
-            p->OUT_6 = false;
+        if(*p->_OUT & 0x40) {
+            if(p->OUT_6 == false) send_control(emu, P1_6_ON_PACKET, NULL, 0);
+            p->OUT_6 = true;  // Set P1OUT.6 flag
+        } else {
+            if(p->OUT_6 == true) send_control(emu, P1_6_OFF_PACKET, NULL, 0);
+            p->OUT_6 = false;// Reset P1OUT.6 flag
         }
+        p->DIR_6 = true;
     }
     else
     {
@@ -452,6 +483,8 @@ void setup_port_1 (Emulator *emu)
     
     p->DIR_7 = false; p->OUT_7 = false; p->IFG_7 = false; 
     p->IE_7 = false; p->SEL_7 = false; p->SEL2_7 = false;
+
+    p->PIN0F = P1_0_OFF_PACKET;
 }
 
 /* POWER UP CLEAR (PUC)      

+ 11 - 8
emulator/devices/peripherals/port1.h

@@ -37,14 +37,17 @@ struct Port_1 {
   uint8_t *_REN;  /* r/w     PUC reset */
 
   // Peripherals activation flags (for emulator)
-  bool DIR_0, OUT_0, IFG_0, IE_0, SEL_0, SEL2_0;
-  bool DIR_1, OUT_1, IFG_1, IE_1, SEL_1, SEL2_1;
-  bool DIR_2, OUT_2, IFG_2, IE_2, SEL_2, SEL2_2;
-  bool DIR_3, OUT_3, IFG_3, IE_3, SEL_3, SEL2_3;
-  bool DIR_4, OUT_4, IFG_4, IE_4, SEL_4, SEL2_4;
-  bool DIR_5, OUT_5, IFG_5, IE_5, SEL_5, SEL2_5;
-  bool DIR_6, OUT_6, IFG_6, IE_6, SEL_6, SEL2_6;
-  bool DIR_7, OUT_7, IFG_7, IE_7, SEL_7, SEL2_7;
+  bool DIR_0, OUT_0, IFG_0, IE_0, SEL_0, SEL2_0, REN_0;
+  bool DIR_1, OUT_1, IFG_1, IE_1, SEL_1, SEL2_1, REN_1;
+  bool DIR_2, OUT_2, IFG_2, IE_2, SEL_2, SEL2_2, REN_2;
+  bool DIR_3, OUT_3, IFG_3, IE_3, SEL_3, SEL2_3, REN_3;
+  bool DIR_4, OUT_4, IFG_4, IE_4, SEL_4, SEL2_4, REN_4;
+  bool DIR_5, OUT_5, IFG_5, IE_5, SEL_5, SEL2_5, REN_5;
+  bool DIR_6, OUT_6, IFG_6, IE_6, SEL_6, SEL2_6, REN_6;
+  bool DIR_7, OUT_7, IFG_7, IE_7, SEL_7, SEL2_7, REN_7;
+
+  // Pin flags
+  uint8_t PIN0F, PIN1F, PIN2F, PIN3F, PIN4F, PIN5F, PIN6F, PIN7F;
 
 };
 

+ 4 - 1
emulator/win.h

@@ -4,8 +4,11 @@
 #ifndef _WIN_H_
 #define _WIN_H_
 
-#define strncasecmp(x,y,z) _strnicmp(x,y,z)
+#ifdef _MSC_VER
 
+#define strncasecmp(x,y,z) _strnicmp(x,y,z)
 void usleep(__int64 usec);
 
+#endif
+
 #endif