Bläddra i källkod

Add code to generate the state change table

Baglio Tabifata 4 år sedan
förälder
incheckning
43bab22f89
1 ändrade filer med 73 tillägg och 3 borttagningar
  1. 73 3
      src/net/hkzlab/dupal/boardio/DuPALAnalyzer.java

+ 73 - 3
src/net/hkzlab/dupal/boardio/DuPALAnalyzer.java

@@ -102,7 +102,8 @@ public class DuPALAnalyzer {
         if(serObjPath != null) saveStatus(serObjPath);
         if(serObjPath != null) saveStatus(serObjPath);
 
 
         //try { printStateStructure(System.out, pspecs, mStates); } catch(IOException e){};
         //try { printStateStructure(System.out, pspecs, mStates); } catch(IOException e){};
-        try { printLogicTableOUTPUTS(System.out, pspecs, additionalOUTs, IOasOUT_Mask, mStates); } catch(IOException e){};
+        //try { printLogicTableOUTPUTS(System.out, pspecs, additionalOUTs, IOasOUT_Mask, mStates); } catch(IOException e){};
+        try { printLogicTableREGOUTPUTS(System.out, pspecs, additionalOUTs, IOasOUT_Mask, mStates); } catch(IOException e){};
     }
     }
 
 
     private int guessIOs() {
     private int guessIOs() {
@@ -515,6 +516,73 @@ public class DuPALAnalyzer {
         }
         }
     }
     }
 
 
+    static private void printLogicTableREGOUTPUTS(OutputStream out, PALSpecs specs, int additionalOUTs, int ioOUTMask, MacroState[] mStates) throws IOException {
+        out.write(("# OUTPUT logic table\n").getBytes(StandardCharsets.US_ASCII));
+        int totInputs = specs.getNumINPins() + (specs.getNumIOPins() - additionalOUTs);
+        StringBuffer strBuf = new StringBuffer();
+
+        out.write((".i " + (totInputs + specs.getNumROUTPins()) + "\n").getBytes(StandardCharsets.US_ASCII));
+        out.write((".o " + specs.getNumROUTPins() + "\n").getBytes(StandardCharsets.US_ASCII)); // * 2 because we get both an output and its OE state
+        
+        // Input labels
+        strBuf.delete(0, strBuf.length()); 
+        strBuf.append(".ilb ");
+        for(int idx = 0; idx < specs.getNumROUTPins(); idx++) {
+            strBuf.append(specs.getROUT_PinNames()[idx]+"_old ");
+        }
+        for(int idx = 0; idx < specs.getNumINPins(); idx++) {
+            strBuf.append(specs.getIN_PinNames()[idx]+" ");
+        }
+        if(totInputs > specs.getNumINPins()) {
+            int ioINMask = specs.getIO_READMask() & ~ioOUTMask;
+            for(int idx = 0; idx < 8; idx++) {
+                if(((ioINMask >> idx) & 0x01) > 0) strBuf.append(specs.getIO_PinNames()[idx] + " ");
+            }
+        }
+        strBuf.append('\n');
+        out.write(strBuf.toString().getBytes(StandardCharsets.US_ASCII));
+
+        // Output labels
+        strBuf.delete(0, strBuf.length());
+        strBuf.append(".ob ");
+        for(int idx = 0; idx < specs.getNumROUTPins(); idx++) {
+            strBuf.append(specs.getROUT_PinNames()[idx]+" ");
+        }
+        strBuf.append("\n\n");
+        out.write(strBuf.toString().getBytes(StandardCharsets.US_ASCII));
+
+        for(int ms_idx = 0; ms_idx < mStates.length; ms_idx++) {
+            MacroState ms = mStates[ms_idx];
+            if(ms == null) continue; // This state was not filled
+
+            for(int sl_idx = 0; sl_idx < ms.links.length; sl_idx++) {
+                strBuf.delete(0, strBuf.length());
+
+                // Add the registered outputs as inputs
+                for(int bit_idx = 0; bit_idx < specs.getNumROUTPins(); bit_idx++) {
+                    strBuf.append(((mStates[ms_idx].rpin_status >> ((specs.getNumROUTPins() - 1) - bit_idx)) & 0x01) > 0 ? '1' : '0');
+                }
+
+                // Add the inputs as inputs
+                for(int bit_idx = 0; bit_idx < totInputs; bit_idx++) {
+                    strBuf.append(((sl_idx >> bit_idx) & 0x01) > 0 ? '1' : '0');
+                }
+
+                strBuf.append(' ');
+
+                // Add the registered outputs of the new state as outputs
+                for(int bit_idx = 0; bit_idx < specs.getNumROUTPins(); bit_idx++) {
+                    strBuf.append(((mStates[ms_idx].links[sl_idx].destMS.rpin_status >> ((specs.getNumROUTPins() - 1) - bit_idx)) & 0x01) > 0 ? '1' : '0');
+                }
+
+                strBuf.append('\n');
+                out.write(strBuf.toString().getBytes(StandardCharsets.US_ASCII));
+            }
+        }
+
+        out.write(("\n.e\n").getBytes(StandardCharsets.US_ASCII));
+    }
+
     /*
     /*
      * This method will write out a table with all the OUTPUTS states, to be minimized
      * This method will write out a table with all the OUTPUTS states, to be minimized
      * Inputs for this table will be
      * Inputs for this table will be
@@ -526,13 +594,14 @@ public class DuPALAnalyzer {
      * - OE status for each output
      * - OE status for each output
      */
      */
     static private void printLogicTableOUTPUTS(OutputStream out, PALSpecs specs, int additionalOUTs, int ioOUTMask, MacroState[] mStates) throws IOException {
     static private void printLogicTableOUTPUTS(OutputStream out, PALSpecs specs, int additionalOUTs, int ioOUTMask, MacroState[] mStates) throws IOException {
-        out.write(("OUTPUT logic table\n").getBytes(StandardCharsets.US_ASCII));
+        out.write(("# OUTPUT logic table\n").getBytes(StandardCharsets.US_ASCII));
         int totInputs = specs.getNumINPins() + (specs.getNumIOPins() - additionalOUTs);
         int totInputs = specs.getNumINPins() + (specs.getNumIOPins() - additionalOUTs);
         StringBuffer strBuf = new StringBuffer();
         StringBuffer strBuf = new StringBuffer();
 
 
         out.write((".i " + (totInputs + specs.getNumROUTPins()) + "\n").getBytes(StandardCharsets.US_ASCII));
         out.write((".i " + (totInputs + specs.getNumROUTPins()) + "\n").getBytes(StandardCharsets.US_ASCII));
         out.write((".o " + (additionalOUTs*2) + "\n").getBytes(StandardCharsets.US_ASCII)); // * 2 because we get both an output and its OE state
         out.write((".o " + (additionalOUTs*2) + "\n").getBytes(StandardCharsets.US_ASCII)); // * 2 because we get both an output and its OE state
-        
+       
+        // Input labels
         strBuf.delete(0, strBuf.length()); 
         strBuf.delete(0, strBuf.length()); 
         strBuf.append(".ilb ");
         strBuf.append(".ilb ");
         for(int idx = 0; idx < specs.getNumROUTPins(); idx++) {
         for(int idx = 0; idx < specs.getNumROUTPins(); idx++) {
@@ -550,6 +619,7 @@ public class DuPALAnalyzer {
         strBuf.append('\n');
         strBuf.append('\n');
         out.write(strBuf.toString().getBytes(StandardCharsets.US_ASCII));
         out.write(strBuf.toString().getBytes(StandardCharsets.US_ASCII));
 
 
+        // Output labels
         strBuf.delete(0, strBuf.length());
         strBuf.delete(0, strBuf.length());
         strBuf.append(".ob ");
         strBuf.append(".ob ");
         for(int idx = 0; idx < 8; idx++) {
         for(int idx = 0; idx < 8; idx++) {