; --------------------------------------------------------------------------------
; @Title: Analyzer Programming Dialog
; @Description: Please refer to pdf/analyzer_dialog.pdf for more info
; @Props: NoIndex, NoWelcome, NoFullText
; @Author: -
; @Copyright: (C) 1989-2017 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: analyzerdialog.cmm 11204 2017-08-10 12:24:05Z smeister $

; --------------------------------------------------------------------------------
;                               Dialog Levelx
; --------------------------------------------------------------------------------

  IF WINdow.EXIST(_a_dialog)
    ENDDO

  LOCAL &DBoolean &DBinary &DHex &DInteger &DAscii &DString &DRange &DAddress &DARange &DTime &DTRange &DFloat &DNumeric &DIntNum &DBitmask &DEmpty
  LOCAL &spres &ret &adir &trace &a1 &a2 &a3 &b1 &b2 &b3 &c1 &c2 &c3 &oaw &oar &ab &bb &cb
  LOCAL &hac &ecc8 &hacmod &bamap &debug &subdialog &oaw1 &oaw2 &oar1 &oar2
  ; nur setzen zum Testen 1. call from local dir 0. call from system dir !!!!!!!
  &debug=0.
  &subdialog=0.
  &DBoolean=0x00000001
  &DBinary=0x00000002
  &DHex=0x00000004
  &DInteger=0x00000008
  &DFloat=0x00000010
  &DAscii=0x00000020
  &DIntNum=0x0000002E
  &DNumeric=0x0000003E
  &DString=0x00000040
  &DRange=0x00000080
  &DAddress=0x00000100
  &DARange=0x00000200
  &DTime=0x00000400
  &DTRange=0x00000800
  &DBitmask=0x00004000
  &DEmpty=0x00008000
  IF os.file(~~/init_ba_map.cmm)&&os.file(~~/set_ba_map.cmm)
    &bamap=1.
  ELSE
    &bamap=0.

  IF A.CONFIG.HAC()
  (
    &hac=1.
    &ecc8=0.
  )
  ELSE
  (
    &hac=0.
    IF A.CONFIG.ECC8()
      &ecc8=1.
    ELSE
      &ecc8=0.
  )

  PRINT ""
  GOSUB GetTrace
  WINPOS ,,,,,, _a_dialog
  DIALOG
  (
        HEADER "Analyzer Programming"
	ICON ":atrigger"

; --------------------------------------------------------------------------------
;                             Definition
; --------------------------------------------------------------------------------
        POS 0. 0. 78.
        line "Definition"
        POS 10. 1. 7.
        TEXT "Address"
        POS 29. 1. 7.
        TEXT "Address"
        POS 48. 1. 7.
        TEXT "Address"
; --------------------------------------------------------------------------------
;                             A-Range
; --------------------------------------------------------------------------------
        POS 1. 2. 8.
        TEXT "A-Range :"
        POS 10. 2. 15.
RA1:    EDIT "" "GOSUB CallCheckAddr A1"
        POS 25. 2. 2.
VA1:    BUTTON "V" "GOSUB CallVAddr A1"
        POS 27. 2. 2.
        TEXT " or"
        POS 29. 2. 15.
RA2:    EDIT "" "GOSUB CallCheckAddr A2"
        POS 44. 2. 2.
VA2:    BUTTON "V" "GOSUB CallVAddr A2"
        POS 46. 2. 2.
        TEXT " or"
        POS 48. 2. 15.
RA3:    EDIT "" "GOSUB CallCheckAddr A3"
        POS 63. 2. 2.
VA3:    BUTTON "V" "GOSUB CallVAddr A3"
; --------------------------------------------------------------------------------
;                             B-Range
; --------------------------------------------------------------------------------
        POS 1. 3. 8.
        TEXT "B-Range :"
        POS 10. 3. 15.
RB1:    EDIT "" "GOSUB CallCheckAddr B1"
        POS 25. 3. 2.
VB1:    BUTTON "V" "GOSUB CallVAddr B1"
        POS 27. 3. 2.
        TEXT " or"
        POS 29. 3. 15.
RB2:    EDIT "" "GOSUB CallCheckAddr B2"
        POS 44. 3. 2.
VB2:    BUTTON "V" "GOSUB CallVAddr B2"
        POS 46. 3. 2.
        TEXT " or"
        POS 48. 3. 15.
RB3:    EDIT "" "GOSUB CallCheckAddr B3"
        POS 63. 3. 2.
VB3:    BUTTON "V" "GOSUB CallVAddr B3"
; --------------------------------------------------------------------------------
;                             C-Range
; --------------------------------------------------------------------------------
        POS 1. 4. 8.
        TEXT "C-Range :"
        POS 10. 4. 15.
RC1:    EDIT "" "GOSUB CallCheckAddr C1"
        POS 25. 4. 2.
VC1:    BUTTON "V" "GOSUB CallVAddr C1"
        POS 27. 4. 2.
        TEXT " or"
        POS 29. 4. 15.
RC2:    EDIT "" "GOSUB CallCheckAddr C2"
        POS 44. 4. 2.
VC2:    BUTTON "V" "GOSUB CallVAddr C2"
        POS 46. 4. 2.
        TEXT " or"
        POS 48. 4. 15.
RC3:    EDIT "" "GOSUB CallCheckAddr C3"
        POS 63. 4. 2.
VC3:    BUTTON "V" "GOSUB CallVAddr C3"
; --------------------------------------------------------------------------------
;                             Data0
; --------------------------------------------------------------------------------
        POS 7. 5.5 10.
        TEXT "Value"
        POS 30. 5.5 10.
        TEXT "Type"
        POS 1. 6.5 6.5
        TEXT "DATA0:"
        POS 7.5 6.5 20.
RD01:   EDIT "" "GOSUB CallCheckData D0"
        POS 27.5 6.5 2.
VD01:   BUTTON "V" "GOSUB CallVData D0"
        POS 30. 6.5 6.
RD02:   PULLDOWN A.DSEL() "GOSUB CallCheckData D0"
; --------------------------------------------------------------------------------
;                             Data1
; --------------------------------------------------------------------------------
        POS 1. 7.5 6.5
        TEXT "DATA1:"
        POS 7.5 7.5 20.
RD11:   EDIT "" "GOSUB CallCheckData D1"
        POS 27.5 7.5 2.
VD11:   BUTTON "V" "GOSUB CallVData D1"
        POS 30. 7.5 6.
RD12:   PULLDOWN A.DSEL() "GOSUB CallCheckData D1"
; --------------------------------------------------------------------------------
;                             Count0
; --------------------------------------------------------------------------------
        POS 48.5 5.5 10.
        TEXT "Value"
        POS 60. 5.5 10.
        TEXT "Unit"
        POS 41. 6.5 7.5
        TEXT "COUNT0:"
        POS 48.5 6.5 9.
EC0:    EDIT "" "GOSUB CallCheckCount C0"
        POS 57.5 6.5 2.
VC01:   BUTTON "V" "GOSUB CallVCount C0"
        POS 60. 6.5 5.
PC0:    PULLDOWN ",ks,s,ms,us,ns" "GOSUB CallCheckCount C0"
; --------------------------------------------------------------------------------
;                             Count1
; --------------------------------------------------------------------------------

        POS 41. 7.5 7.5
        TEXT "COUNT1:"
        POS 48.5 7.5 9.
EC1:    EDIT "" "GOSUB CallCheckCount C1"
        POS 57.5 7.5 2.
VC11:   BUTTON "V" "GOSUB CallVCount C1"
        POS 60. 7.5 5.
PC1:    PULLDOWN ",ks,s,ms,us,ns" "GOSUB CallCheckCount C1"
; --------------------------------------------------------------------------------
;                             Level0
; --------------------------------------------------------------------------------
        POS 0. 9. 78.
        line "Level0"
        POS 1. 10. 10.
        TEXT "Action"
        POS 21. 10. 13.
        TEXT "Address/Range"
        POS 37. 10. 10.
        TEXT "RD/WR..."
        POS 49. 10. 10.
        TEXT "Data"
        POS 64. 10. 10.
        TEXT "Count"
; --------------------------------------------------------------------------------
;                             Level0-Z1
; --------------------------------------------------------------------------------
        POS 1. 11. 18.
S0A1:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level1,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S0A1"
        POS 19. 11. 2.
        TEXT "IF"
        POS 21. 11. 14.
S0AR1:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S0AR1"
        POS 35. 11. 2.
        TEXT " &"
        POS 37. 11. 10.
S0WR1:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S0WR1"
        POS 47. 11. 2.
        TEXT " &"
        POS 49. 11. 13.
S0D1:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S0D1"
        POS 62. 11. 2.
        TEXT " &"
        POS 64. 11. 14.
S0C1:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S0C1"
; --------------------------------------------------------------------------------
;                             Level0-Z2
; --------------------------------------------------------------------------------
        POS 1. 12. 18.
S0A2:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level1,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S0A2"
        POS 19. 12. 2.
        TEXT "IF"
        POS 21. 12. 14.
S0AR2:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S0AR2"
        POS 35. 12. 2.
        TEXT " &"
        POS 37. 12. 10.
S0WR2:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S0WR2"
        POS 47. 12. 2.
        TEXT " &"
        POS 49. 12. 13.
S0D2:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S0D2"
        POS 62. 12. 2.
        TEXT " &"
        POS 64. 12. 14.
S0C2:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S0C2"
; --------------------------------------------------------------------------------
;                             Level0-Z3
; --------------------------------------------------------------------------------
        POS 1. 13. 18.
S0A3:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level1,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S0A3"
        POS 19. 13. 2.
        TEXT "IF"
        POS 21. 13. 14.
S0AR3:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S0AR3"
        POS 35. 13. 2.
        TEXT " &"
        POS 37. 13. 10.
S0WR3:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S0WR3"
        POS 47. 13. 2.
        TEXT " &"
        POS 49. 13. 13.
S0D3:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S0D3"
        POS 62. 13. 2.
        TEXT " &"
        POS 64. 13. 14.
S0C3:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S0C3"
; --------------------------------------------------------------------------------
;                             Level0-Z4
; --------------------------------------------------------------------------------
        POS 1. 14. 18.
S0A4:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level1,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S0A4"
        POS 19. 14. 2.
        TEXT "IF"
        POS 21. 14. 14.
S0AR4:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S0AR4"
        POS 35. 14. 2.
        TEXT " &"
        POS 37. 14. 10.
S0WR4:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S0WR4"
        POS 47. 14. 2.
        TEXT " &"
        POS 49. 14. 13.
S0D4:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S0D4"
        POS 62. 14. 2.
        TEXT " &"
        POS 64. 14. 14.
S0C4:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S0C4"
; --------------------------------------------------------------------------------
;                             Level1
; --------------------------------------------------------------------------------
        POS 0. 15. 78.
        line "Level1"
; --------------------------------------------------------------------------------
;                             Level1-Z1
; --------------------------------------------------------------------------------
        POS 1. 16. 18.
S1A1:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level0,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S1A1"
        POS 19. 16. 2.
        TEXT "IF"
        POS 21. 16. 14.
S1AR1:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S1AR1"
        POS 35. 16. 2.
        TEXT " &"
        POS 37. 16. 10.
S1WR1:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S1WR1"
        POS 47. 16. 2.
        TEXT " &"
        POS 49. 16. 13.
S1D1:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S1D1"
        POS 62. 16. 2.
        TEXT " &"
        POS 64. 16. 14.
S1C1:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S1C1"
; --------------------------------------------------------------------------------
;                             Level1-Z2
; --------------------------------------------------------------------------------
        POS 1. 17. 18.
S1A2:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level0,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S1A2"
        POS 19. 17. 2.
        TEXT "IF"
        POS 21. 17. 14.
S1AR2:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S1AR2"
        POS 35. 17. 2.
        TEXT " &"
        POS 37. 17. 10.
S1WR2:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S1WR2"
        POS 47. 17. 2.
        TEXT " &"
        POS 49. 17. 13.
S1D2:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S1D2"
        POS 62. 17. 2.
        TEXT " &"
        POS 64. 17. 14.
S1C2:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S1C2"
; --------------------------------------------------------------------------------
;                             Level1-Z3
; --------------------------------------------------------------------------------
        POS 1. 18. 18.
S1A3:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level0,Goto Level2,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S1A3"
        POS 19. 18. 2.
        TEXT "IF"
        POS 21. 18. 14.
S1AR3:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S1AR3"
        POS 35. 18. 2.
        TEXT " &"
        POS 37. 18. 10.
S1WR3:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S1WR3"
        POS 47. 18. 2.
        TEXT " &"
        POS 49. 18. 13.
S1D3:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S1D3"
        POS 62. 18. 2.
        TEXT " &"
        POS 64. 18. 14.
S1C3:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S1C3"
; --------------------------------------------------------------------------------
;                             Level2
; --------------------------------------------------------------------------------
        POS 0. 19. 78.
        line "Level2"
; --------------------------------------------------------------------------------
;                             Level2-Z1
; --------------------------------------------------------------------------------
        POS 1. 20. 18.
S2A1:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level0,Goto Level1,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S2A1"
        POS 19. 20. 2.
        TEXT "IF"
        POS 21. 20. 14.
S2AR1:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S2AR1"
        POS 35. 20. 2.
        TEXT " &"
        POS 37. 20. 10.
S2WR1:  PULLDOWN ",READ,WRITE,ACCESS"  "GOSUB CallRW S2WR1"
        POS 47. 20. 2.
        TEXT " &"
        POS 49. 20. 13.
S2D1:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S2D1"
        POS 62. 20. 2.
        TEXT " &"
        POS 64. 20. 14.
S2C1:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S2C1"
; --------------------------------------------------------------------------------
;                             Level2-Z2
; --------------------------------------------------------------------------------
        POS 1. 21. 18.
S2A2:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level0,Goto Level1,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S2A2"
        POS 19. 21. 2.
        TEXT "IF"
        POS 21. 21. 14.
S2AR2:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S2AR2"
        POS 35. 21. 2.
        TEXT " &"
        POS 37. 21. 10.
S2WR2:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S2WR2"
        POS 47. 21. 2.
        TEXT " &"
        POS 49. 21. 13.
S2D2:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S2D2"
        POS 62. 21. 2.
        TEXT " &"
        POS 64. 21. 14.
S2C2:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S2C2"
; --------------------------------------------------------------------------------
;                             Level2-Z3
; --------------------------------------------------------------------------------
        POS 1. 22. 18.
S2A3:   PULLDOWN ",Sample,Stop Analyzer,Stop CPU&Analyzer,Goto Level0,Goto Level1,Inc COUNT0,Inc COUNT1,Restart COUNT0,Restart COUNT1,Mark A,Mark B,Mark C" "GOSUB CallAction S2A3"
        POS 19. 22. 2.
        TEXT "IF"
        POS 21. 22. 14.
S2AR3:  PULLDOWN ",A-Range,B-Range,C-Range,AB-Range,AC-Range,BC-Range,ABC-Range,NOT A-Range,NOT B-Range,NOT C-Range" "GOSUB CallARange S2AR3"
        POS 35. 22. 2.
        TEXT " &"
        POS 37. 22. 10.
S2WR3:  PULLDOWN ",READ,WRITE,ACCESS" "GOSUB CallRW S2WR3"
        POS 47. 22. 2.
        TEXT " &"
        POS 49. 22. 13.
S2D3:   PULLDOWN ",DATA0,NOT DATA0,DATA1,NOT DATA1" "GOSUB CallData S2D3"
        POS 62. 22. 2.
        TEXT " &"
        POS 64. 22. 14.
S2C3:   PULLDOWN ",COUNT0,NOT COUNT0,COUNT1,NOT COUNT1" "GOSUB CallCount S2C3"
; --------------------------------------------------------------------------------
;                             Button-Leiste
; --------------------------------------------------------------------------------
        POS 0. 23. 78.
        line ""
        POS 1. 24.5 7.
        BUTTON "CLEAR" "GOSUB InitDialogS1"
        POS 9. 24.5 7.
        BUTTON "LOAD" "GOSUB InitProgram"
        POS 17. 24.5 7.
        BUTTON "VIEW" "GOSUB SetAnaProgram 3."
        POS 25. 24.5 7.
        BUTTON "SAVE" "GOSUB SetAnaProgram 1."
        POS 37. 24.5 10.
        BUTTON "Program" "GOSUB SetAnaProgram 2."
        POS 48. 24.5 13.
        BUTTON "Program && Save" "GOSUB SetAnaProgram 0."
        POS 62. 24.5 16.
        BUTTON "Program && Save && Close" "jumpto okclose"
        POS 1. 26. 12.
        TEXT "Actual used file:"
        POS 13. 26. 25.
IFILE:  EDIT ""
        (
          IF &subdialog!=0.
          (
            LOCAL &TEXT
            IF &subdialog==1.
              &TEXT="Please close Define Address Window first!"
            ELSE IF &subdialog==2.
              &TEXT="Please close Define Data Window first!"
            ELSE IF &subdialog==3.
              &TEXT="Please close Define Count Window first!"
            PRINT %ERROR "&TEXT"
            DIALOG.SET IFILE ""
          )
        )
        POS 38. 26. 2.
FVBUT:  BUTTON "V"
        (
          IF &subdialog!=0.
          (
            LOCAL &TEXT
            IF &subdialog==1.
              &TEXT="Please close Define Address Window first!"
            ELSE IF &subdialog==2.
              &TEXT="Please close Define Data Window first!"
            ELSE IF &subdialog==3.
              &TEXT="Please close Define Count Window first!"
            PRINT %ERROR "&TEXT"
          )
          ELSE
            DIALOG.SETfilew IFILE "&adir"
        )
        CLOSE "jumpto winclose"
        POS 72. 26. 6.
        BUTTON "About" "GOSUB ShowVersion"
;        POS 50. 26.25 1.
;        TEXT ""
  )
  &adir="*.ts"
  GOSUB InitDialogS1
backloop:
  stop
okclose:
  GOSUB SetAnaProgram 0.
winclose:
  IF &subdialog!=0.
    DIALOG.END
  DIALOG.END
  ENDDO

InitDialogS1:
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
  )
  ELSE
  (
    DIALOG.SET RA1 ""
    DIALOG.SET RA2 ""
    DIALOG.SET RA3 ""
    DIALOG.SET RB1 ""
    DIALOG.SET RB2 ""
    DIALOG.SET RB3 ""
    DIALOG.SET RC1 ""
    DIALOG.SET RC2 ""
    DIALOG.SET RC3 ""
    DIALOG.SET RD01 ""
    IF cpubondout()!=""
      DIALOG.SET RD02 "W"
    DIALOG.ENABLE VD01
    DIALOG.SET RD11 ""
    IF cpubondout()!=""
      DIALOG.SET RD12 "W"
    DIALOG.ENABLE VD11
    DIALOG.SET EC0  ""
    DIALOG.SET PC0  ""
    DIALOG.SET EC1  ""
    DIALOG.SET PC1  ""
    DIALOG.SET S0A1  ""
    DIALOG.SET S0AR1 ""
    DIALOG.SET S0WR1 ""
    DIALOG.SET S0D1  ""
    DIALOG.SET S0C1  ""
    DIALOG.SET S0A2  ""
    DIALOG.SET S0AR2 ""
    DIALOG.SET S0WR2 ""
    DIALOG.SET S0D2  ""
    DIALOG.SET S0C2  ""
    DIALOG.SET S0A3  ""
    DIALOG.SET S0AR3 ""
    DIALOG.SET S0WR3 ""
    DIALOG.SET S0D3  ""
    DIALOG.SET S0C3  ""
    DIALOG.SET S0A4  ""
    DIALOG.SET S0AR4 ""
    DIALOG.SET S0WR4 ""
    DIALOG.SET S0D4  ""
    DIALOG.SET S0C4  ""
    DIALOG.SET S1A1  ""
    DIALOG.SET S1AR1 ""
    DIALOG.SET S1WR1 ""
    DIALOG.SET S1D1  ""
    DIALOG.SET S1C1  ""
    DIALOG.SET S1A2  ""
    DIALOG.SET S1AR2 ""
    DIALOG.SET S1WR2 ""
    DIALOG.SET S1D2  ""
    DIALOG.SET S1C2  ""
    DIALOG.SET S1A3  ""
    DIALOG.SET S1AR3 ""
    DIALOG.SET S1WR3 ""
    DIALOG.SET S1D3  ""
    DIALOG.SET S1C3  ""
    DIALOG.SET S2A1  ""
    DIALOG.SET S2AR1 ""
    DIALOG.SET S2WR1 ""
    DIALOG.SET S2D1  ""
    DIALOG.SET S2C1  ""
    DIALOG.SET S2A2  ""
    DIALOG.SET S2AR2 ""
    DIALOG.SET S2WR2 ""
    DIALOG.SET S2D2  ""
    DIALOG.SET S2C2  ""
    DIALOG.SET S2A3  ""
    DIALOG.SET S2AR3 ""
    DIALOG.SET S2WR3 ""
    DIALOG.SET S2D3  ""
    DIALOG.SET S2C3  ""
    DIALOG.SET IFILE ""

    DIALOG.ENABLE S0A1
    DIALOG.ENABLE S0AR1
    DIALOG.ENABLE S0WR1
    DIALOG.ENABLE S0D1
    DIALOG.ENABLE S0D2
    DIALOG.ENABLE S0D3
    DIALOG.ENABLE S0D4
    DIALOG.ENABLE S0C1
    DIALOG.ENABLE S0A2
    DIALOG.ENABLE S0AR2
    DIALOG.ENABLE S0WR2
    DIALOG.ENABLE S0C2
    DIALOG.ENABLE S0A3
    DIALOG.ENABLE S0AR3
    DIALOG.ENABLE S0WR3
    DIALOG.ENABLE S0C3
    DIALOG.ENABLE S0A4
    DIALOG.ENABLE S0AR4
    DIALOG.ENABLE S0WR4
    DIALOG.ENABLE S0C4
    DIALOG.DISABLE S1A1
    DIALOG.DISABLE S1AR1
    DIALOG.DISABLE S1WR1
    DIALOG.DISABLE S1D1
    DIALOG.DISABLE S1C1
    DIALOG.DISABLE S1A2
    DIALOG.DISABLE S1AR2
    DIALOG.DISABLE S1WR2
    DIALOG.DISABLE S1D2
    DIALOG.DISABLE S1C2
    DIALOG.DISABLE S1A3
    DIALOG.DISABLE S1AR3
    DIALOG.DISABLE S1WR3
    DIALOG.DISABLE S1D3
    DIALOG.DISABLE S1C3
    DIALOG.DISABLE S2A1
    DIALOG.DISABLE S2AR1
    DIALOG.DISABLE S2WR1
    DIALOG.DISABLE S2D1
    DIALOG.DISABLE S2C1
    DIALOG.DISABLE S2A2
    DIALOG.DISABLE S2AR2
    DIALOG.DISABLE S2WR2
    DIALOG.DISABLE S2D2
    DIALOG.DISABLE S2C2
    DIALOG.DISABLE S2A3
    DIALOG.DISABLE S2AR3
    DIALOG.DISABLE S2WR3
    DIALOG.DISABLE S2D3
    DIALOG.DISABLE S2C3
    a.rp
  )
  RETURN
; --------------------------------------------------------------------------------
;                             Dialog Callbackroutinen
; --------------------------------------------------------------------------------
CallCheckAddr:
  LOCAL &aval &anr &atype
  ENTRY &anr

  &anr="R"+"&anr"
  &aval=dialog.string("&anr")
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &anr ""
  )
  ELSE IF "&aval"!=""
  (
    on error GOSUB
    (
      &aval=""
      RETURN
    )
    EVAL &aval
    &atype=eval.type()

    IF &atype!=&DAddress&&&atype!=&DARange&&"&aval"!=""
    (
      &atype="&aval"+" no valid address!"
      PRINT %ERROR "&atype"
      &aval=""
    )
    IF "&aval"==""
     DIALOG.SET &anr ""
  )
  RETURN

CallVAddr:
  LOCAL &addr &anr &aval
  ENTRY &anr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
  )
  ELSE
  (
    &anr="R"+"&anr"
    &addr=dialog.string("&anr")
    IF &debug==1.
      do diaaddress &addr
    ELSE
      do ~~/demo/analyzer/trigger/diaaddress &addr
    ENTRY &aval
    IF "&aval"!="0."
      DIALOG.SET &anr "&aval"
  )
  RETURN

CallCheckCount:
  LOCAL &cval &cunit &cnr &ce &cu &t1 &cmax &c0e &c0u &c0val &c0unit &ttmp
  ENTRY &cnr
  &t1=string.cut("&cnr",1.)
  &ce="E"+"&cnr"
  &cu="P"+"&cnr"
  &ttmp=&t1^1.
  &t1=string.cut("&ttmp",-1.)
  &c0e="EC"+"&t1"
  &c0u="PC"+"&t1"
  &cval=dialog.string("&ce")
  &c0val=dialog.string("&c0e")
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &ce ""
    DIALOG.SET &cu ""
  )
  ELSE IF "&cval"!=""
  (
    &cunit=dialog.string("&cu")
    &c0unit=dialog.string("&c0u")
    IF "&cunit"!=""
    (
      on error GOSUB
      (
        &cval=""
        RETURN
      )
      EVAL &cval
      &t1=eval.type()
      IF &t1!=&DInteger&&&t1!=&DIntNum&&&t1!=&DFloat&&&t1!=&DHex&&&t1!=&DNumeric&&"&cval"!=""
      (
        &t1="&cval"+" no valid time value!"
        PRINT %ERROR "&t1"
        &cval=""
      )
      IF &hac==1.&&"&c0unit"!=""
      (
        &t1="Only one time counter allowed with HAC!"
        PRINT %ERROR "&t1"
        &cval=""
      )
      IF "&cval"!=""
      (
        on error GOSUB
        (
          &cval=""
          RETURN
        )
        &cnr="&cval"+"&cunit"
        EVAL &cnr
        &t1=eval.type()

        IF &t1!=&DTime&&"&cval"!=""
        (
          &t1="&cnr"+" no valid time value!"
          PRINT %ERROR "&t1"
          &cval=""
        )
        IF "&c0val"!=""
        (
          GOSUB GetMaxCountVal 1. &c0unit
          ENTRY &cmax
          IF &c0val>&cmax
          (
            IF "&c0unit"!=""
              &t1="Already defined counter "+"&c0val"+" bigger than max value "+"&cmax"+" for "+"&c0unit"+"!"
            ELSE
              &t1="Already defined counter "+"&c0val"+" bigger than max value "+"&cmax"+"!"
            PRINT %ERROR "&t1"
            DIALOG.SET &c0e ""
            DIALOG.SET &c0u ""
          )
          GOSUB GetMaxCountVal 1. &cunit
        )
        ELSE
          GOSUB GetMaxCountVal 0. &cunit

        ENTRY &cmax
        IF &cval>&cmax
        (
          &t1="&cval"+" bigger than max value "+"&cmax"+" for "+"&cunit"+"!"
          PRINT %ERROR "&t1"
          &cval=""
        )
      )
    )
    ELSE
    (
      on error GOSUB
      (
        &cval=""
        RETURN
      )
      EVAL &cval
      &t1=eval.type()

      IF &t1!=&DInteger&&&t1!=&DIntNum&&&t1!=&DFloat&&&t1!=&DBinary&&&t1!=&DHex&&&t1!=&DNumeric&&"&cval"!=""
      (
        &t1="&cval"+" no valid counter !"
        PRINT %ERROR "&t1"
        &cval=""
      )
      IF "&c0val"!=""
      (
        GOSUB GetMaxCountVal 1. &c0unit
        ENTRY &cmax
        IF &c0val>&cmax
        (
          IF "&c0unit"!=""
            &t1="Already defined counter "+"&c0val"+" bigger than max value "+"&cmax"+" for "+"&c0unit"+"!"
          ELSE
            &t1="Already defined counter "+"&c0val"+" bigger than max value "+"&cmax"+"!"
          PRINT %ERROR "&t1"
          DIALOG.SET &c0e ""
          DIALOG.SET &c0u ""
        )
        GOSUB GetMaxCountVal 1. &cunit
      )
      ELSE
        GOSUB GetMaxCountVal 0. &cunit

      ENTRY &cmax
      IF &cval>&cmax
      (
        &t1="&cval"+" bigger than max value "+"&cmax"+"!"
        PRINT %ERROR "&t1"
        &cval=""
      )
    )
    IF "&cval"==""
    (
      DIALOG.SET &ce ""
      DIALOG.SET &cu ""
    )
    ELSE
    (
      DIALOG.SET &ce "&cval"
      DIALOG.SET &cu "&cunit"
    )
  )
  RETURN

CallVCount:
  LOCAL &cval &cunit &cnr &ce &cu
  ENTRY &cnr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
  )
  ELSE
  (
    &ce="E"+"&cnr"
    &cu="P"+"&cnr"
    &cval=dialog.string("&ce")
    &cunit=dialog.string("&cu")
    IF &debug==1.
      do diacount &cval &cunit
    ELSE
      do ~~/demo/analyzer/trigger/diacount &cval &cunit
    ENTRY &cval &cunit
    IF &cval!="0."
    (
      DIALOG.SET &ce &cval
      DIALOG.SET &cu &cunit
      GOSUB CallCheckCount &cnr
    )
  )
  RETURN

CallCheckData:
  LOCAL &dval &type &dnr &dc &dt &t1 &ndval
  ENTRY &dnr
  &dc="R"+"&dnr"+"1"
  &dt="R"+"&dnr"+"2"
  &dval=dialog.string("&dc")
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &dc ""
  )
  ELSE IF "&dval"!=""
  (
    &type=dialog.string("&dt")
    IF "&type"!=""
    (
      GOSUB CheckData &dval &type
      ENTRY &ndval
      IF "&ndval"==""
        DIALOG.SET &dc ""
      IF "&dval"!="&ndval"
        DIALOG.SET &dc "&ndval"
    )
    ELSE
    (
      &txt="Data type not defined. Define type first!"
      PRINT %ERROR "&txt"
      DIALOG.SET &dc ""
    )
  )
  RETURN

CallVData:
  LOCAL &dval &dtype &dnr &dc &dt
  ENTRY &dnr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
  )
  ELSE
  (
    &dc="R"+"&dnr"+"1"
    &dt="R"+"&dnr"+"2"
    &dval=dialog.string("&dc")
    &dtype=dialog.string("&dt")
    IF &debug==1.
      do diadata &dtype &dval
    ELSE
      do ~~/demo/analyzer/trigger/diadata &dtype &dval
    ENTRY &dval &dtype
    IF &dval!="0."
    (
      DIALOG.SET &dc &dval
      DIALOG.SET &dt &dtype
    )
  )
  RETURN

CallAction:
  ; Uebergabe S<level>A<line>
  LOCAL &anr &ret &line &level
  ENTRY &anr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &anr ""
  )
  ELSE
  (
    &level=string.mid("&anr",1.,1.)
    &level="&level"+"."
    &line=string.mid("&anr",3.,1.)
    &line="&line"+"."
    &spres=dialog.string("&anr")
    GOSUB InitStates "&spres" &level &line
    ENTRY &ret
    IF &ret==1.
      DIALOG.SET &anr ""
  )
  RETURN

CallARange:
  ; Uebergabe S<level>AR<line>
  LOCAL &anr &ret &line &level
  ENTRY &anr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &anr ""
  )
  ELSE
  (
    &level=string.mid("&anr",1.,1.)
    &level="&level"+"."
    &line=string.mid("&anr",4.,1.)
    &line="&line"+"."
    &spres=dialog.string("&anr")
    GOSUB CheckARange "&spres" &level &line
    ENTRY &ret
    IF &ret==1.
      DIALOG.SET &anr ""
  )
  RETURN

CallRW:
  ; Uebergabe S<level>RW<line>
  LOCAL &anr
  ENTRY &anr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &anr ""
  )
  RETURN

CallData:
  ; Uebergabe S<level>D<line>
  LOCAL &anr &ret &line &level
  ENTRY &anr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &anr ""
  )
  ELSE
  (
    &level=string.mid("&anr",1.,1.)
    &level="&level"+"."
    &line=string.mid("&anr",3.,1.)
    &line="&line"+"."

    &spres=dialog.string("&anr")
    GOSUB CheckDataCall "&spres" &level
    ENTRY &ret
    IF &ret==1.
      DIALOG.SET &anr ""
  )
  RETURN

CallCount:
  ; Uebergabe S<level>C<line>
  LOCAL &anr &ret &line &level
  ENTRY &anr
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    DIALOG.SET &anr ""
  )
  ELSE
  (
    &level=string.mid("&anr",1.,1.)
    &level="&level"+"."
    &line=string.mid("&anr",3.,1.)
    &line="&line"+"."
    &spres=dialog.string("&anr")
    GOSUB CheckCount "&spres" &level
    ENTRY &ret
    IF &ret==1.
      DIALOG.SET &anr ""
  )
  RETURN

CheckARange:
   LOCAL &spres &A1R &A2R &A3R &ret &diaret &ra1 &ra2 &ra3 &level &line &txt &t1 &t2
   ENTRY &spres &level &line
   &ret=0.
   &ra1="0."
   &ra2="0."
   &ra3="0."
   IF &hac==1.&&&spres!=""
   (
     IF &spres!="A-Range"&&&spres!="B-Range"&&&spres!="C-Range"
     (
       &txt=&spres+" not allowed with HAC !"
       PRINT %ERROR "&txt"
       &ret=1.
     )
     IF &ret==0.
     (
       &t1=string.cut("&level",-1.)
       &t2=string.cut("&line",-1.)
       &txt="S"+"&t1"+"A"+"&t2"
       &diaret=dialog.string(&txt)
       IF "&diaret"!=""&&(("&diaret"=="Mark A"&&&spres!="A-Range")||("&diaret"=="Mark B"&&&spres!="B-Range")||("&diaret"=="Mark C"&&&spres!="C-Range"))
       (
         &txt="&diaret"+" not allowed with "+&spres+" condition with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
     )
     IF &ret==0.
     (
       GOSUB CheckHACModel
       ENTRY &txt
       IF &txt==2.&&&level==1.&&(&spres=="A-Range"||&spres=="B-Range")
       (
         &txt=&spres+" not allowed in Level"+"&level"+" with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       ELSE IF &level==1.&&&spres=="A-Range"
       (
         &txt=&spres+" not allowed in Level"+"&level"+" with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       ELSE IF &level==2.&&(&spres=="A-Range"||&spres=="B-Range")
       (
         &txt=&spres+" not allowed in Level"+"&level"+" with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
     )
   )

   IF &ret==0.
   (
     IF &spres=="A-Range"||&spres=="AB-Range"||&spres=="AC-Range"||&spres=="ABC-Range"||&spres=="NOT A-Range"||&spres=="NOT AB-Range"||&spres=="NOT AC-Range"||&spres=="NOT ABC-Range"
     (
       &A1R=dialog.string(RA1)
       &A2R=dialog.string(RA2)
       &A3R=dialog.string(RA3)
       IF "&A1R"==""&&"&A2R"==""&&"&A3R"==""
       (
         IF &debug==1.
           do diaaddress
         ELSE
           do ~~/demo/analyzer/trigger/diaaddress
         ENTRY &diaret
         IF "&diaret"=="0."||"&diaret"==""
           &ret=1.
         ELSE
           &ra1="&diaret"
       )
     )
   )
   IF &ret==0.
   (
     IF &spres=="B-Range"||&spres=="AB-Range"||&spres=="BC-Range"||&spres=="ABC-Range"||&spres=="NOT B-Range"||&spres=="NOT AB-Range"||&spres=="NOT BC-Range"||&spres=="NOT ABC-Range"
     (
       &A1R=dialog.string(RB1)
       &A2R=dialog.string(RB2)
       &A3R=dialog.string(RB3)
       IF "&A1R"==""&&"&A2R"==""&&"&A3R"==""
       (
         IF &debug==1.
           do diaaddress
         ELSE
           do ~~/demo/analyzer/trigger/diaaddress
         ENTRY &diaret
         IF "&diaret"=="0."||"&diaret"==""
           &ret=1.
         ELSE
           &ra2="&diaret"
       )
     )
     IF &ret==0.
     (
       IF &spres=="C-Range"||&spres=="AC-Range"||&spres=="BC-Range"||&spres=="ABC-Range"||&spres=="NOT C-Range"||&spres=="NOT AC-Range"||&spres=="NOT BC-Range"||&spres=="NOT ABC-Range"
       (
         &A1R=dialog.string(RC1)
         &A2R=dialog.string(RC2)
         &A3R=dialog.string(RC3)
         IF "&A1R"==""&&"&A2R"==""&&"&A3R"==""
         (
           IF &debug==1.
             do diaaddress
           ELSE
             do ~~/demo/analyzer/trigger/diaaddress
           ENTRY &diaret
           IF "&diaret"=="0."||"&diaret"==""
             &ret=1.
           ELSE
             &ra3="&diaret"
         )
       )
     )
   )
   IF &ret==0.
   (
     IF "&ra1"!="0."
       DIALOG.SET RA1 "&ra1"
     IF "&ra2"!="0."
       DIALOG.SET RB1 "&ra2"
     IF "&ra3"!="0."
       DIALOG.SET RC1 "&ra3"
   )
  RETURN &ret

CheckDataCall:
   LOCAL &spres &dval &dtype &ret &level &txt
   ENTRY &spres &level
   &ret=0.
   IF &hac==1.&&(&spres=="NOT DATA0"||&spres=="NOT DATA1")
   (
     &txt=&spres+" not allowed with HAC !"
     PRINT %ERROR "&txt"
     &ret=1.
   )
   IF &hac==1.&&&level==2.&&(&spres=="DATA0"||&spres=="DATA1")
   (
     &txt="In Level"+"&level"+" "+&spres+" not allowed with HAC !"
     PRINT %ERROR "&txt"
     &ret=1.
   )

   IF &ret==0.
   (
     IF &spres=="DATA0"||&spres=="NOT DATA0"
     (
       &dval=dialog.string(RD01)
       &dtype=dialog.string(RD02)
       IF "&dval"==""
       (
         IF &debug==1.
           do diadata &dtype &dval
         ELSE
           do ~~/demo/analyzer/trigger/diadata &dtype &dval
         ENTRY &dval &dtype
         IF &dval!="0."&&&dval!=""
         (
           DIALOG.SET RD01 &dval
           DIALOG.SET RD02 &dtype
         )
         ELSE
           &ret=1.
       )
     )
     IF &spres=="DATA1"||&spres=="NOT DATA1"
     (
       &dval=dialog.string(RD11)
       &dtype=dialog.string(RD12)
       IF "&dval"==""
       (
         IF &debug==1.
           do diadata &dtype &dval
         ELSE
           do ~~/demo/analyzer/trigger/diadata &dtype &dval
         ENTRY &dval &dtype
         IF &dval!="0."&&&dval!=""
         (
           DIALOG.SET RD11 &dval
           DIALOG.SET RD12 &dtype
         )
         ELSE
           &ret=1.
       )
     )
   )
  RETURN &ret

InitStates:
   LOCAL &spres &level &line &ret &mod &txt &lmask &rmask &act
   ENTRY &spres &level &line
   &ret=0.
   IF &spres==""
   (
     IF &level==1.
     (
       LOCAL &a1 &a2 &a3 &b11 &b12 &b13 &b14 &b21 &b22 &b23 &b24 &b31 &b32 &b33 &b34 &b41 &b42 &b43 &b44
       &a1=dialog.string(S1A1)
       &b11=dialog.string(S1AR1)
       &b12=dialog.string(S1WR1)
       &b13=dialog.string(S1D1)
       &b14=dialog.string(S1C1)
       &a2=dialog.string(S1A2)
       &b21=dialog.string(S1AR2)
       &b22=dialog.string(S1WR2)
       &b23=dialog.string(S1D2)
       &b24=dialog.string(S1C2)
       &a3=dialog.string(S1A3)
       &b31=dialog.string(S1AR3)
       &b32=dialog.string(S1WR3)
       &b33=dialog.string(S1D3)
       &b34=dialog.string(S1C3)
       IF "&a1"==""&&"&a2"==""&&"&a3"==""&&"&b11"==""&&"&b12"==""&&"&b13"==""&&"&b14"==""&&"&b21"==""&&"&b22"==""&&"&b23"==""&&"&b24"==""&&"&b31"==""&&"&b32"==""&&"&b33"==""&&"&b34"==""&&"&b41"==""&&"&b42"==""&&"&b43"==""&&"&b44"==""
       (
         DIALOG.DISABLE S1A1
         DIALOG.DISABLE S1AR1
         DIALOG.DISABLE S1WR1
         DIALOG.DISABLE S1D1
         DIALOG.DISABLE S1C1
         DIALOG.DISABLE S1A2
         DIALOG.DISABLE S1AR2
         DIALOG.DISABLE S1WR2
         DIALOG.DISABLE S1D2
         DIALOG.DISABLE S1C2
         DIALOG.DISABLE S1A3
         DIALOG.DISABLE S1AR3
         DIALOG.DISABLE S1WR3
         DIALOG.DISABLE S1D3
         DIALOG.DISABLE S1C3
       )
     )
     ELSE
     (
       LOCAL &a1 &a2 &a3 &b11 &b12 &b13 &b14 &b21 &b22 &b23 &b24 &b31 &b32 &b33 &b34 &b41 &b42 &b43 &b44
       &a1=dialog.string(S2A1)
       &b11=dialog.string(S2AR1)
       &b12=dialog.string(S2WR1)
       &b13=dialog.string(S2D1)
       &b14=dialog.string(S2C1)
       &a2=dialog.string(S2A2)
       &b21=dialog.string(S2AR2)
       &b22=dialog.string(S2WR2)
       &b23=dialog.string(S2D2)
       &b24=dialog.string(S2C2)
       &a3=dialog.string(S2A3)
       &b31=dialog.string(S2AR3)
       &b32=dialog.string(S2WR3)
       &b33=dialog.string(S2D3)
       &b34=dialog.string(S2C3)
       IF "&a1"==""&&"&a2"==""&&"&a3"==""&&"&b11"==""&&"&b12"==""&&"&b13"==""&&"&b14"==""&&"&b21"==""&&"&b22"==""&&"&b23"==""&&"&b24"==""&&"&b31"==""&&"&b32"==""&&"&b33"==""&&"&b34"==""&&"&b41"==""&&"&b42"==""&&"&b43"==""&&"&b44"==""
       (
         DIALOG.DISABLE S2A1
         DIALOG.DISABLE S2AR1
         DIALOG.DISABLE S2WR1
         DIALOG.DISABLE S2D1
         DIALOG.DISABLE S2C1
         DIALOG.DISABLE S2A2
         DIALOG.DISABLE S2AR2
         DIALOG.DISABLE S2WR2
         DIALOG.DISABLE S2D2
         DIALOG.DISABLE S2C2
         DIALOG.DISABLE S2A3
         DIALOG.DISABLE S2AR3
         DIALOG.DISABLE S2WR3
         DIALOG.DISABLE S2D3
         DIALOG.DISABLE S2C3
       )
     )
   )
   IF &hac==1.
   (
     IF (&spres=="Mark A"&&&level!=0.)||((&spres=="Mark B"||&spres=="Goto Level1")&&&level==2.)||(&spres=="Goto Level2"&&&level==0.)
     (
       &txt="In Level"+"&level"+" "+&spres+" not allowed with HAC !"
       PRINT %ERROR "&txt"
       &ret=1.
     )
     IF &ret==0.
     (
       GOSUB CheckHACModel
       ENTRY &mod
       GOSUB GetLineMask &level &line
       ENTRY &lmask &act
       IF ((&mod==1.&&&level==2.)||(&mod==2.&&&level==1.))&&(&spres=="Restart COUNT0"||&spres=="Restart COUNT1")
       (
         &txt=&spres+" not allowed in last level &level with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       &rmask=&lmask&0y10000000
       IF &ret==0.&&&spres=="Mark A"&&&lmask!=0y0&&(&rmask!=0y10000000||&lmask==0y11000000)
       (
         &txt="Mark A only with A-Range condition allowed!"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       &rmask=&lmask&0y01000000
       IF &ret==0.&&&spres=="Mark B"&&&lmask!=0y0&&(&rmask!=0y01000000||&lmask==0y11000000)
       (
         &txt="Mark B only with B-Range condition allowed!"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       &rmask=&lmask&0y11000000
       IF &ret==0.&&&spres=="Mark C"&&&lmask!=0y0&&&rmask!=0y11000000
       (
         &txt="Mark C only with C-Range condition allowed!"
         PRINT %ERROR "&txt"
         &ret=1.
       )

       IF &ret==0.&&&level==1.&&&mod==2.&&&spres=="Goto Level2"
       (
         &txt="Construction2 used with HAC. Level2 not allowed to use!"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       ;IF &level!=2.&&&mod==1.&&(&spres=="Stop Analyzer"||&spres=="Stop CPU&Analyzer")
       ;(
       ;  &txt="Construction1 used with HAC. "+&spres+" only allowed in Level 2!"
       ;  PRINT %ERROR "&txt"
       ;  &ret=1.
       ;)
       ;IF &level!=1.&&&mod==2.&&(&spres=="Stop Analyzer"||&spres=="Stop CPU&Analyzer")
       ;(
       ;  &txt="Construction2 used with HAC. "+&spres+" only allowed in Level 1!"
       ;  PRINT %ERROR "&txt"
       ;  &ret=1.
       ;)
       IF &ret==0.&&&mod==1.&&&level==2.&&&lmask!=0y0&&(&spres=="Inc COUNT0"||&spres=="Inc COUNT1"||&spres=="Sample")
       (
         &txt="Construction1 used with HAC. "+&spres+" only allowed without condition in Level 2!"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       IF &ret==0.&&&mod==2.&&&level==1.&&&lmask!=0y0&&(&spres=="Inc COUNT0"||&spres=="Inc COUNT1"||&spres=="Sample")
       (
         &txt="Construction2 used with HAC. "+&spres+" only allowed without condition in Level 1!"
         PRINT %ERROR "&txt"
         &ret=1.
       )
       &rmask=&lmask&0y00000011
       IF (&spres=="Inc COUNT0"&&&rmask==0y00000010)||(&spres=="Inc COUNT1"&&&rmask==0y00000001)
       (
         &txt=&spres+" not allowed with count condition !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
     )
   )
   IF &ret==0.&&(&spres=="Restart COUNT0"||&spres=="Inc COUNT0")
   (
     GOSUB CheckCount "COUNT0" &level
     ENTRY &ret
   )
   IF &ret==0.&&(&spres=="Restart COUNT1"||&spres=="Inc COUNT1")
   (
     GOSUB CheckCount "COUNT1" &level
     ENTRY &ret
   )
   IF &ret==0.&&&spres=="Goto Level0"
   (
     DIALOG.ENABLE S0A1
     DIALOG.ENABLE S0AR1
     DIALOG.ENABLE S0WR1
     DIALOG.ENABLE S0C1
     DIALOG.ENABLE S0A2
     DIALOG.ENABLE S0AR2
     DIALOG.ENABLE S0WR2
     DIALOG.ENABLE S0C2
     DIALOG.ENABLE S0A3
     DIALOG.ENABLE S0AR3
     DIALOG.ENABLE S0WR3
     DIALOG.ENABLE S0C3
     DIALOG.ENABLE S0A4
     DIALOG.ENABLE S0AR4
     DIALOG.ENABLE S0WR4
     DIALOG.ENABLE S0C4
     DIALOG.ENABLE S0D1
     DIALOG.ENABLE S0D2
     DIALOG.ENABLE S0D3
     DIALOG.ENABLE S0D4
   )
   IF &ret==0.&&&spres=="Goto Level1"
   (
     DIALOG.ENABLE S1A1
     DIALOG.ENABLE S1AR1
     DIALOG.ENABLE S1WR1
     DIALOG.ENABLE S1C1
     DIALOG.ENABLE S1A2
     DIALOG.ENABLE S1AR2
     DIALOG.ENABLE S1WR2
     DIALOG.ENABLE S1C2
     DIALOG.ENABLE S1A3
     DIALOG.ENABLE S1AR3
     DIALOG.ENABLE S1WR3
     DIALOG.ENABLE S1C3
     DIALOG.ENABLE S1D1
     DIALOG.ENABLE S1D2
     DIALOG.ENABLE S1D3
   )
   IF &ret==0.&&&spres=="Goto Level2"
   (
     DIALOG.ENABLE S2A1
     DIALOG.ENABLE S2AR1
     DIALOG.ENABLE S2WR1
     DIALOG.ENABLE S2C1
     DIALOG.ENABLE S2A2
     DIALOG.ENABLE S2AR2
     DIALOG.ENABLE S2WR2
     DIALOG.ENABLE S2C2
     DIALOG.ENABLE S2A3
     DIALOG.ENABLE S2AR3
     DIALOG.ENABLE S2WR3
     DIALOG.ENABLE S2C3
     DIALOG.ENABLE S2D1
     DIALOG.ENABLE S2D2
     DIALOG.ENABLE S2D3
   )
  RETURN &ret

CheckCount:
   LOCAL &spres &cval &cunit &ret &msg &level &txt
   ENTRY &spres &level
   &ret=0.
   IF &hac==1.
   (
     IF &spres=="NOT COUNT0"||&spres=="NOT COUNT1"
     (
       &txt=&spres+" not allowed with HAC !"
       PRINT %ERROR "&txt"
       &ret=1.
     )
   )
   IF &ret==0.&&(&spres=="COUNT0"||&spres=="NOT COUNT0")
   (
     IF dialog.string(EC0)==""
     (
       IF &debug==1.
         do diacount
       ELSE
         do ~~/demo/analyzer/trigger/diacount
       ENTRY &cval &cunit
       IF &cval!="0."&&&cval!=""
       (
         DIALOG.SET EC0 &cval
         DIALOG.SET PC0 &cunit
       )
       ELSE
         &ret=1.
     )
     ELSE
     (
       IF &hac==1.&&&level==0.&&dialog.string(PC0)!=""
       (
         &txts="In Level"+"&level"+" Time-Counter "+&spres+" not allowed to use with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
     )
   )
   IF &ret==0.&&(&spres=="COUNT1"||&spres=="NOT COUNT1")
   (
     IF dialog.string(EC1)==""
     (
       IF &debug==1.
         do diacount
       ELSE
         do ~~/demo/analyzer/trigger/diacount
       ENTRY &cval &cunit
       IF &cval!="0."&&&cval!=""
       (
         DIALOG.SET EC1 &cval
         DIALOG.SET PC1 &cunit
       )
       ELSE
         &ret=1.
     )
     ELSE
     (
       IF &hac==1.&&&level==0.&&dialog.string(PC1)!=""
       (
         &txt="In Level"+"&level"+" Time-Counter "+&spres+" not allowed to use with HAC !"
         PRINT %ERROR "&txt"
         &ret=1.
       )
     )
   )
  RETURN &ret
; --------------------------------------------------------------------------------
;                             Spezialitaeten HAC
; --------------------------------------------------------------------------------
CheckHACModel:
  LOCAL &mod &mask1 &mask2 &mask3 &mask4 &act
  &mod=0.
  IF &hac==1.
  (
    GOSUB GetLineMask 0. 1.
    ENTRY &mask1 &act
    IF &act==""
      &mask1=0y11111111
    GOSUB GetLineMask 0. 2.
    ENTRY &mask2 &act
    IF &act==""
      &mask2=&mask1
    GOSUB GetLineMask 0. 3.
    ENTRY &mask3 &act
    IF &act==""
      &mask3=&mask2
    GOSUB GetLineMask 0. 4.
    ENTRY &mask4 &act
    IF &act==""
      &mask4=&mask3

    IF &mask1==0y11111111&&&mask2==0y11111111&&&mask3==0y11111111&&&mask4==0y11111111
    (
      &mask1=0y0
      &mask2=0y0
      &mask3=0y0
      &mask3=0y0
    )
    ELSE IF &mask1==0y11111111&&&mask2==0y11111111&&&mask3==0y11111111
    (
      &mask1=0y0
      &mask2=0y0
    )
    ELSE IF &mask1==0y11111111&&&mask2==0y11111111
      &mask1=0y0

    IF (&mask4==0y0&&&mask3==0y0&&&mask2==0y0&&&mask1==0y11000000)||(&mask4==0y0&&&mask3==0y0&&&mask1==0y0&&&mask2==0y11000000)
      &mod=1.
    ELSE IF (&mask4==0y0&&&mask2==0y0&&&mask1==0y0&&&mask3==0y11000000)||(&mask3==0y0&&&mask2==0y0&&&mask1==0y0&&&mask4==0y11000000)
      &mod=1.
    ELSE IF &mask1!=0y0&&&mask2!=0y0&&&mask3==0y0&&&mask4==0y0&&&mask1==&mask2
    (
      IF &mask1==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1!=0y0&&&mask3!=0y0&&&mask2==0y0&&&mask4==0y0&&&mask1==&mask3
    (
      IF &mask1==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1!=0y0&&&mask4!=0y0&&&mask2==0y0&&&mask3==0y0&&&mask1==&mask4
    (
      IF &mask1==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask2!=0y0&&&mask3!=0y0&&&mask1==0y0&&&mask4==0y0&&&mask2==&mask3
    (
      IF &mask2==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask2!=0y0&&&mask4!=0y0&&&mask1==0y0&&&mask3==0y0&&&mask2==&mask4
    (
      IF &mask2==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask3!=0y0&&&mask4!=0y0&&&mask1==0y0&&&mask2==0y0&&&mask3==&mask4
    (
      IF &mask3==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1!=0y0&&&mask2==0y0&&&mask3==0y0&&&mask4==0y0
    (
      IF &mask1==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1==0y0&&&mask2!=0y0&&&mask3==0y0&&&mask4==0y0
    (
      IF &mask2==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1==0y0&&&mask2==0y0&&&mask3!=0y0&&&mask4==0y0
    (
      IF &mask3==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1==0y0&&&mask2==0y0&&&mask3==0y0&&&mask4!=0y0
    (
      IF &mask4==0y11000000
        &mod=1.
      ELSE
        &mod=2.
    )
    ELSE IF &mask1!=0y0&&&mask2!=0y0&&&mask3!=0y0&&&mask4==0y0
    (
      IF (&mask1==0y11000000&&&mask2==&mask3)||(&mask2==0y11000000&&&mask1==&mask3)||(&mask3==0y11000000&&&mask1==&mask2)||(&mask1==&mask2&&&mask2==&mask3)
        &mod=2.
      ELSE
        &mod=-1.
    )
    ELSE IF &mask1!=0y0&&&mask2==0y0&&&mask3!=0y0&&&mask4!=0y0
    (
      IF (&mask1==0y11000000&&&mask3==&mask4)||(&mask3==0y11000000&&&mask1==&mask4)||(&mask4==0y11000000&&&mask1==&mask3)||(&mask1==&mask3&&&mask3==&mask4)
        &mod=2.
      ELSE
        &mod=-1.
    )
    ELSE IF &mask1!=0y0&&&mask2!=0y0&&&mask3==0y0&&&mask4!=0y0
    (
      IF (&mask1==0y11000000&&&mask2==&mask4)||(&mask2==0y11000000&&&mask1==&mask4)
        &mod=2.
      ELSE IF (&mask4==0y11000000&&&mask1==&mask2)||(&mask1==&mask2&&&mask2==&mask4)
        &mod=2.
      ELSE
          &mod=-1.
    )
    ELSE IF &mask1==0y0&&&mask2!=0y0&&&mask3!=0y0&&&mask4!=0y0
    (
      IF (&mask2==0y11000000&&&mask3==&mask4)||(&mask3==0y11000000&&&mask2==&mask4)
        &mod=2.
      ELSE IF (&mask4==0y11000000&&&mask2==&mask3)||(&mask2==&mask3&&&mask3==&mask4)
        &mod=2.
      ELSE
        &mod=-1.
    )
    ELSE IF &mask1!=0y0&&&mask2!=0y0&&&mask3!=0y0&&&mask4!=0y0
    (
      IF (&mask1==0y11000000&&&mask2==&mask3&&&mask3==&mask4)||(&mask2==0y11000000&&&mask1==&mask3&&&mask3==&mask4)
        &mod=1.
      ELSE IF (&mask3==0y11000000&&&mask1==&mask2&&&mask2==&mask4)||(&mask4==0y11000000&&&mask1==&mask2&&&mask2==&mask3)
        &mod=1.
      ELSE IF &mask1==&mask2&&&mask2==&mask3&&&mask3==&mask4
        &mod=1.
      ELSE IF &mask1==0y11000000&&((&mask2==&mask3&&&mask3!=&mask4)||(&mask2!=&mask3&&&mask3==&mask4))
        &mod=2.
      ELSE IF &mask2==0y11000000&&((&mask1==&mask3&&&mask3!=&mask4)||(&mask1!=&mask3&&&mask3==&mask4))
        &mod=2.
      ELSE IF &mask3==0y11000000&&((&mask1==&mask2&&&mask2!=&mask4)||(&mask1!=&mask2&&&mask2==&mask4))
        &mod=2.
      ELSE IF &mask4==0y11000000&&((&mask1==&mask2&&&mask2!=&mask3)||(&mask1!=&mask2&&&mask2==&mask3))
        &mod=2.
      ELSE IF (&mask1==&mask2&&&mask2!=&mask3&&&mask3==&mask4)||(&mask1==&mask3&&&mask1!=&mask2&&&mask2==&mask4)
        &mod=2.
      ELSE IF (&mask1==&mask4&&&mask1!=&mask2&&&mask2==&mask3)
        &mod=2.
      ELSE IF (&mask1!=&mask2&&&mask2==&mask3&&&mask3==&mask4)||(&mask2==&mask1&&&mask1==&mask3&&&mask3==&mask4)
        &mod=2.
      ELSE IF (&mask3==&mask1&&&mask1==&mask2&&&mask2==&mask4)||(&mask4==&mask1&&&mask1==&mask2&&&mask2==&mask3)
        &mod=2.
      ELSE
        &mod=-1.
    )
  )
  RETURN &mod

GetLineMask:
  LOCAL &level &line &mask &a &r &rw &d &c
  ENTRY &level &line
  &mask=0y00000000
  GOSUB GetXLineY &level &line
  ENTRY &a &r &rw &d &c
  IF "&r"=="AB"
    &mask=0y10000000
  ELSE IF "&r"=="BB"
    &mask=0y01000000
  ELSE IF "&r"=="CB"
    &mask=0y11000000
  ELSE IF "&r"=="READ"
    &mask=0y00100000
  ELSE IF "&r"=="WRITE"
    &mask=0y00010000
  ELSE IF "&r"=="(READ||WRITE)"
    &mask=0y00110000
  ELSE IF "&r"=="DATA0"
    &mask=0y00001000
  ELSE IF "&r"=="DATA1"
    &mask=0y00000100
  ELSE IF "&r"=="COUNT0"
    &mask=0y00000010
  ELSE IF "&r"=="COUNT1"
    &mask=0y00000001

  IF "&rw"=="READ"
    &mask=&mask|0y00100000
  ELSE IF "&rw"=="WRITE"
    &mask=&mask|0y00010000
  ELSE IF "&rw"=="(READ||WRITE)"
    &mask=&mask|0y00110000
  ELSE IF "&rw"=="DATA0"
    &mask=&mask|0y00001000
  ELSE IF "&rw"=="DATA1"
    &mask=&mask|0y00000100
  ELSE IF "&rw"=="COUNT0"
    &mask=&mask|0y00000010
  ELSE IF "&rw"=="COUNT1"
    &mask=&mask|0y00000001

  IF "&d"=="DATA0"
    &mask=&mask|0y00001000
  ELSE IF "&d"=="DATA1"
    &mask=&mask|0y00000100
  ELSE IF "&d"=="COUNT0"
    &mask=&mask|0y00000010
  ELSE IF "&d"=="COUNT1"
    &mask=&mask|0y00000001

  IF "&c"=="COUNT0"
    &mask=&mask|0y00000010
  ELSE IF "&c"=="COUNT1"
    &mask=&mask|0y00000001

  RETURN &mask &a

CheckHACRules:
  LOCAL &markc &markc1 &markc2 &txt &ret &markx &markcxx &markcxxx
  &maskc=0.
  GOSUB CheckLevel0 0.
  ENTRY &markc &ret
  &hacmod=0.
  IF &ret==2.
  (
    IF &hacmod!=1.
      &hacmod=1.
    &ret=0.
  )
  ELSE IF &ret==3.
  (
    IF &hacmod!=2.
      &hacmod=2.
    &ret=0.
  )
  ELSE IF &ret==1.
    &ret=-1.
  IF &ret==0.
  (
    IF &hacmod==2.
      GOSUB CheckLevelX 1.
    ELSE
      GOSUB CheckLevel0 1.
    ENTRY &markc1 &ret
    IF &ret==1.
      &ret=-1.
    ELSE IF &hacmod==2.
      &ret=&hacmod
    ELSE
      &ret=0.
    &markx=&markc&0y10000000
    &markcxx=&markc1&0y10000000
    IF &markcxx==0y0&&&markx==0y10000000
    (
      &txt="Mark C must be used in Level1 too.!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    IF &markcxx==0y10000000&&&markx==0y0
    (
      &txt="Mark C must be used in Level0 too.!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    &markx=&markc&0y01000000
    &markcxx=&markc1&0y01000000
    IF &markcxx==0y01000000&&&markx==0y01000000
    (
      &txt="Count0 only allowed to used in one level!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    &markx=&markc&0y00100000
    &markcxx=&markc1&0y00100000
    IF &markcxx==0y00100000&&&markx==0y00100000
    (
      &txt="Count1 only allowed to used in one level!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    &markx=&markc&0y00010000
    &markcxx=&markc1&0y00010000
    IF &markcxx==0y00010000&&&markx==0y00010000
    (
      &txt="Data0 only allowed to used in one level!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    &markx=&markc&0y00001000
    &markcxx=&markc1&0y00001000
    IF &markcxx==0y00001000&&&markx==0y00001000
    (
      &txt="Data1 only allowed to used in one level!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
  )
  IF &ret==0.
  (
    GOSUB CheckLevelX 2.
    ENTRY &markc2 &ret
    IF &ret==1.
      &ret=-1.
    ELSE
      &ret=&hacmod

    &markx=&markc&0y10000000
    &markcxxx=&markc2&0y10000000
    IF &ret>0.&&&markcxxx==0y0&&&markx==0y10000000
    (
      &txt="Mark C must be used in Level2 too.!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    IF &ret>0.&&&markcxxx==0y10000000&&&markx==0y0
    (
      &txt="Mark C must be used in Level0 and Level1 too.!"
      PRINT %ERROR "&txt"
      &ret=-1.
    )
    IF &ret>0.
    (
      &markx=&markc&0y01000000
      &markcxx=&markc1&0y01000000
      &markcxxx=&markc2&0y01000000
      IF (&markcxxx==0y01000000&&&markx==0y01000000)||(&markcxxx==0y01000000&&&markcxx==0y01000000)
      (
        &txt="Count0 only allowed to used in one level!"
        PRINT %ERROR "&txt"
        &ret=-1.
      )
      &markx=&markc&0y00100000
      &markcxx=&markc1&0y00100000
      &markcxxx=&markc2&0y00100000
      IF (&markcxxx==0y00100000&&&markx==0y00100000)||(&markcxxx==0y00100000&&&markcxx==0y00100000)
      (
        &txt="Count1 only allowed to used in one level!"
        PRINT %ERROR "&txt"
        &ret=-1.
      )
      &markcxxx=&markc2&0y00010000
      IF &markcxxx==0y00010000
      (
        &txt="Data0 only allowed to used in level &level!"
        PRINT %ERROR "&txt"
        &ret=-1.
      )
      &markcxx=&markc2&0y00001000
      IF &markcxxx==0y00001000
      (
        &txt="Data1 only allowed to used in level &level!"
        PRINT %ERROR "&txt"
        &ret=-1.
      )
    )
  )
  RETURN &ret

CheckLevel0:
  LOCAL &markc &txt &ret &rmask1 &rmask2 &rmask3 &rmask4 &cmask &level
  LOCAL &tp0 &tp1 &tp0oC &tp1oC &stp0 &stp1 &gtpx &maskx &actx &i &wend
  ENTRY &level
  ;Check Level0 first
  &tp0=-1.
  &tp1=-1.
  &stp0=-1.
  &stp1=-1.
  &tp0oC=-1.
  &tp1oC=-1.
  &gtpx=0y00000000
  &i=1.
  &ret=0.
  &markc=0y0
  &cmask=0y00000000
  IF &level==0.
    &wend=4.
  ELSE
    &wend=3.
  GOSUB GetLineMask &level &i
  ENTRY &maskx &actx
  IF &actx=="Mark C"
    &markc=0y10000000
  IF &actx=="Mark C"&&&maskx!=0y11000000
  (
    &txt="Mark C only allowed with condition C-Range in Level&level !"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  &rmask3=&maskx&0y11000000
  IF &actx!="Mark C"&&&rmask3==0y11000000
  (
    &txt="C-Range only allowed with Mark C in Level&level !"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF (&actx=="Restart COUNT0"&&&maskx!=0y00000010)||(&actx=="Restart COUNT1"&&&maskx!=0y00000001)
  (
    IF &actx=="Restart COUNT0"
      &txt=&actx+" only allowed with this Count0 condition! (Level&level line &i)"
    ELSE
      &txt=&actx+" only allowed with this Count1 condition! (Level&level line &i)"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  ELSE IF &actx=="Restart COUNT0"&&&maskx==0y00000010
    &markc=&markc|0y00000100
  ELSE IF &actx=="Restart COUNT1"&&&maskx==0y00000001
    &markc=&markc|0y00000010

  IF &maskx!=0y0&&&markc==0.
  (
    &rmask1=&maskx&0y11000000
    &rmask2=&maskx&0y01000000
    &rmask3=&maskx&0y00000010
    &rmask4=&maskx&0y00000001
    IF &actx!="Sample"&&&rmask1!=0y11000000&&&rmask2==0y01000000
      &tp1=&maskx
    ELSE IF &actx!="Sample"
      &tp0=&maskx
    IF (&actx=="Inc COUNT0"||&actx=="Inc COUNT1")&&(&rmask3!=0y0||&rmask4!=0y0)
    (
      &txt=&actx+" only allowed without any Count condition! (Level&level line &i)"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    IF &ret==0.&&(&actx=="Inc COUNT0"||&actx=="Inc COUNT1")
    (
      IF &tp0>=0y0
      (
        &tp0oC=&maskx
        &tp0=-1.
        IF &actx=="Inc COUNT0"
          &cmask=0y10000000
        ELSE IF &actx=="Inc COUNT1"
          &cmask=0y01000000
      )
      IF &tp1>=0y0
      (
        &tp1oC=&maskx
        &tp1=-1.
        IF &actx=="Inc COUNT0"
          &cmask=0y00100000
        ELSE IF &actx=="Inc COUNT1"
          &cmask=0y00010000
      )
    )
    IF &ret==0.&&&actx=="Sample"&&&rmask2==0y01000000
    (
      &tp1oC=&maskx&0y11111100
      IF &tp1oC!=&maskx
        &tp1=&maskx
      &stp1=&maskx
    )
    ELSE IF &ret==0.&&&actx=="Sample"
    (
      &tp0oC=&maskx&0y11111100
      IF &tp0oC!=&maskx
        &tp0=&maskx
      &stp0=&maskx
    )
  )
  ELSE IF &markc==0.
  (
    IF &actx!=""&&&actx!="Sample"&&&actx!="Mark C"&&&actx!="Mark B"
    (
      &tp0=0y0
      IF &actx=="Inc COUNT0"
        &cmask=0y10000000
      ELSE IF &actx=="Inc COUNT1"
        &cmask=0y01000000
    )
    ELSE IF &actx=="Mark B"
      &tp1=0y0
    ELSE &actx=="Sample"
      &tp0oC=0y0
  )
  IF &ret==0.&&(&actx=="Goto Level1"||&actx=="Goto Level2"||&actx=="Stop Analyzer"||&actx=="Stop CPU&Analyzer")
  (
    IF (&actx=="Goto Level1"||&actx=="Goto Level2")&&&tp0==&maskx
      &gtpx=0y10000000
    ELSE IF (&actx=="Goto Level1"||&actx=="Goto Level2")&&&tp1==&maskx
      &gtpx=0y01000000
    ELSE IF &actx=="Stop Analyzer"&&&tp0==&maskx
      &gtpx=0y00100000
    ELSE IF &actx=="Stop Analyzer"&&&tp1==&maskx
      &gtpx=0y00010000
    ELSE IF &actx=="Stop CPU&Analyzer"&&&tp0==&maskx
      &gtpx=0y00001000
    ELSE IF &actx=="Stop CPU&Analyzer"&&&tp1==&maskx
      &gtpx=0y00000100
  )
  IF &tp0>=0y0
    &tp0oC=&tp0&0y11111100
  IF &tp1>=0y0
    &tp1oC=&tp1&0y11111100

  while &ret==0.&&&i<&wend
  (
    LOCAL &oCmask
    &i=&i+1.
    GOSUB GetLineMask &level &i
    ENTRY &maskx &actx
    IF &actx=="Mark C"
      &markc=&markc|0y10000000
    IF &actx=="Mark C"&&&maskx!=0y11000000
    (
      &txt="Mark C only allowed with condition C-Range in Level&level !"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    &rmask3=&maskx&0y11000000
    IF &actx!="Mark C"&&&rmask3==0y11000000
    (
      &txt="C-Range only allowed with Mark C in Level&level !"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    IF (&actx=="Restart COUNT0"&&&maskx!=0y00000010)||(&actx=="Restart COUNT1"&&&maskx!=0y00000001)
    (
      IF &actx=="Restart COUNT0"
        &txt=&actx+" only allowed with Count0 condition! (Level&level line &i)"
      ELSE
        &txt=&actx+" only allowed with Count1 condition! (Level&level line &i)"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &actx=="Restart COUNT0"&&&maskx==0y00000010
      &markc=&markc|0y00000100
    ELSE IF &actx=="Restart COUNT1"&&&maskx==0y00000001
      &markc=&markc|0y00000010
    &rmask3=&maskx&0y00000010
    &rmask4=&maskx&0y00000001
    &oCmask=&maskx&0y11111100
    IF &maskx!=0y0&&&actx!="Mark C"&&&actx!="Restart COUNT0"&&&actx!="Restart COUNT1"
    (
      IF (&actx=="Inc COUNT0"||&actx=="Inc COUNT1")&&(&rmask3!=0y0||&rmask4!=0y0)
      (
        &txt=&actx+" only allowed without any Count condition! (Level&level line &i)"
        PRINT %ERROR "&txt"
        &ret=1.
      )

      IF &ret==0.&&(&actx=="Inc COUNT0"||&actx=="Inc COUNT1")
      (
        LOCAL &tpcount &tp0count &tp1count
        IF &tp0>=0y0
        (
          IF &tp0oC<0y0
            &tp0oC=&tp0&0y11111100
          IF &tp0oC!=&oCmask
          (
            IF &tp1>=0y0
            (
              IF &tp1oC<0y0
                &tp1oC=&tp1&0y11111100
              IF &tp1oC!=&oCmask
              (
                &txt="Condition Level&level line &i condition variant not allowed with HAC!"
                PRINT %ERROR "&txt"
                &ret=1.
              )
            )
            ELSE IF &tp1oC>=0y0&&&tp1oC!=&oCmask
            (
              &txt="Condition(c2) Level&level line &i condition variant not allowed with HAC!"
              PRINT %ERROR "&txt"
              &ret=1.
            )
            ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)&&&level!=0.
            (
              &txt="Condition(c2) Level&level line &i condition variant not allowed with HAC!"
              PRINT %ERROR "&txt"
              &ret=1.
            )
            ELSE IF &level==1.&&&tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
            (
              &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
              PRINT %ERROR "&txt"
              &ret=1.
            )
            ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
              &tp1oC=&maskx&0y11111100
          )
        )
        ELSE IF &tp1oC>=0y0&&&tp1oC!=&oCmask
        (
          &txt="Condition(c2) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp1>=0y0
        (
          IF &tp1oC<0y0
            &tp1oC=&tp1&0y11111100
          IF &tp1oC!=&oCmask&&&tp1!=&maskx
          (
            &txt="Condition Level&level line &i condition variant not allowed with HAC!"
            PRINT %ERROR "&txt"
            &ret=1.
          )
        )
        ELSE IF &tp1>=0y0&&&tp1oC>=0y0&&&tp1oC!=&oCmask&&&tp1!=&maskx
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp1oC>=0y0&&&tp1oC!=&oCmask
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &level==1.&&&tp1>=0&&&tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp1oC!=&maskx&&&tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
          &tp0oC=&maskx&0y11111100
        ELSE IF &level==1.&&&tp0>=0&&&tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
          &tp1oC=&maskx&0y11111100

        IF &actx=="Inc COUNT0"&&(&tp0==&maskx||&tp0oC==&maskx)
          &cmask=&cmask|0y10000000
        ELSE IF &actx=="Inc COUNT1"&&(&tp0==&maskx||&tp0oC==&maskx)
          &cmask=&cmask|0y01000000
        IF &actx=="Inc COUNT0"&&(&tp1==&maskx||&tp1oC==&maskx)
          &cmask=&cmask|0y00100000
        ELSE IF &actx=="Inc COUNT1"&&(&tp1==&maskx||&tp1oC==&maskx)
          &cmask=&cmask|0y00010000
        &tp0count=0y0
        &tp1count=0y0
        IF &tp0>=0y0
          &tp0count=&tp0&0y00000011
        IF &tp1>=0y0
          &tp1count=&tp1&0y00000011
        IF (&actx=="Inc COUNT0"&&&tp0==&maskx&&(&tp0count==0y00000001||&tp1count==0y00000010))||(&actx=="Inc COUNT0"&&&tp1==&maskx&&(&tp1count==0y00000001||&tp0count==0y00000010))
        (
          &txt=&actx+" could not be used with this condition variant with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF (&actx=="Inc COUNT1"&&&tp0==&maskx&&(&tp0count==0y00000010||&tp1count==0y00000001))||(&actx=="Inc COUNT1"&&&tp1==&maskx&&(&tp1count==0y00000010||&tp0count==0y00000001))
        (
          &txt=&actx+" could not be used with this condition variant with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        &tp0count=0y0
        &tp1count=0y0
        IF &stp0>=0y0
          &tp0count=&stp0&0y00000011
        IF &stp1>=0y0
          &tp1count=&stp1&0y00000011
        IF (&actx=="Inc COUNT0"&&&tp0==&maskx&&(&tp0count==0y00000001||&tp1count==0y00000010))||(&actx=="Inc COUNT0"&&&tp1==&maskx&&(&tp1count==0y00000001||&tp0count==0y00000010))
        (
          &txt=&actx+" could not be used with this condition variant with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF (&actx=="Inc COUNT1"&&&tp0==&maskx&&(&tp0count==0y00000010||&tp1count==0y00000001))||(&actx=="Inc COUNT1"&&&tp1==&maskx&&(&tp1count==0y00000010||&tp0count==0y00000001))
        (
          &txt=&actx+" could not be used with this condition variant with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
      IF &ret==0.&&&actx=="Sample"
      (
        IF &tp0>=0y0||&tp0oC>=0y0
        (
          IF &tp0oC<0y0
            &tp0oC=&tp0&0y11111100
          IF &tp0oC!=&oCmask&&&tp0!=&maskx
          (
            IF &tp1>=0y0
            (
              IF &tp1oC<0y0
                &tp1oC=&tp1&0y11111100
              IF (&tp1!=&tp1oC&&&tp1oC!=&oCmask&&&tp1!=&maskx)||(&tp1==&tp1oC&&&tp1!=&maskx)
              (
                &txt="Condition Level&level line &i condition variant not allowed with HAC!"
                PRINT %ERROR "&txt"
                &ret=1.
              )
            )
            ELSE IF (&tp1oC>=0y0&&&tp1oC!=&oCmask)||(&tp0==&tp0oC&&&tp0==&oCmask)
            (
              &txt="Condition Level&level line &i condition variant not allowed with HAC!"
              PRINT %ERROR "&txt"
              &ret=1.
            )
            ELSE IF &tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
            (
              &tp0oC=&maskx&0y11111100
              IF &tp0oC!=&maskx
                &tp0=&maskx
              &stp0=&maskx
            )
            ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
            (
              &tp1oC=&maskx&0y11111100
              IF &tp1oC!=&maskx
                &tp1=&maskx
              &stp1=&maskx
            )
          )
          ELSE IF &tp0oC==&oCmask&&&tp0<0y0
          (
            &tp0=&maskx
            &stp0=&maskx
          )
          ELSE IF &tp0==&tp0oC&&&tp0!=&oCmask
          (
            &txt="Condition Level&level line &i condition variant not allowed with HAC!"
            PRINT %ERROR "&txt"
            &ret=1.
          )
        )
        ELSE IF &tp1>=0y0||&tp1oC>=0y0
        (
          IF &tp1oC<0y0
            &tp1oC=&tp1&0y11111100

          IF (&tp0>=0y0&&&tp1oC!=&oCmask&&&tp1!=&maskx)||(&tp1==&tp1oC&&&tp1==&oCmask)
          (
            &txt="Condition Level&level line &i condition variant not allowed with HAC!"
            PRINT %ERROR "&txt"
            &ret=1.
          )
          ELSE IF &tp1<0y0&&&tp1oC==&oCmask
          (
            &tp1=&maskx
            &stp1=&maskx
          )
          ELSE IF &tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
          (
            &tp0oC=&maskx&0y11111100
            IF &tp0oC!=&maskx
              &tp0=&maskx
            &stp0=&maskx
          )
        )
        ELSE IF (&tp1oC>=0y0&&&tp1oC!=&oCmask)
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
        (
          &tp0oC=&maskx&0y11111100
          IF &tp0oC!=&maskx
            &tp0=&maskx
          &stp0=&maskx
        )
        ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &tp1oC=&maskx&0y11111100
          IF &tp1oC!=&maskx
            &tp1=&maskx
          &stp1=&maskx
        )
        IF (&tp0==&maskx||&tp0==&oCmask)
          &stp0=&maskx
        ELSE IF (&tp1==&maskx||&tp1==&oCmask)
          &stp1=&maskx
      )
      IF &ret==0.&&&actx=="Mark B"
      (
        IF (&tp1>=0y0&&&tp1!=&maskx)||(&tp1<0y0&&&tp1oC>=0y0&&&oCmask!=&tp1oC)
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &level==1.&&&tp0>=0&&&tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &tp1=&maskx
          &tp1oC=&tp1&0y11111100
        )
      )
      IF &ret==0.&&&actx=="Mark A"
      (
        IF (&tp0>=0y0&&&tp0!=&maskx)||(&tp0<0y0&&&tp0oC>=0y0&&&oCmask!=&tp0oC)
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &level==1.&&&tp1>=0&&&tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp0<0y0&&(&tp0oC<=0y0||&oCmask==&tp0oC)
        (
          &tp0=&maskx
          &tp0oC=&tp0&0y11111100
        )
      )
      IF &ret==0.&&&actx!=""&&(&actx=="Goto Level1"||&actx=="Goto Level2"||&actx=="Stop Analyzer"||&actx=="Stop CPU&Analyzer")
      (
        IF &tp0>=0y0&&&tp0!=&maskx
        (
          IF (&tp1>=0y0&&&tp1!=&maskx)||(&tp1<0y0&&&tp1oC>=0y0&&&oCmask!=&tp1oC)
          (
            &txt="Condition Level&level line &i condition variant not allowed with HAC!"
            PRINT %ERROR "&txt"
            &ret=1.
          )
          ELSE IF &tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
          (
            &tp1=&maskx
            &tp1oC=&tp1&0y11111100
          )
        )
        ELSE IF &level==1.&&&tp1>=0&&&tp1!=&maskx&&&tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp1!=&maskx&&&tp0<0y0&&(&tp0oC<=0y0||&oCmask==&tp0oC)
        (
          &tp0=&maskx
          &tp0oC=&tp0&0y11111100
        )
        ELSE IF &level==1.&&&tp0>=0&&&tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp0!=&maskx&&&tp1<0y0&&(&tp1oC<=0y0||&oCmask==&tp1oC)
        (
          &tp1=&maskx
          &tp1oC=&tp1&0y11111100
        )
        ELSE IF (&tp0<0y0&&&tp0oC>=0y0&&&oCmask!=&tp0oC)||(&tp1<0y0&&&tp1oC>=0y0&&&oCmask!=&tp1oC)||(&tp1>=0y0&&&tp1!=&maskx)
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
      IF &ret==0.&&&rmask3!=0y0
      (
        &rmask1=0y0
        &rmask2=0y0
        &rmask3=0y0
        &rmask4=0y0
        IF &tp0>=0y0
        (
          &rmask1=&tp0&0y00000010
          &rmask2=&cmask&0y00100000
        )
        IF &tp1>=0y0
        (
          &rmask3=&tp1&0y00000010
          &rmask4=&cmask&0y10000000
        )
        IF &rmask1==&rmask3
        (
          &txt="COUNT0 could not be used with two conditions with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF (&rmask1!=0y0&&&rmask2!=0y0)||(&rmask3!=0y0&&&rmask4!=0y0)
        (
          &txt="COUNT0 could not be used in this condition variant with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
      ELSE IF &ret==0.&&&rmask4!=0y0
      (
        &rmask1=0y0
        &rmask2=0y0
        &rmask3=0y0
        &rmask4=0y0
        IF &tp0>=0y0
        (
          &rmask1=&tp0&0y00000001
          &rmask2=&cmask&0y00010000
        )
        IF &tp1>=0y0
        (
          &rmask3=&tp1&0y00000001
          &rmask4=&cmask&0y01000000
        )
        IF &rmask1==&rmask3
        (
          &txt="COUNT1 could not be used with two conditions with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF (&rmask1!=0y0&&&rmask2!=0y0)||(&rmask3!=0y0&&&rmask4!=0y0)
        (
          &txt="COUNT1 could not be used in this condition variant with HAC! (Level&level line &i)"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
    )
    ELSE IF &actx!="Mark C"&&&actx!="Restart COUNT0"&&&actx!="Restart COUNT1"
    (
      IF &actx!=""&&&actx!="Sample"&&&actx!="Mark B"
      (
        IF &level==1.&&&tp1>=0&&&tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &actx!="Inc COUNT0"&&&actx!="Inc COUNT1"&&&tp0<0y0&&(&tp0oC<=0y0||&tp0oC==&oCmask)
        (
          &tp0=0y0
          &tp0oC=0y0
        )
        ELSE IF &level==1.&&&tp0>=0&&&tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &tp0>0y0&&&tp1<0y0&&(&tp1oC<=0y0||&tp1oC==&oCmask)
        (
          &tp1=0y0
          &tp1oC=0y0
        )
        ELSE IF &tp0>0y0&&&tp1>0y0
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        IF &actx=="Inc COUNT0"&&(&tp0==&maskx||&tp0oC==&maskx)
          &cmask=&cmask|0y10000000
        ELSE IF &actx=="Inc COUNT1"&&(&tp0==&maskx||&tp0oC==&maskx)
          &cmask=&cmask|0y01000000
        IF &actx=="Inc COUNT0"&&(&tp1==&maskx||&tp1oC==&maskx)
          &cmask=&cmask|0y00100000
        ELSE IF &actx=="Inc COUNT1"&&(&tp1==&maskx||&tp1oC==&maskx)
          &cmask=&cmask|0y00010000
      )
      ELSE IF &actx=="Mark B"
      (
        IF &tp1>0y0&&&tp1oC>0y0
        (
          &txt="Condition Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF &level==1.&&&tp0>=0&&&tp1<0y0
        (
          &txt="Condition(c1) Level&level line &i condition variant not allowed with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE
          &tp1=0y0
      )
    )
    IF &ret==0.&&(&actx=="Goto Level1"||&actx=="Goto Level2")&&&tp0==&maskx
      &gtpx=&gtpx|0y10000000
    ELSE IF &ret==0.&&(&actx=="Goto Level1"||&actx=="Goto Level2")&&&tp1==&maskx
      &gtpx=&gtpx|0y01000000
    ELSE IF &ret==0.&&&actx=="Stop Analyzer"&&&tp0==&maskx
      &gtpx=&gtpx|0y00100000
    ELSE IF &ret==0.&&&actx=="Stop Analyzer"&&&tp1==&maskx
      &gtpx=&gtpx|0y00010000
    ELSE IF &ret==0.&&&actx=="Stop CPU&Analyzer"&&&tp0==&maskx
      &gtpx=&gtpx|0y00001000
    ELSE IF &ret==0.&&&actx=="Stop CPU&Analyzer"&&&tp1==&maskx
      &gtpx=&gtpx|0y00000100
  ) ;while

  IF &tp0oC>=0y0&&&tp0<0y0
    &tp0=&tp0oC
  IF &tp1oC>=0y0&&&tp1<0y0
    &tp1=&tp1oC
  IF &ret==0.&&&tp0>=0&&&tp1>=0
  (
    &rmask3=&tp0&0y00001100
    &rmask4=&tp1&0y00001100
    IF &rmask3==&rmask4&&&rmask3!=0y0&&&rmask4!=0y0
    (
      IF &rmask3==0y00001000
        &txt="DATA0 cannot be used with two conditions in level &level with HAC!"
      ELSE
        &txt="DATA1 cannot be used with two conditions in level &level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )

  IF &ret==0.
  (
    &rmask4=0y0
    &rmask4=&cmask&0y11000000
    IF &tp0!=&tp0oC&&&rmask4!=0y10000000&&&rmask4!=0y01000000
    (
      &rmask4=&tp0^&tp0oC
      IF &rmask4==0y00000010
        &txt="COUNT0 used but never set in level &level with HAC!"
      ELSE
        &txt="COUNT1 used but never set in level &level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &rmask4==0y10000000
      &markc=&markc|0y01000000
    ELSE IF &rmask4==0y01000000
      &markc=&markc|0y00100000
    &rmask4=&cmask&0y00110000
    IF &tp1!=&tp1oC&&&rmask4!=0y00100000&&&rmask4!=0y00010000
    (
      &rmask4=&tp1^&tp1oC
      IF &rmask4==0y00000010
        &txt="COUNT0 used but never set in level &level with HAC!"
      ELSE
        &txt="COUNT1 used but never set in level &level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &rmask4==0y00100000
      &markc=&markc|0y01000000
    ELSE IF &rmask4==0y00010000
      &markc=&markc|0y00100000

    IF &ret==0.
    (
      &rmask2=&cmask&0y10000000
      &rmask3=&cmask&0y00100000
      IF &rmask2!=0y0||&rmask3!=0y0
      (
        IF &rmask2!=0y0
          &rmask2=&tp0&0y00000010
        ELSE
          &rmask2=0y0
        IF &rmask3!=0y0
          &rmask3=&tp1&0y00000010
        ELSE
          &rmask3=0y0
        IF &rmask2==0y0&&&rmask3==0y0
        (
          &txt="COUNT0 set but never used in level &level with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
    )
    IF &ret==0.
    (
      &rmask2=&cmask&0y01000000
      &rmask3=&cmask&0y00010000
      IF &rmask2!=0y0||&rmask3!=0y0
      (
        IF &rmask2!=0y0
          &rmask2=&tp0&0y00000001
        ELSE
          &rmask2=0y0
        IF &rmask3!=0y0
          &rmask3=&tp1&0y00000001
        ELSE
          &rmask3=0y0
        IF &rmask2==0y0&&&rmask3==0y0
        (
          &txt="COUNT1 set but never used in level &level with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
    )
  )
  &rmask2=&gtpx&0y11000000
  &rmask3=&gtpx&0y00110000
  &rmask4=&gtpx&0y00001100
  IF &ret==0.&&((&rmask2!=0y0&&&rmask3!=0y0)||(&rmask2!=0y0&&&rmask4!=0y0)||(&rmask3!=0y0&&&rmask4!=0y0))
  (
    &txt="Only one of Goto LevelX, Stop Analyzer or Stop CPU&Analyzer could be used per Level with HAC!"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  &rmask4=0y0
  &rmask4=&gtpx&0y11000000
  IF &ret==0.&&&rmask4!=0y0
  (
    IF &ret==0.&&&tp0>=0y0&&&tp1>=0y0&&&rmask4!=0y11000000
    (
      &txt="Goto LevelX must be used for each condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0<0y0&&&tp1>=0y0&&&rmask4!=0y01000000
    (
      &txt="Goto LevelX must be used with correct condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0>=0y0&&&tp1<0y0&&&rmask4!=0y10000000
    (
      &txt="Goto LevelX must be used with correct condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )
  &rmask3=0y0
  &rmask3=&gtpx&0y00110000
  IF &ret==0.&&&rmask3!=0y0
  (
    IF &rmask4!=0y0
    (
      &txt="Stop Analyzer only allowed in last level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    IF &tp0>=0y0&&&tp1>=0y0&&&rmask3!=0y00110000
    (
      &txt="Stop Analyzer must be used for each condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0<0y0&&&tp1>=0y0&&&rmask3!=0y00010000
    (
      &txt="Stop Analyzer must be used with correct condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0>=0y0&&&tp1<0y0&&&rmask3!=0y00100000
    (
      &txt="Stop Analyzer must be used with correct condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )

  &rmask3=0y0
  &rmask3=&gtpx&0y00001100
  IF &ret==0.&&&rmask3!=0y0
  (
    IF &tp0>=0y0&&&tp1>=0y0&&&rmask3!=0y00001100
    (
      &txt="Stop CPU&Analyzer must be used for each condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0<0y0&&&tp1>=0y0&&&rmask3!=0y00000100
    (
      &txt="Stop CPU&Analyzer must be used with correct condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0>=0y0&&&tp1>0y0&&&rmask3!=0y00001000
    (
      &txt="Stop CPU&Analyzer must be used with correct condition with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )
  IF &ret==0.
  (
    IF &level==0.
    (
      IF &tp0>=0y0&&&tp1>=0y0
        &ret=3.
      ELSE IF &tp0>=0y0||&tp1>=0y0
        &ret=2.
    )
    IF &tp0>=0
    (
     &rmask3=&tp0&0y00001100
     IF &rmask3==0y00001000
       &markc=&markc|0y00010000
     ELSE IF &rmask3==0y00000100
       &markc=&markc|0y00001000
    )
    IF &tp1>=0
    (
     &rmask3=&tp1&0y00001100
     IF &rmask3==0y00001000
       &markc=&markc|0y00010000
     ELSE IF &rmask3==0y00000100
       &markc=&markc|0y00001000
    )
  )
  RETURN &markc &ret

CheckLevelX:
  LOCAL &markc &txt &ret &rmask1 &rmask2 &rmask3 &rmask4 &cmask &level
  LOCAL &tp0 &gtpx &maskx &actx &i &wend
  ENTRY &level
  &tp0=-1.
  &gtpx=0y0
  &i=1.
  &ret=0.
  &markc=0y0
  &cmask=0y0
  &wend=3.
  GOSUB GetLineMask &level &i
  ENTRY &maskx &actx
  IF &actx=="Mark C"
    &markc=0y10000000
  IF &actx=="Mark C"&&&maskx!=0y11000000
  (
    &txt="Mark C only allowed with condition C-Range in Level&level line &i!"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  &rmask3=&maskx&0y00111100
  IF &rmask3!=0y0
  (
    &txt="READ/WRITE or Data0/1 not allowed in Level&level !"
    PRINT %ERROR "&txt"
    &ret=1.
  )

  &rmask3=&maskx&0y11000000
  IF &actx!="Mark C"&&&rmask3==0y11000000
  (
    &txt="C-Range only allowed with Mark C in Level&level !"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF &actx=="Restart COUNT0"||&actx=="Restart COUNT1"||&actx=="Mark B"||&actx=="Mark A"
  (
    &txt=&actx+" not allowed in last Level&level line &i!"
    PRINT %ERROR "&txt"
    &ret=1.
  )

  IF &ret==0.&&&maskx!=0y0&&&markc==0y0
  (
    &rmask1=&maskx&0y11111100
    &rmask2=&maskx&0y01000000
    &rmask3=&maskx&0y00000010
    &rmask4=&maskx&0y00000001
    &oCmask=&maskx&0y11111100
    IF &oCmask==0y00000010
      &cmask=0y10000000
    ELSE IF &oCmask==0y00000001
      &cmask=0y01000000
    IF &rmask1!=0y0
    (
      &txt="Only Count0/1 allowed as condition in last Level&level line &i!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &actx=="Sample"&&&maskx!=0y0
    (
      &txt="Sample only allowed with no condition in Level&level line &i!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &actx!="Sample"
      &tp0=&maskx
    IF (&actx=="Inc COUNT0"||&actx=="Inc COUNT1")&&(&rmask3!=0y0||&rmask4!=0y0)
    (
      &txt=&actx+" only allowed without any Count condition! (Level&level line &i)"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &actx=="Inc COUNT0"||&actx=="Inc COUNT1"
    (
      IF &actx=="Inc COUNT0"
        &markc=&markc|0y01000000
      ELSE IF &actx=="Inc COUNT1"
        &markc=&markc|0y00100000
    )
  )
  ELSE IF &ret==0.&&&markc==0y0
  (
    IF &actx!=""&&&actx!="Mark C"&&&actx!="Sample"
      &tp0=0y0
    &rmask3=0y0
    &rmask4=0y0
  )
  IF &hacmod==2.&&&level==1.&&&actx=="Goto Level2"
  (
    &txt=&actx+" not allowed in condition c2! (Level&level line &i)"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF &ret==0.&&(&actx=="Goto Level0"||&actx=="Stop Analyzer"||&actx=="Stop CPU&Analyzer")
  (
    IF &rmask3==0y0&&&rmask4==0y0
    (
      &txt="Goto Level0, Stop Analyzer or Stop CPU&Analyzer need to have Count0/1 condition in last level! (Level&level line &i)"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    IF &actx=="Goto Level0"
      &gtpx=0y10000000
    IF &actx=="Stop Analyzer"&&&gtpx!=0y0
    (
      &txt=&actx+" not allowed with Goto! (Level&level line &i)"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &actx=="Stop Analyzer"&&&gtpx==0y0
      &gtpx=0y00100000
    IF &actx=="Stop CPU&Analyzer"&&&gtpx!=0y0
    (
      &txt=&actx+" not allowed with Goto or Stop Analyzer! (Level&level line &i)"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &actx=="Stop CPU&Analyzer"&&&gtpx==0y0
      &gtpx=0y00001000
  )
  &tp0oC=0y0

  while &ret==0.&&&i<&wend
  (
    LOCAL &oCmask
    &i=&i+1.
    GOSUB GetLineMask &level &i
    ENTRY &maskx &actx
    IF &actx=="Mark C"
      &markc=&markc|0y10000000
    IF &actx=="Mark C"&&&maskx!=0y11000000
    (
      &txt="Mark C only allowed without condition C-Range in Level&level !"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    &rmask3=&maskx&0y00111100
    IF &rmask3!=0y0
    (
      &txt="READ/WRITE or Data0/1 not allowed in Level&level !"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    &rmask3=&maskx&0y11000000
    IF &actx!="Mark C"&&&rmask3==0y11000000
    (
      &txt="C-Range only allowed with Mark C in Level&level !"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    IF &actx=="Restart COUNT0"||&actx=="Restart COUNT1"||&actx=="Mark B"||&actx=="Mark A"
    (
      &txt=&actx+" not allowed in last Level&level line &i!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    &rmask3=&maskx&0y00000010
    &rmask4=&maskx&0y00000001
    &oCmask=&maskx&0y11111100
    IF &rmask3==0y00000010
      &cmask=0y10000000
    ELSE IF &rmask4==0y00000001
      &cmask=0y01000000
    IF &maskx!=0y0&&&actx!="Mark C"
    (
      IF (&actx=="Inc COUNT0"||&actx=="Inc COUNT1")&&&oCmask!=0y0
      (
        &txt=&actx+" only allowed without any condition in last Level&level line &i!"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      IF &actx=="Inc COUNT0"
        &markc=&markc|0y01000000
      ELSE IF &actx=="Inc COUNT1"
        &markc=&markc|0y00100000

      IF &ret==0.&&&actx=="Sample"
      (
        IF &maskx!=0y0
        (
          &txt="Sample only allowed with no condition in Level&level line &i!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
        ELSE IF (&tp0>=0y0||&tp0oC==0y0)&&&tp0oC!=&oCmask&&&tp0!=&maskx
        (
          &txt="Condition Level&level line &i condition not allowed in last Level with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
      IF &hacmod==2.&&&level==1.&&&actx=="Goto Level2"
      (
        &txt=&actx+" not allowed in condition c2! (Level&level line &i)"
        PRINT %ERROR "&txt"
        &ret=1.
      )
    )
    ELSE IF &actx!=""&&&actx!="Sample"&&&actx!="Mark C"
    (
      IF &tp0<0y0&&(&tp0oC==0y0||&tp0oC==&oCmask)
        &tp0=0y0
      ELSE IF &tp0>0y0&&&actx!="Goto Level0"&&&actx!="Stop Analyzer"&&&actx!="Stop CPU&Analyzer"
      (
        &txt="Condition Level&level line &i condition variant not allowed with HAC!"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      IF  &actx=="Inc COUNT0"
        &markc=&markc|0y01000000
      ELSE IF &actx=="Inc COUNT1"
        &markc=&markc|0y00100000
      &rmask3=0y0
      &rmask4=0y0
    )
    IF &ret==0.&&&actx!=""&&(&actx=="Goto Level0"||&actx=="Stop Analyzer"||&actx=="Stop CPU&Analyzer")
    (
      IF &tp0>=0y0&&&tp0!=&maskx
      (
        &txt="Condition Level&level line &i condition variant not allowed with HAC!"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      ELSE IF &tp0<0y0
        &tp0=&maskx

      IF &rmask3==0y0&&&rmask4==0y0
      (
        &txt="Goto Level0, Stop Analyzer or Stop CPU&Analyzer need to have Count0/1 condition in last level! (Level&level line &i)"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      IF &ret==0.&&&actx=="Goto Level0"&&&tp0==&maskx&&&gtpx!=0y0
      (
        &txt="Only one of Goto Level0, Stop Analyzer or Stop CPU&Analyzer allowed in last level! (Level&level line &i)"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      ELSE IF &ret==0.&&&actx=="Goto Level0"&&&tp0==&maskx
        &gtpx=&gtpx|0y10000000
      IF &ret==0.&&&actx=="Stop Analyzer"&&&tp0==&maskx&&&gtpx!=0y0
      (
        &txt="Only one of Goto Level0, Stop Analyzer or Stop CPU&Analyzer allowed in last level! (Level&level line &i)"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      ELSE IF &ret==0.&&&actx=="Stop Analyzer"&&&tp0==&maskx
        &gtpx=&gtpx|0y00100000
      IF &ret==0.&&&actx=="Stop CPU&Analyzer"&&&tp0==&maskx&&&gtpx!=0y0
      (
        &txt="Only one of Goto Level0, Stop Analyzer or Stop CPU&Analyzer allowed in last level! (Level&level line &i)"
        PRINT %ERROR "&txt"
        &ret=1.
      )
      ELSE IF &ret==0.&&&actx=="Stop CPU&Analyzer"&&&tp0==&maskx
        &gtpx=&gtpx|0y00001000
    )
  )

  IF &ret==0.
  (
    &rmask4=0y0
    &rmask4=&markc&0y01100000
    IF &rmask4==0y0&&&tp0>=0y0
    (
      &txt="No counter used/set in last level &level!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    ELSE IF &tp0!=&tp0oC&&(&rmask4!=0y01000000||&rmask4!=0y00100000)
    (
      &rmask3=&tp0^&tp0oC
      IF &rmask3==0y00000010&&&rmask4!=0y01000000
        &txt="COUNT0 (DELAY) used but never set in level &level with HAC!"
      ELSE IF &rmask3==0y00000001&&&rmask4!=0y00100000
        &txt="COUNT1 (DELAY) used but never set in level &level with HAC!"
      ELSE
        &txt=""
      IF "&txt"!=""
      (
        PRINT %ERROR "&txt"
        &ret=1.
      )
    )
    ELSE IF &rmask4==0y01100000
    (
      &txt="Only one counter could be used in lase level &level!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
    IF &ret==0.
    (
      &rmask2=&cmask&0y10000000
      IF &rmask2!=0y0
      (
        &rmask2=&tp0&0y00000010
        IF &rmask2==0y0
        (
          &txt="COUNT0 set but never used in level &level with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
    )
    IF &ret==0.
    (
      &rmask2=&cmask&0y01000000
      IF &rmask2!=0y0
      (
        &rmask2=&tp0&0y00000001
        IF &rmask2==0y0
        (
          &txt="COUNT1 set but never used in level &level with HAC!"
          PRINT %ERROR "&txt"
          &ret=1.
        )
      )
    )
  )

  &rmask4=0y0
  &rmask4=&gtpx&0y11000000
  IF &ret==0.&&&rmask4!=0y0&&&rmask4!=0y10000000
  (
    &txt="Goto LevelX must be used with correct condition with HAC!"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF &ret==0.&&&rmask4==0y10000000
  (
    &rmask4=&gtpx&0y01111111
    IF &rmask4!=0y0
    (
      &txt="Only one of Goto LevelX, Stop Analyzer or Stop CPU&Analyzer could be used per Level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )

  &rmask3=0y0
  &rmask3=&gtpx&0y00110000
  IF &ret==0.&&&rmask3!=0y0&&&rmask4!=0y0
  (
    &txt="Only one of Goto LevelX, Stop Analyzer or Stop CPU&Analyzer could be used per Level with HAC!"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF &ret==0.&&&rmask3!=0y0&&&rmask3!=0y00100000
  (
    &txt="Stop Analyzer must be used with correct condition with HAC!"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF &ret==0.&&&rmask4==0y00100000
  (
    &rmask4=&gtpx&0y11011111
    IF &rmask4!=0y0
    (
      &txt="Only one of Goto LevelX, Stop Analyzer or Stop CPU&Analyzer could be used per Level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )

  &rmask3=0y0
  &rmask3=&gtpx&0y00001100
  IF &ret==0.&&&rmask3!=0y0&&&rmask3!=0y00001000
  (
    &txt="Stop CPU&Analyzer must be used with correct condition with HAC!"
    PRINT %ERROR "&txt"
    &ret=1.
  )
  IF &ret==0.&&&rmask3==0y00001000
  (
    &rmask4=&gtpx&0y11110111
    IF &rmask4!=0y0
    (
      &txt="Only one of Goto LevelX, Stop Analyzer or Stop CPU&Analyzer could be used per Level with HAC!"
      PRINT %ERROR "&txt"
      &ret=1.
    )
  )
  RETURN &markc &ret
; --------------------------------------------------------------------------------
;                Programm schreiben und Analyzer programmieren
; --------------------------------------------------------------------------------
SetAnaProgram:
  LOCAL &addr &data &count &zeilen &nocomment &file &ret &level &act &radi &noco
  ENTRY &nocomment
  ; &nocomment=0. -> Programm mit Kommentar zum Programmieren schreiben
  ; &nocomment=1. -> Programm mit Kommentar speichern
  ; &nocomment=2. -> Programm mit Kommentar zum Programmieren schreiben in Temp file <tmp>\ana.ts
  ; &nocomment=3. -> Programm ohne Kommentar zum Anschauen schreiben
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Cannot program. Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Cannot program. Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Cannot program. Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
    RETURN
  )
  IF run()&&system.access.denied()
  (
    IF ice()
    (
      IF !MAP.CONFIG.FDPRAM()
      (
        PRINT %ERROR "Program is running! Please stop before programming!"
        RETURN
      )
    )
    ELSE
    (
      PRINT %ERROR "Program is running! Please stop before programming!"
      RETURN
    )
  )
  GOSUB GetTrace
  &file=dialog.string(IFILE)
  IF (&nocomment==2.||&nocomment==0.)
  (
    GOSUB BreakDel166
    ENTRY &ret
    IF &ret==0.
      RETURN
  )
  IF &nocomment<2.
  (
    while "&file"==""
    (
      &file="&adir"
      DIALOG.SETfilew IFILE "&file"
      &file=dialog.string(IFILE)
      IF "&file"==""
      (
        PRINT %ERROR "No file choosen!"
        RETURN
      )
    )
    GOSUB SetDir &file
    &noco=0.
  )
  ELSE
  (
    &noco=1.
    IF "&file"==""
    (
      &file=os.ptd()
      &file="&file"+"/ana.ts"
    )
    ELSE
    (
      LOCAL &p &x &y &tfile
      &y=string.len("&file")-1.
      &x=&y+1.
      &p=string.mid("&file",&y,1.)
      while "&p"!="/"&&"&p"!="\"
      (
        &y=&y-1.
        &p=string.mid("&file",&y,1.)
      )
      &tfile=string.mid("&file",&y+1.,&x-&y)
      &file=os.ptd()
      &file="&file"+"/"+"&tfile"
    )
  )
  IF &hac==1.
  (
    GOSUB CheckHACModel
    ENTRY &hacmod
    GOSUB CheckHACRules
    ENTRY &hacmod
  )
  ELSE
    &hacmod=0.
  IF &hacmod>=0.
  (
    OPEN #1 "&file" /CREATE
    &data=0y0
    &count=0y0
    &zeilen=0y0
    &addr=0y0
    &a1=""
    &a2=""
    &a3=""
    &b1=""
    &b2=""
    &b3=""
    &c1=""
    &c2=""
    &c3=""
    IF &nocomment<3.
    (
      &radi=radix()
      &msg=";"+"&radi"+" written with Analyzer Programing Dialog Version 1.7.0: 20.06.2001"
      WRITE #1 "&msg"
    )
    GOSUB WriteADDR &noco
    ENTRY &addr
    IF &addr>=0.
    (
      &addr=&addr*0y100
      GOSUB WriteDATA &noco
      ENTRY &data
      IF &data>=0.
        &addr=&addr+&data
      &addr=&addr*0y100
      GOSUB WriteCOUNT &noco
      ENTRY &count
      IF &count>=0.
        &addr=&addr+&count
      GOSUB WriteStates &addr &noco
      ENTRY &zeilen &level &act
    )
    CLOSE #1
    IF &nocomment==0.||&nocomment==2.
    (
      IF &addr>=0.&&&data>=0.&&&count>=0.&&&zeilen>0.
      (
        ;on error GOSUB
        ;  RETURN
        a.rp "&file"
        PRINT "Analyzer programed sucessfully!"
      )
      ELSE
      (
        LOCAL &msg
        &msg="Could not program analyzer! Stop at Level"+"&level"+" Line "+"&act"
        ;PRINT %ERROR "&msg"
      )
    )
    ELSE IF &nocomment==3.
    (
      IF &addr>=0.&&&data>=0.&&&count>=0.&&&zeilen>0.
      (
        edit.quit "&file"
        edit "&file"
      )
      ELSE
        PRINT %ERROR "Program not correct! Could not edit!"
    )
    ELSE IF &nocomment==1.
      PRINT "Program saved!"

  )
RETURN

WriteADDR:
  LOCAL &sa1 &sa2 &sa3 &sa4 &x &addx &addrc &res &noco &add
  ENTRY &noco
  &sa4=""
  &x=0.
  &res=0.
  while &x<3.
  (
    IF &x==0.
    (
      GOSUB GetXRange "A"
      ENTRY &sa1 &sa2 &sa3
    )
    ELSE IF &x==1.
    (
      IF "&addx"!=""&&&res>=0.
      (
        IF &noco==0.
        (
          IF &bamap==1.
            do ~~/demo/analyzer/trigger/init_ba_map
          GOSUB WriteADDRCom "A" &sa1 &sa2 &sa3
        )
        IF &trace==1.
        (
          GOSUB WriteADDRLine166 "A" &sa1 &sa2 &sa3
          ENTRY &sa1 &sa2 &sa3
          IF "&sa1"=="0."
          (
            &res=-1.
            RETURN &res
          )
        )
        IF &trace==3.
        (
          GOSUB WriteADDRLine166Fire "A" &sa1 &sa2 &sa3
          ENTRY &sa1 &sa2 &sa3
          IF "&sa1"=="0."
          (
            &res=-1.
            RETURN &res
          )
        )
        GOSUB WriteADDRLine "A" &sa1 &sa2 &sa3
        &res=0y100
      )
      GOSUB GetXRange "B"
      ENTRY &sa1 &sa2 &sa3
    )
    ELSE IF &x==2.
    (
      IF "&addx"!=""&&&res>=0.
      (
        IF &noco==0.
        (
          GOSUB WriteADDRCom "B" &sa1 &sa2 &sa3
        )
        IF &trace==1.
        (
          GOSUB WriteADDRLine166 "B" &sa1 &sa2 &sa3
          ENTRY &sa1 &sa2 &sa3
          IF "&sa1"=="0."
          (
            &res=-1.
            RETURN &res
          )
        )
        IF &trace==3.
        (
          GOSUB WriteADDRLine166Fire "B" &sa1 &sa2 &sa3
          ENTRY &sa1 &sa2 &sa3
          IF "&sa1"=="0."
          (
            &res=-1.
            RETURN &res
          )
        )
        GOSUB WriteADDRLine "B" &sa1 &sa2 &sa3
        &res=&res+0y10
      )
      GOSUB GetXRange "C"
      ENTRY &sa1 &sa2 &sa3
    )

    &add=0.
    &addx=""
    on error GOSUB
      RETURN
    IF "&sa1"!=""
    (
      EVAL &sa1
      &addrc=eval.type()
      IF &addrc!=&DAddress&&&addrc!=&DARange
        &add=-1.
      &addx=1.
    )
    ELSE
      &add=0.
    IF "&sa2"!=""
    (
      EVAL &sa2
      &addrc=eval.type()
      IF &addrc!=&DAddress&&&addrc!=&DARange
        &add=-1.
      &addx=&addx+2.
    )
    ELSE
      &add=0.
    IF "&sa3"!=""
    (
      EVAL &sa3
      &addrc=eval.type()
      IF &addrc!=&DAddress&&&addrc!=&DARange
        &add=-1.
      &addx=&addx+4.
    )
    ELSE
      &add=0.

    IF &add<0.
    (
      &res=-1.
    )
    &x=&x+1.
  )
  IF "&addx"!=""&&&res>=0.
  (
    IF &noco==0.
    (
      GOSUB WriteADDRCom "C" &sa1 &sa2 &sa3
    )
    IF &trace==1.
    (
      GOSUB WriteADDRLine166 "C" &sa1 &sa2 &sa3
      ENTRY &sa1 &sa2 &sa3
      IF "&sa1"=="0."
      (
        &res=-1.
        RETURN &res
      )
    )
    IF &trace==3.
    (
      GOSUB WriteADDRLine166Fire "C" &sa1 &sa2 &sa3
      ENTRY &sa1 &sa2 &sa3
      IF "&sa1"=="0."
      (
        &res=-1.
        RETURN &res
      )
    )
    GOSUB WriteADDRLine "C" &sa1 &sa2 &sa3
    &res=&res+0y1
  )
  RETURN &res

GetXRange:
  LOCAL &r1 &r2 &r3 &a1 &a2 &a3 &x &t1
  ENTRY &x
  &r1="R"+&x+"1"
  &r2="R"+&x+"2"
  &r3="R"+&x+"3"
  &a1=dialog.string(&r1)
  &a2=dialog.string(&r2)
  &a3=dialog.string(&r3)
  RETURN &a1 &a2 &a3

WriteADDRCom:
  LOCAL &x &r1 &r2 &r3
  ENTRY &x &r1 &r2 &r3

  &addrc=";#"+&x+"B,"+"&r1"+","+"&r2"+","+"&r3"
  WRITE #1 "&addrc"
  RETURN

WriteADDRLine:
  LOCAL &x &r1 &r2 &r3 &aaddr
  ENTRY &x &r1 &r2 &r3
  IF "&r1"!=""
  (
    &aaddr="ADDR "+&x+"B "+"&r1"
    WRITE #1 "&aaddr"
    IF &bamap==1.
      do ~~/demo/analyzer/trigger/set_ba_map &r1
  )
  IF "&r2"!=""
  (
    &aaddr="ADDR "+&x+"B "+"&r2"
    WRITE #1 "&aaddr"
    IF &bamap==1.
      do ~~/demo/analyzer/trigger/set_ba_map &r2
  )
  IF "&r3"!=""
  (
    &aaddr="ADDR "+&x+"B "+"&r3"
    WRITE #1 "&aaddr"
    IF &bamap==1.
      do ~~/demo/analyzer/trigger/set_ba_map &r3
  )
  RETURN

WriteADDRLine166:
  LOCAL &x &r1 &r2 &r3 &oax &oay &ret &aaddr
  ENTRY &x &r1 &r2 &r3
  GOSUB CheckARange166 &x &r1 &r2 &r3
  ENTRY &ret &oax &oay
  IF &ret==-1.
    &r1=0.
  ELSE
  (
    ; Achtung! In Zukunft kann auch ADDR OAR &r1||&r2||&r3
    ; bzw. ADDR OAR &r1 ADDR OAR &r2 ADDR OAR geschrieben werden
    ; -> Auskunft Michael
    ; Hier wird ADDR OAR &r1 ADDR OARX &r2 geschreiben und
    ; wenn 3. Eintrag belegt Fehler ausgegeben
    IF "&r1"!=""&&"&oax"!=""
    (
      &aaddr="ADDR "+"&oax"+" "+"&r1"
      WRITE #1 "&aaddr"
      IF "&oay"!=""
      (
        &aaddr="ADDR "+"&oay"+" "+"&r1"
        WRITE #1 "&aaddr"
      )
      IF &bamap==1.
        do ~~/demo/analyzer/trigger/set_ba_map &r1
      &r1=""
    )
    IF "&r2"!=""&&"&oax"!=""
    (
      IF ("&oax"=="OAR"||"&oax"=="OARX")&&&oar<2.
      (
        IF &x=="A"
          &ab="&oax"+"||"+"OARX"
        ELSE IF &x=="B"
          &bb="&oax"+"||"+"OARX"
        ELSE IF &x=="C"
          &cb="&oax"+"||"+"OARX"
        &oax="OARX"
        &oar=&oar+1.
      )
      ELSE IF ("&oax"=="OAR"||"&oax"=="OARX")&&&oar>1.
      (
        &TEXT="Maximum OARs reached at "+&x+"-Range ("+"&r2"+")!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
      )
      ELSE IF ("&oax"=="OAW"||"&oax"=="OAWX")&&&oaw<2.
      (
        IF &x=="A"
          &ab="&oax"+"||"+"OAWX"
        ELSE IF &x=="B"
          &bb="&oax"+"||"+"OAWX"
        ELSE IF &x=="C"
          &cb="&oax"+"||"+"OAWX"
        &oax="OAWX"
        &oaw=&oaw+1.
      )
      ELSE IF ("&oax"=="OAW"||"&oax"=="OAWX")&&&oaw>1.
      (
        &TEXT="Maximum OAWs reached at "+&x+"-Range ("+"&r2"+")!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
      )
      IF &ret>=0.
      (
        &aaddr="ADDR "+"&oax"+" "+"&r2"
        WRITE #1 "&aaddr"
        IF "&oay"!=""
        (
          &aaddr="ADDR "+"&oay"+" "+"&r2"
          WRITE #1 "&aaddr"
        )
        IF &bamap==1.
          do ~~/demo/analyzer/trigger/set_ba_map &r2
        &r2=""
      )
    )
    IF "&r3"!=""&&"&oax"!=""
    (
      IF ("&oax"=="OAR"||"&oax"=="OARX")&&&oar<2.
      (
        IF &x=="A"
          &ab="&oax"+"||"+"OARX"
        ELSE IF &x=="B"
          &bb="&oax"+"||"+"OARX"
        ELSE IF &x=="C"
          &cb="&oax"+"||"+"OARX"
        &oax="OARX"
        &oar=&oar+1.
      )
      ELSE IF ("&oax"=="OAR"||"&oax"=="OARX")&&&oar>1.
      (
        &TEXT="Maximum OARs reached at "+&x+"-Range ("+"&r3"+")!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
      )
      ELSE IF ("&oax"=="OAW"||"&oax"=="OAWX")&&&oaw<2.
      (
        IF &x=="A"
          &ab="&oax"+"||"+"OAWX"
        ELSE IF &x=="B"
          &bb="&oax"+"||"+"OAWX"
        ELSE IF &x=="C"
          &cb="&oax"+"||"+"OAWX"
        &oax="OAWX"
        &oaw=&oaw+1.
      )
      ELSE IF ("&oax"=="OAW"||"&oax"=="OAWX")&&&oaw>1.
      (
        &TEXT="Maximum OAWs reached at "+&x+"-Range ("+"&r3"+")!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
      )
      IF &ret>=0.
      (
        &aaddr="ADDR "+"&oax"+" "+"&r3"
        WRITE #1 "&aaddr"
        IF "&oay"!=""
        (
          &aaddr="ADDR "+"&oay"+" "+"&r3"
          WRITE #1 "&aaddr"
        )
        IF &bamap==1.
          do ~~/demo/analyzer/trigger/set_ba_map &r3
        &r3=""
      )
    )
  )
  IF &ret==-1.
    &r1=0.
  RETURN &r1 &r2 &r3


WriteADDRLine166Fire:
  LOCAL &x &r1 &r2 &r3 &aaddr &baccess &bdata
  ENTRY &x &r1 &r2 &r3
  GOSUB CheckARange166Fire &x &r1 &r2 &r3
  ENTRY &ret &baccess %line &bdata
  IF &ret==-1.
  (
    &r1=0.
  )
  ELSE
  (
  IF "&r1"!=""
  (
    &aaddr="ADDR "+&x+"B "+"&r1"+" &baccess"+" &bdata"
    WRITE #1 "&aaddr"
    IF &bamap==1.
      do ~~/demo/analyzer/trigger/set_ba_map &r1
    &r1=""
  )
  IF "&r2"!=""
  (
    &aaddr="ADDR "+&x+"B "+"&r2"+" &baccess"+" &bdata"
    WRITE #1 "&aaddr"
    IF &bamap==1.
      do ~~/demo/analyzer/trigger/set_ba_map &r2
    &r2=""
  )
  IF "&r3"!=""
  (
    &aaddr="ADDR "+&x+"B "+"&r3"+" &baccess"+" &bdata"
    WRITE #1 "&aaddr"
    IF &bamap==1.
      do ~~/demo/analyzer/trigger/set_ba_map &r3
    &r3=""
  )
  )
  RETURN &r1 &r2 &r3


CheckARange166:  ; &x = "A" | "B" | "C"  &r1 &r2 &3 Addresses or Ranges
  LOCAL &x &r1 &r2 &r3 &oax &oay &type &access &TEXT
  ENTRY &x &r1 &r2 &r3

  &type=0x0 ; 0x1 = data 0x2 = address
  &ret=0.
  &oax=""
  &oay=""
  IF "&r1"!=""
 (
     LOCAL &r1x
     EVAL &r1
     &ret=eval.type()
     IF &ret==&DARange
     (
       GOSUB GetRangeBeginEnd &r1
       ENTRY &r1x
     )
     ELSE
      &r1x="&r1"
     &ret=0.
     IF address.data(&r1x)
       &type=0x1
     ELSE
       &type=0x2
  )
  IF "&r2"!=""
  (
     LOCAL &r2x
     EVAL &r2
     &ret=eval.type()
     IF &ret==&DARange
     (
       GOSUB GetRangeBeginEnd &r2
       ENTRY &r2x
     )
     ELSE
      &r2x="&r2"
     &ret=0.
     IF address.data(&r2x)&&(&type==0x1||&type==0x0)
       &type=0x1
     ELSE IF !address.data(&r2x)&&(&type==0x2||&type==0x0)
       &type=0x2
     ELSE
     (
        &TEXT=&x+"-Range entry "+"&r2"+" of different type than other entries!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
     )
  )
  IF "&r3"!=""&&&ret!=-1.
  (
     LOCAL &r3x
     EVAL &r3
     &ret=eval.type()
     IF &ret==&DARange
     (
       GOSUB GetRangeBeginEnd &r3
       ENTRY &r3x
     )
     ELSE
      &r3x="&r3"
     &ret=0.
     IF address.data(&r3)&&(&type==0x1||&type==0x0)
       &type=0x1
     ELSE IF !address.data(&r3)&&(&type==0x2||&type==0x0)
       &type=0x2
     ELSE
     (
        &TEXT=&x+"-Range entry "+"&r3"+" of different type than other entries!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
     )
  )
  IF &ret==0.
  (
    GOSUB CheckUsageAccess &x &type
    ENTRY &access ; RETURN -1. = error 0x0 = no access defined 0x1 = read 0x2 = write 0x3 = (read||write)

    IF "&access"=="-1."
      &ret=-1.
    ELSE IF &type==0x1
    (
       IF &access==0x0
       (
          &TEXT="No access type defined for data address at "+&x+"-Range!"
          PRINT %ERROR "&TEXT"
          &ret=-1.
       )
       ELSE IF &access==0x1
       (
         IF &oar==0.
           &oax="OAR"
         ELSE IF &oar==1.
           &oax="OARX"
         ELSE
         (
          &TEXT="Maximum OARs reached at "+&x+"-Range!"
          PRINT %ERROR "&TEXT"
          &ret=-1.
         )
         &oar=&oar+1.
       )
       ELSE IF &access==0x2
       (
         IF &oaw==0.
           &oax="OAW"
         ELSE IF &oaw==1.
           &oax="OAWX"
         ELSE
         (
          &TEXT="Maximum OAWs reached at "+&x+"-Range!"
          PRINT %ERROR "&TEXT"
          &ret=-1.
         )
         &oaw=&oaw+1.
       )
       ELSE IF &access==0x3
       (
         IF &oar==0.
           &oax="OAR"
         ELSE IF &oar==1.
           &oax="OARX"
         ELSE
         (
          &TEXT="Maximum OARs reached at "+&x+"-Range!"
          PRINT %ERROR "&TEXT"
          &ret=-1.
         )
         &oar=&oar+1.
         IF &oaw==0.
           &oay="OAW"
         ELSE IF &oaw==1.
           &oay="OAWX"
         ELSE
         (
          &TEXT="Maximum OAWs reached at "+&x+"-Range!"
          PRINT %ERROR "&TEXT"
          &ret=-1.
         )
         &oaw=&oaw+1.
       )
       IF &x=="A"&&"&oay"==""
         &ab="&oax"
       IF &x=="A"&&"&oay"!=""
         &ab="&oax"+"||"+"&oay"
       IF &x=="B"
         &bb="&oax"
       IF &x=="B"&&"&oay"!=""
         &bb="&oax"+"||"+"&oay"
       IF &x=="C"
         &cb="&oax"
       IF &x=="C"&&"&oay"!=""
         &cb="&oax"+"||"+"&oay"
    ) ; IF &type==0x1
    ELSE IF &type==0x2&&&x!="C"
    (
       &oay=""
       IF &access==0x0
         &oax=&x+"BA"
       ELSE IF &access==0x1
         &oax=&x+"BR"
       ELSE IF &access==0x2
         &oax=&x+"BW"
       ELSE IF &access==0x3
         &oax=&x+"BD"
       IF &x=="A"
       (
         &ab="&oax"
         &oax="AB"
       )
       IF &x=="B"
       (
         &bb="&oax"
         &oax="BB"
       )
       IF &x=="C"
       (
         &cb="&oax"
         &oax="CB"
       )
    )
    ELSE IF &type==0x2&&&x=="C"
    (
      &TEXT="Program address breakpoints are only allowed with A- or B-Range!"
      PRINT %ERROR "&TEXT"
      &ret=-1.
    )

  ) ; IF &ret==0.


  RETURN &ret &oax &oay


CheckARange166Fire:  ; &x = "A" | "B" | "C"  &r1 &r2 &3 Addresses or Ranges
  LOCAL &x &r1 &r2 &r3 &baccess &bdata &type &access &TEXT &sa1 &sa2 &bdata0 &bdata0w &bdata1 &bdata1w
  ENTRY &x &r1 &r2 &r3

  &type=0x0 ; 0x1 = data 0x2 = address
  &ret=0.
  &baccess=""
  &bdata=""
  &bdata0=""
  &bdata1=""

  &sa1=dialog.string(RD01)
  &bdata0w=dialog.string(RD02)
  IF "&sa1"!=""
  (
    GOSUB CheckData &sa1 &bdata0w
    ENTRY &bdata0
  )

  &sa1=dialog.string(RD11)
  &bdata1w=dialog.string(RD12)
  IF "&sa1"!=""
  (
    GOSUB CheckData &sa1 &bdata1w
    ENTRY &bdata1
  )

  IF "&r1"!=""
  (
     LOCAL &r1x
     EVAL &r1
     &ret=eval.type()
     IF &ret==&DARange
     (
       GOSUB GetRangeBeginEnd &r1
       ENTRY &r1x
     )
     ELSE
      &r1x="&r1"
     &ret=0.
     IF address.data(&r1x)
       &type=0x1
     ELSE
       &type=0x2
  )
  IF "&r2"!=""
  (
     LOCAL &r2x
     EVAL &r2
     &ret=eval.type()
     IF &ret==&DARange
     (
       GOSUB GetRangeBeginEnd &r2
       ENTRY &r2x
     )
     ELSE
      &r2x="&r2"
     &ret=0.
     IF address.data(&r2x)&&(&type==0x1||&type==0x0)
       &type=0x1
     ELSE IF !address.data(&r2x)&&(&type==0x2||&type==0x0)
       &type=0x2
     ELSE
     (
        &TEXT=&x+"-Range entry "+"&r2"+" of different type than other entries!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
     )
  )
  IF "&r3"!=""&&&ret!=-1.
  (
     LOCAL &r3x
     EVAL &r3
     &ret=eval.type()
     IF &ret==&DARange
     (
       GOSUB GetRangeBeginEnd &r3
       ENTRY &r3x
     )
     ELSE
      &r3x="&r3"
     &ret=0.
     IF address.data(&r3)&&(&type==0x1||&type==0x0)
       &type=0x1
     ELSE IF !address.data(&r3)&&(&type==0x2||&type==0x0)
       &type=0x2
     ELSE
     (
        &TEXT=&x+"-Range entry "+"&r3"+" of different type than other entries!"
        PRINT %ERROR "&TEXT"
        &ret=-1.
     )
  )

  IF &ret==0.
  (
    GOSUB CheckUsageAccess &x &type
    ENTRY &access ; RETURN -1. = error 0x0 = no access defined 0x1 = read 0x2 = write 0x3 = (read||write)

    IF "&access"=="-1."
      &ret=-1.
    ELSE IF &type==0x1
    (
       IF &access==0x0
       (
	 &baccess=""
       )
       ELSE IF &access==0x1
       (
	 &baccess="/Read"
       )
       ELSE IF &access==0x2
       (
	 &baccess="/Write"
       )
       ELSE IF &access==0x3
       (
	 &baccess="/ReadWrite"
       )
       IF &x=="A"
       (
         &ab="AB"
       )
       IF &x=="B"
       (
         &bb="BB"
       )
       IF &x=="C"
       (
         &cb="CB"
       )
    ) ; IF &type==0x1
    ELSE IF &type==0x2
    (
       &baccess="/Program"
       IF &x=="A"
       (
         &ab="AB"
       )
       IF &x=="B"
       (
         &bb="BB"
       )
       IF &x=="C"
       (
         &cb="CB"
       )
    )

    IF &ret==0.
    (
      LOCAL &dat
      GOSUB CheckUsageData &x
      ENTRY &dat
      IF "&dat"==""
      (
      )
      ELSE IF &dat==-1.
      (
	&ret=-1.
      )
      ELSE
      (
        IF &dat==0.
	  &bdata="/Data."+"&bdata0w"+" "+"&bdata0"
	ELSE IF &dat==1.
	  &bdata="/Data."+"&bdata1w"+" "+"&bdata1"
	ELSE IF &dat==2.
	  &bdata="/Data."+"&bdata0w"+" !"+"&bdata0"
	ELSE IF &dat==3.
	  &bdata="/Data."+"&bdata1w"+" !"+"&bdata1"
	ELSE
	  &bdata=""
      )
    )


  ) ; IF &ret==0.

  RETURN &ret &baccess &bdata


GetRangeBeginEnd:
  LOCAL &range &rbeg &rend &found &char
  ENTRY &range
  &found=string.scan("&range","v.range(",0.)
  IF &found>=0.
  (
    &char=string.mid("&range",8.,1.)
    IF "&char"==""""
      &rbeg=string.mid("&range",9.,string.len("&range")-11.)
    ELSE
      &rbeg=string.mid("&range",8.,string.len("&range")-9.)
    &rend="v.end("+"&rbeg"+")"
  )
  &found=string.scan("&range","--",0.)
  IF &found>=0.
  (
    &rbeg=string.mid("&range",0.,&found)
    &found=&found+2.
    &rend="&rbeg"
  )
  &found=string.scan("&range","++",0.)
  IF &found>=0.
  (
    &rbeg=string.mid("&range",0.,&found)
    &found=&found+2.
    &rend=string.mid("&range",&found,string.len("&range")-&found)
    &rend="&rbeg"+"+"+"&rend"
  )
  RETURN &rend


CheckUsageAccess:
  LOCAL &x &range &xa &xende &y &sa1 &sa2 &sa3 &sa4 &sa5 &type &access &TEXT
  ENTRY &x &type ; &x = "A"|"B" &type = 0x1 data 0x2 programm

  &range=&x+"B"
  &xa=&x
  &access=""
  &y=0.
  while &y<3.&&"&access"!="-1."
  (
    &x=1.
    IF &y==0.
      &xende=5.
    ELSE
      &xende=4.
    while &x<&xende&&"&access"!="-1."
    (
      IF &x==1.
      (
        GOSUB GetXLineY &y &x
        ENTRY &sa1 &sa2 &sa3 &sa4 &sa5
      )
      ELSE
      (
        GOSUB GetXLineY &y &x
        ENTRY &sa1 &sa2 &sa3 &sa4 &sa5
      )

      IF string.scan("&sa2","&range",0)>=0 ; kann auch AB&&BB ect. sein
      (
        LOCAL &saccess
        IF "&sa3"=="READ"
          &saccess=0x1
        ELSE IF "&sa3"=="WRITE"
          &saccess=0x2
        ELSE IF "&sa3"=="(READ||WRITE)"
          &saccess=0x3
        ELSE
          &saccess=" "

        IF "&access"==""
        (
          IF "&sa3"=="READ"
            &access=0x1
          ELSE IF "&sa3"=="WRITE"
            &access=0x2
          ELSE IF "&sa3"=="(READ||WRITE)"
            &access=0x3
          ELSE
            &access=" "
        )
        ELSE IF "&access"!=""&&"&saccess"!="&access"
        (
          &access=-1.
          &TEXT="&xa"+"-Range cannot be used with different access types (RD/WR). (Level "+"&y"+" Line "+"&x"+")"
          PRINT %ERROR "&TEXT"
        )
      )
      &x=&x+1.
    )
    &y=&y+1.
  )
  IF &type!=0x2&&("&access"==" "||"&access"=="")
  (
    &access=-1.
    &TEXT="&xa"+"-Range cannot be used without access type (RD/WR) in condition."
    PRINT %ERROR "&TEXT"
  )
  ELSE IF &type==0x2&&("&access"==" "||"&access"=="")
    &access=0x0

  RETURN &access ; RETURN -1. = error 0x0 = no access defined 0x1 = read 0x2 = write 0x3 = (read||write)


CheckUsageData:
  LOCAL &x &xa &xende &y &sa1 &sa2 &sa3 &sa4 &sa5 &type &data &sdata &TEXT &range
  ENTRY &x

  &range=&x+"B"
  &xa=&x
  &sdata=""
  &y=0.
  while &y<3.&&"&sdata"!="-1."
  (
    &x=1.
    IF &y==0.
      &xende=5.
    ELSE
      &xende=4.
    while &x<&xende&&"&sdata"!="-1."
    (
      IF &x==1.
      (
        GOSUB GetXLineY &y &x
        ENTRY &sa1 &sa2 &sa3 &sa4 &sa5
      )
      ELSE
      (
        GOSUB GetXLineY &y &x
        ENTRY &sa1 &sa2 &sa3 &sa4 &sa5
      )

      IF string.scan("&sa2","&range",0)>=0
      (
      IF ("&sa2"=="DATA0"||"&sa3"=="DATA0"||"&sa4"=="DATA0")
	&data="0."
      ELSE IF ("&sa2"=="!DATA0"||"&sa3"=="!DATA0"||"&sa4"=="!DATA0")
	&data="2."
      ELSE IF ("&sa2"=="DATA1"||"&sa3"=="DATA1"||"&sa4"=="DATA1")
	&data="1."
      ELSE IF ("&sa2"=="!DATA1"||"&sa3"=="!DATA1"||"&sa4"=="!DATA1")
	&data="3."
      ELSE
	&data=" "

      IF "&data"!=" "
      (
        IF "&sdata"==""
  	  &sdata=&data

        IF "&data"!=" "&&"&sdata"!="&data"
        (
          &sdata=-1.
          &TEXT="&xa"+"-Range cannot be used with different data values. (Level "+"&y"+" Line "+"&x"+")"
          PRINT %ERROR "&TEXT"
        )
      )
      )
      &x=&x+1.
    )
    &y=&y+1.
  )

  RETURN &sdata ; RETURN -1. = error


CollectAnd:
  LOCAL &sand &sa1 &sa2 &sa3 &sa4 &sax1 &sax2 &sax3 &sax4 &addr &addrc
  ENTRY &sand &sa1 &sa2 &sa3 &sa4
  GOSUB SetCondition166 &sa1 &sa2 &sa3 &sa4
  ENTRY &sax1 &sax2 &sax3 &sax4
  &addr=""
  &addrc=""
  IF "&sax1"=="0."
  (
    &addr=0.
    RETURN &addr &addrc
  )

  IF "&sax1"!=""
  (
    &addrc="&sa1"
    &addr="&sax1"
    IF "&sa2"!=""
    (
      &addrc="&addrc"+","+"&sa2"
      IF "&sax2"!=""
        &addr="&addr"+&sand+"&sax2"
      IF "&sa3"!=""
      (
        &addrc="&addrc"+","+"&sa3"
        IF "&sax3"!=""
          &addr="&addr"+&sand+"&sax3"
        IF "&sa4"!=""
        (
          &addrc="&addrc"+","+"&sa4"
          IF "&sax4"!=""
          &addr="&addr"+&sand+"&sax4"
        )
        ELSE
          &addrc="&addrc"+","
      )
      ELSE IF "&sa4"!=""
      (
        &addrc="&addrc"+","
        &addrc="&addrc"+","+"&sa4"
        IF "&sax4"!=""
          &addr="&addr"+&sand+"&sax4"
      )
      ELSE
        &addrc="&addrc"+",,"
    )
    ELSE IF "&sa3"!=""
    (
      &addrc="&addrc"+",,"+"&sa3"
      IF "&sax3"!=""
        &addr="&addr"+&sand+"&sax3"
      IF "&sa4"!=""
      (
        &addrc="&addrc"+","+"&sa4"
        IF "&sax4"!=""
          &addr="&addr"+&sand+"&sax4"
      )
      ELSE
        &addrc="&addrc"+","
    )
    ELSE IF "&sa4"!=""
    (
      &addrc="&addrc"+",,,"+"&sa4"
      IF "&sax4"!=""
        &addr="&addr"+&sand+"&sax4"
    )
    ELSE
      &addrc="&addrc"+",,,"
  )
  ELSE IF "&sa2"!=""
  (
    &addrc=","+"&sa2"
    IF "&sax2"!=""
      &addr="&sax2"
    IF "&sa3"!=""
    (
      &addrc="&addrc"+","+"&sa3"
      IF "&sax3"!=""
        &addr="&addr"+&sand+"&sax3"
      IF "&sa4"!=""
      (
        &addrc="&addrc"+","+"&sa4"
        IF "&sax4"!=""
          &addr="&addr"+&sand+"&sax4"
      )
      ELSE
        &addrc="&addrc"+","
    )
    ELSE IF "&sax4"!=""
    (
      &addrc="&addrc"+",,"+"&sa4"
      IF "&sax4"!=""
        &addr="&addr"+&sand+"&sax4"
    )
    ELSE
      &addrc="&addrc"+",,"
  )
  ELSE IF "&sa3"!=""
  (
    &addrc=",,"+"&sa3"
    IF "&sax3"!=""
      &addr="&sax3"
    IF "&sax4"!=""
    (
      &addrc="&addrc"+","+"&sa4"
      IF "&sax4"!=""
        &addr="&addr"+&sand+"&sa4"
    )
    ELSE
      &addrc="&addrc"+","
  )
  ELSE IF "&sa4"!=""
  (
    &addrc=",,,"+"&sa4"
    IF "&sax4"!=""
      &addr="&sax4"
  )
  RETURN &addr &addrc

WriteDATA:
  LOCAL &sa1 &sa2 &datac &data &res &noco
  ENTRY &noco

  &res=0.
  &sa1=dialog.string(RD01)
  &sa2=dialog.string(RD02)
  IF "&sa1"!=""
  (
    GOSUB CheckData &sa1 &sa2
    ENTRY &sa1
    IF "&sa1"!=""
    (
      IF &noco==0.
      (
        &datac=";#D0,"+"&sa2"+","+"&sa1"
        WRITE #1 "&datac"
      )
      IF &trace==1.
      (
        GOSUB SetData166 0. &sa2 &sa1
      )
      ELSE IF &trace==3.
      (
        GOSUB SetData166Fire 0. &sa2 &sa1
      )
      ELSE
      (
        &data="DATA."+"&sa2"+" DATA0 "+"&sa1"
        WRITE #1 "&data"
      )
      &res=0y10
    )
    ELSE
      &res=-1.

  )
  &sa1=dialog.string(RD11)
  &sa2=dialog.string(RD12)
  IF "&sa1"!=""&&&res>=0.
  (
    GOSUB CheckData &sa1 &sa2
    ENTRY &sa1
    IF "&sa1"!=""
    (
      IF &noco==0.
      (
        &datac=";#D1,"+"&sa2"+","+"&sa1"
        WRITE #1 "&datac"
      )
      IF &trace==1.
      (
        GOSUB SetData166 1. &sa2 &sa1
      )
      ELSE IF &trace==3.
      (
        GOSUB SetData166Fire 1. &sa2 &sa1
      )
      ELSE
      (
        &data="DATA."+"&sa2"+" DATA1 "+"&sa1"
        WRITE #1 "&data"
      )
      &res=&res+0y1
    )
    ELSE
      &res=-1.
  )
  RETURN &res

WriteCOUNT:
  LOCAL &sa1 &sa2 &datac &data &ret &res &noco &cmax &s0a1 &delay &x &y &lmask &rmask &level
  ENTRY &noco

  &res=0.
  &delay=0.
  &level=-1.
  &sa1=dialog.string(EC0)
  &s0a1=dialog.string(EC1)
  &sa2=dialog.string(PC0)
  IF "&sa1"!=""
  (
    IF "&sa2"!=""
    (
      on error GOSUB
        RETURN
      EVAL &sa1
      &ret=eval.type()
      IF &ret!=&DInteger&&&ret!=&DIntNum&&&ret!=&DFloat&&&ret!=&DHex&&&ret!=&DNumeric
        &sa1=-1.

      &data="&sa1"+"&sa2"
      EVAL &data
      &ret=eval.type()
      IF &ret!=&DTime
      (
        &ret="&data"+" no valid time value!"
        PRINT %ERROR "&ret"
        &sa1=-1.
      )
      IF "&s0a1"!=""
        GOSUB GetMaxCountVal 1. &sa2
      ELSE
        GOSUB GetMaxCountVal 0. &sa2

      ENTRY &cmax
      IF &sa1>&cmax
      (
        &ret="&sa1"+" bigger than max value "+"&cmax"+" for "+"&sa2"+"!"
        PRINT %ERROR "&ret"
        &sa1=-1.
      )
    )
    ELSE
    (
      on error GOSUB
        RETURN
      EVAL &sa1
      &ret=eval.type()
      IF &ret!=&DInteger&&&ret!=&DIntNum&&&ret!=&DFloat&&&ret!=&DBinary&&&ret!=&DHex&&&ret!=&DNumeric
      (
        &ret="&sa1"+" no valid count value!"
        PRINT %ERROR "&ret"
        &sa1=-1.
      )
    )

    IF &sa1>-1.
    (
      IF &noco==0.
      (
        &datac=";#C0,"+"&sa1"+","+"&sa2"
        WRITE #1 "&datac"
      )
      IF &hac==1.
      (
        LOCAL &act
        &x=0.
        while &x<3.&&&level<0.
        (
          IF &x==0.
            &y=4.
          ELSE
            &y=3.
          while &y>0.&&&level<0.
          (
            GOSUB GetLineMask &x &y
            ENTRY &lmask &act
            &rmask=&lmask&0y00000010
            IF &rmask!=0y0||&act=="Inc COUNT0"
              &level=&x
            &y=&y-1.
          )
          &x=&x+1.
        )
        IF (&hacmod==1.&&&level==2.)||(&hacmod==2.&&&level==1.)||("&sa2"!="")
        (
          IF "&sa2"!=""
            &data="TIME DELAY "+"&sa1"+"&sa2"
          ELSE
            &data="EVENT DELAY "+"&sa1"
          &delay=1.
        )
      )
      IF "&sa2"!=""&&&delay==0.
        &data="TIME COUNT0 "+"&sa1"+"&sa2"
      ELSE IF &delay==0.
        &data="EVENT COUNT0 "+"&sa1"

      WRITE #1 "&data"
      &res=0y10
    )
    ELSE
      &res=-1.
  )
  IF &delay==0.
    &level=-1
  ELSE
    &delay=0.
  &sa1=dialog.string(EC1)
  &s0a1=dialog.string(EC0)
  &sa2=dialog.string(PC1)
  IF "&sa1"!=""&&&res>=0.
  (
    IF "&sa2"!=""
    (
      on error GOSUB
        RETURN
      EVAL &sa1
      &ret=eval.type()
      IF &ret!=&DInteger&&&ret!=&DIntNum&&&ret!=&DFloat&&&ret!=&DHex&&&ret!=&DNumeric
        &sa1=-1.

      &data="&sa1"+"&sa2"
      EVAL &data
      &ret=eval.type()
      IF &ret!=&DTime
      (
        &ret="&data"+" no valid time value!"
        PRINT %ERROR "&ret"
        &sa1=-1.
      )
      IF "&s0a1"!=""
        GOSUB GetMaxCountVal 1. &sa2
      ELSE
        GOSUB GetMaxCountVal 0. &sa2
      ENTRY &cmax
      IF &sa1>&cmax
      (
        &ret="&sa1"+" bigger than max value "+"&cmax"+" for "+"&sa2"+"!"
        PRINT %ERROR "&ret"
        &sa1=-1.
      )
    )
    ELSE
    (
      on error GOSUB
        RETURN
      EVAL &sa1
      &ret=eval.type()
      IF &ret!=&DInteger&&&ret!=&DIntNum&&&ret!=&DFloat&&&ret!=&DBinary&&&ret!=&DHex&&&ret!=&DNumeric
      (
        &ret="&sa1"+" no valid count value!"
        PRINT %ERROR "&ret"
        &sa1=-1.
      )
    )
    IF &sa1>-1.
    (
      IF &noco==0.
      (
        &datac=";#C1,"+"&sa1"+","+"&sa2"
        WRITE #1 "&datac"
      )
      IF &hac==1.&&&level<0.
      (
        &x=0.
        &level=-1.
        &delay=0.
        while &x<3.&&&level<0.
        (
          IF &x==0.
            &y=4.
          ELSE
            &y=3.
          while &y>0.&&&level<0.
          (
            GOSUB GetLineMask &x &y
            ENTRY &lmask &act
            &rmask=&lmask&0y00000001
            IF &rmask!=0y0||&act=="Inc COUNT1"
              &level=&x
            &y=&y-1.
          )
          &x=&x+1.
        )
        IF (&hacmod==1.&&&level==2.)||(&hacmod==2.&&&level==1.)||("&sa2"!="")
        (
          IF "&sa2"!=""
            &data="TIME DELAY "+"&sa1"+"&sa2"
          ELSE
            &data="EVENT DELAY "+"&sa1"
          &delay=1.
        )
      )
      IF "&sa2"!=""&&&delay==0.
        &data="TIME COUNT1 "+"&sa1"+"&sa2"
      ELSE IF &delay==0.
        &data="EVENT COUNT1 "+"&sa1"
      WRITE #1 "&data"
      &res=&res+0y1
    )
    ELSE
      &res=-1.
  )
  RETURN &res

WriteStates:
  LOCAL &sa1 &sa2 &sa3 &sa4 &sa5 &x &y &addr &addrc &state &ad &z &add &co &cx &sta &noco &addx &xende
  ENTRY &ad &noco

  &z=0.
  &y=0.
  &add=&ad
  &cx=0.
  &sta=0y0
  &co=0y00
  while &y<3.
  (
    &addr=""
    &x=1.
    IF &y==0.
      &xende=5.
    ELSE
      &xende=4.
    while &x<&xende
    (
      IF &x==1.
      (
        GOSUB GetXLineY &y &x
        ENTRY &sa1 &sa2 &sa3 &sa4 &sa5
      )
      ELSE
      (
        IF "&addr"!=""
        (
          LOCAL &coloc &stateloc
          GOSUB WriteActLine &y &addr &sa1 &addrc &noco
          ENTRY &coloc &stateloc
          &co=&coloc|&co
          &sta=&stateloc|&sta
          &z=&z+1.
        )
        GOSUB GetXLineY &y &x
        ENTRY &sa1 &sa2 &sa3 &sa4 &sa5
      )
      IF "&sa1"!=""
      (
        GOSUB CheckBed &ad &add &sa1 &sa2 &sa3 &sa4 &sa5
        ENTRY &addx &add
        IF &addx!=""
        (
          GOSUB CollectAnd "&&" &sa2 &sa3 &sa4 &sa5
          ENTRY &addr &addrc
          IF "&addr"==""
          (
            &addr="TRUE"
            &addrc=",,,"
          )
          ELSE IF "&addr"=="0."
          (
            &z=-1.
            RETURN &z &y &x
          )
        )
      )
      ELSE
        &addr=""
      IF "&addr"!=""
      (
        LOCAL &cxloc &cmask0 &cmask1 &cmask2
        &cmask0=&cx&0y001
        &cmask1=&cx&0y010
        &cmask2=&cx&0y100
        IF (&y==0.&&&cmask0==0.)||(&y==1.&&&cmask1==0.)||(&y==2.&&&cmask2==0.)
        (
          LOCAL &state &t1
          WRITE #1 " "
          &t1=string.cut("&y",-1.)
          &state="LEVEL"+"&t1"+":"
          WRITE #1 "&state"
          IF &y==0.
            &cxloc=0y1
          ELSE IF &y==1.
            &cxloc=0y10
          ELSE IF &y==2.
            &cxloc=0y100
          &cx=&cxloc|&cx
        )
      )
      &x=&x+1.
    )
    IF "&addr"!=""
    (
      LOCAL &coloc &stateloc
      GOSUB WriteActLine &y &addr &sa1 &addrc &noco
      ENTRY &coloc &stateloc
      &co=&coloc|&co
      &sta=&stateloc|&sta
      &z=&z+1.
    )
    &y=&y+1.
  )
end:

  IF &sta!=&cx
  (
    LOCAL &mask1 &mask2 &maskl0 &maskl1 &txt
    &txt=""
    &maskl0=&cx&0y001
    &maskl1=&cx&0y010
    &mask1=&sta&0y010
    IF &mask1==0y0&&&maskl1!=0y0
      &txt="Level1 defined but not referenced!"
    ELSE IF &mask1!=0.&&&maskl1==0.
      &txt="Level1 referenced but not defined!"
    &mask1=&sta&0y100
    &mask2=&cx&0y100
    IF &mask1==0y0&&&mask2!=0y0&&(&mask1!=0y0||&maskl1!=0y0)
      &txt="Level2 defined but not referenced!"
    ELSE IF &mask1!=0.&&&mask2==0.
      &txt="Level2 referenced but not defined!"
    IF "&txt"!=""
    (
      IF &mask1!=0.
      (
        GOSUB ShowError "&txt"
        &z=0.
      )
      ELSE IF &hac==1.||&hac==0.
      (
        GOSUB ShowError "&txt"
        &z=-1.
      )
      IF &add==&ad
        &ad=&ad+0y1110000
    )
  )
  IF &z==0.&&&add==&ad
    GOSUB ShowWarn "No definition used!"
  ELSE IF &z>0.&&&add>0.
  (
    GOSUB ShowUnusedDefs &add
    ENTRY &xende
    IF &xende<0.
      &z=-1.
  )
  &add=&ad&0y0000010
  &cx=&co&0y00000001
  IF &z>0.&&(&add==0y0000010)&&(&cx!=0y01)
  (
    IF &hac==0.
      GOSUB ShowWarn "Count0 used but never incremented!"
    ELSE
    (
      GOSUB ShowError "Count0 used but never incremented!"
      &z=-1.
    )
  )
  &add=&ad&0y0000001
  &cx=&co&0y00000010
  IF &z>0.&&&add==0y00000001&&(&cx!=0y10)
  (
    IF &hac==0.
      GOSUB ShowWarn "Count1 used but never incremented!"
    ELSE
    (
      GOSUB ShowError "Count1 used but never incremented!"
      &z=-1.
    )
  )
  RETURN &z &y &x


GetXLineY:
  LOCAL &x &y &d1 &d2 &d3 &d4 &d5 &a1 &a2 &a3 &a4 &a5 &t1 &t2
  ENTRY &x &y
  &t1=string.cut("&x",-1.)
  &t2=string.cut("&y",-1.)
  &d1="S"+"&t1"+"A"+"&t2"
  &d2="S"+"&t1"+"AR"+"&t2"
  &d3="S"+"&t1"+"WR"+"&t2"
  &d4="S"+"&t1"+"D"+"&t2"
  &d5="S"+"&t1"+"C"+"&t2"

  &a1=dialog.string(&d1)
  &a2=dialog.string(&d2)
  GOSUB ConvRange "&a2"
  ENTRY &a2
  &a3=dialog.string(&d3)
  IF "&a3"=="ACCESS"
    &a3="(READ||WRITE)"
  &a4=dialog.string(&d4)
  GOSUB ConvDaCo "&a4"
  ENTRY &a4
  &a5=dialog.string(&d5)
  GOSUB ConvDaCo "&a5"
  ENTRY &a5
  RETURN "&a1" &a2 &a3 &a4 &a5

ConvRange:
  LOCAL &ran
  ENTRY &ran

  IF &ran!=""
  (
    IF &ran=="A-Range"
      &ran="AB"
    ELSE IF &ran=="B-Range"
      &ran="BB"
    ELSE IF &ran=="C-Range"
      &ran="CB"
    ELSE IF &ran=="AB-Range"
      &ran="AB&&BB"
    ELSE IF &ran=="AC-Range"
      &ran="AB&&CB"
    ELSE IF &ran=="BC-Range"
      &ran="BB&&CB"
    ELSE IF &ran=="ABC-Range"
      &ran="AB&&BB&&CB"
    ELSE IF &ran=="NOT A-Range"
      &ran="!AB"
    ELSE IF &ran=="NOT B-Range"
      &ran="!BB"
    ELSE IF &ran=="NOT C-Range"
      &ran="!CB"
    ELSE IF &ran=="NOT AB-Range"
      &ran="!(AB&&BB)"
    ELSE IF &ran=="NOT AC-Range"
      &ran="!(AB&&CB)"
    ELSE IF &ran=="NOT BC-Range"
      &ran="!(BB&&CB)"
    ELSE IF &ran=="NOT ABC-Range"
      &ran="!(AB&&BB&&CB)"
    ELSE
      &ran="ERROR"
  )
  ELSE
    &ran=""
  RETURN &ran

ConvDaCo:
  LOCAL &bed &not
  ENTRY &bed
  IF &bed!=""
  (
    &not=string.mid(&bed,0.,3.)
    IF "&not"=="NOT"
    (
      &not=string.mid(&bed,4.,2.)
      IF "&not"=="DA"
        &not=string.mid(&bed,4.,5.)
      ELSE IF "&not"=="CO"
        &not=string.mid(&bed,4.,6.)
      &bed="!"+"&not"
    )
    ELSE
    (
      &not=&bed
      &bed="&not"
    )
  )
  ELSE
    &bed=""
  RETURN &bed

WriteActLine:
  LOCAL &addr &sact &addrc &out &count &level &noco &continue &lev
  ENTRY &lev &addr &sact &addrc &noco

  &count=0y00
  &level=0y00
  IF &hac==1.
  (
    IF ((&hacmod==1.&&&lev==2.)||(&hacmod==2.&&&lev==1.))
    (
      IF string.find("&addr","COUNT")
      (
        LOCAL &xb &xe &sb &se
        &xb=string.scan("&addr","COUNT",0.)
        IF &xb>=0.
        (
          &sb=string.mid("&addr",0.,&xb)
          &se=string.mid("&addr",&xb+7.,100.)
          &addr="&sb"+"DELAY"+"&se"
        )
      )
    )
  )

  IF &sact=="Sample"
  (
    IF &noco==0.
    (
      &out=";#SE,"+"&addrc"
      WRITE #1 "&out"
    )
    IF "&addr"==""||"&addr"=="TRUE"
      &out="SAMPLE.ENABLE"
    ELSE
      &out="SAMPLE.ENABLE IF "+"&addr"
    WRITE #1 "&out"
  )
  ELSE IF &sact=="Stop Analyzer"
  (
    IF &noco==0.
    (
      &out=";#STA,"+"&addrc"
      WRITE #1 "&out"
    )
    IF !fire()
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="BREAK"
      ELSE
        &out="BREAK IF "+"&addr"
      WRITE #1 "&out"
    )
    ELSE
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="BREAK.TRACE"
      ELSE
        &out="BREAK.TRACE IF "+"&addr"
      WRITE #1 "&out"
    )
  )
  ELSE IF &sact=="Stop CPU&Analyzer"
  (
    IF &noco==0.
    (
      &out=";#STC,"+"&addrc"
      WRITE #1 "&out"
    )
    IF !fire()
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="TRIGGER.A"
      ELSE
        &out="TRIGGER.A IF "+"&addr"
      WRITE #1 "&out"
    )
    ELSE
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="BREAK.PROGRAM"
      ELSE
        &out="BREAK.PROGRAM IF "+"&addr"
      WRITE #1 "&out"
    )
  )
  ELSE IF &sact=="Goto Level1"||&sact=="Goto Level2"||&sact=="Goto Level0"
  (
    LOCAL &snr
    &snr=string.mid(&sact,10.,1.)
    IF &noco==0.
    (
      &out=";#GS"+"&snr"+","+"&addrc"
      WRITE #1 "&out"
    )
    &continue=0.
    IF &hac==1.&&&sact!="Goto Level0"
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="CONTINUE"
      ELSE
        &out="CONTINUE IF "+"&addr"
      &continue=1.
    )
    IF &continue==0.
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="GOTO LEVEL"+"&snr"
      ELSE
        &out="GOTO LEVEL"+"&snr"+" IF "+"&addr"
    )
    WRITE #1 "&out"
    IF &snr==0.
      &level=0y1
    ELSE IF &snr==1.
      &level=0y10
    ELSE IF &snr==2.
      &level=0y100
  )
  ELSE IF &sact=="Inc COUNT0"||&sact=="Inc COUNT1"
  (
    LOCAL &snr
    &snr=string.mid(&sact,9.,1.)
    IF &noco==0.
    (
      &out=";#IC"+"&snr"+","+"&addrc"
      WRITE #1 "&out"
    )
    IF &hac==1.&&((&hacmod==1.&&&lev==2.)||(&hacmod==2.&&&lev==1.))
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="COUNT.ENABLE DELAY"
      ELSE
        &out="COUNT.ENABLE DELAY IF "+"&addr"
    )
    ELSE
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="COUNT.ENABLE COUNT"+"&snr"
      ELSE
        &out="COUNT.ENABLE COUNT"+"&snr"+" IF "+"&addr"
    )
    WRITE #1 "&out"
    IF &snr==0.
      &count=0y01
    ELSE
      &count=0y10
  )
  ELSE IF &sact=="Restart COUNT0"||&sact=="Restart COUNT1"
  (
    LOCAL &snr
    &snr=string.mid(&sact,13.,1.)
    IF &noco==0.
    (
      &out=";#RC"+"&snr"+","+"&addrc"
      WRITE #1 "&out"
    )
    IF &hac==1.&&((&hacmod==1.&&&lev==2.)||(&hacmod==2.&&&lev==1.))
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="COUNT.RESTART DELAY"
      ELSE
        &out="COUNT.RESTART DELAY IF "+"&addr"
    )
    ELSE
    (
      IF "&addr"==""||"&addr"=="TRUE"
        &out="COUNT.RESTART COUNT"+"&snr"
      ELSE
        &out="COUNT.RESTART COUNT"+"&snr"+" IF "+"&addr"
    )
    WRITE #1 "&out"
    IF &snr==0.
      &count=0y01
    ELSE
      &count=0y10
  )
  ELSE IF &sact=="Mark A"||&sact=="Mark B"||&sact=="Mark C"
  (
    LOCAL &snr
    &snr=string.mid(&sact,5.,1.)
    IF &noco==0.
    (
      &out=";#M"+"&snr"+","+"&addrc"
      WRITE #1 "&out"
    )
    IF "&addr"==""||"&addr"=="TRUE"
      &out="MARK."+"&snr"
    ELSE
      &out="MARK."+"&snr"+" IF "+"&addr"
    WRITE #1 "&out"
  )
  RETURN &count &level

CheckBed:
  LOCAL &ad &add &sa1 &sa2 &sa3 &sa4 &sa5 &addr &mask
  ENTRY &ad &add &sa1 &sa2 &sa3 &sa4 &sa5

  &addr="x"
  IF &sa1==""&&"&sa2"==""&&"&sa3"==""&&"&sa4"==""&&"&sa5"==""
    &addr=""

  IF (&sa1=="Restart COUNT0"||&sa1=="Inc COUNT0")
  (
    &mask=&ad&0y0000010
    IF &mask==0y0
    (
      GOSUB ShowError "Action on COUNT0: COUNT0 not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1111101
  )
  IF (&sa1=="Restart COUNT1"||&sa1=="Inc COUNT1")
  (
    &mask=&ad&0y0000001
    IF &mask==0y0
    (
      GOSUB ShowError "Action on COUNT1: COUNT1 not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1111110
  )
  IF ("&sa2"=="COUNT0"||"&sa2"=="!COUNT0"||"&sa3"=="COUNT0"||"&sa3"=="!COUNT0"||"&sa4"=="COUNT0"||"&sa4"=="!COUNT0"||"&sa5"=="COUNT0"||"&sa5"=="!COUNT0")
  (
    &mask=&ad&0y0000010
    IF &mask==0y0
    (
      GOSUB ShowError "Condition COUNT0: COUNT0 not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1111101
  )
  IF ("&sa2"=="COUNT1"||"&sa2"=="!COUNT1"||"&sa3"=="COUNT1"||"&sa3"=="!COUNT1"||"&sa4"=="COUNT1"||"&sa4"=="!COUNT1"||"&sa5"=="COUNT1"||"&sa5"=="!COUNT1")
  (
    &mask=&ad&0y0000001
    IF &mask==0y0
    (
      GOSUB ShowError "Condition COUNT1: COUNT1 not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1111110
  )
  IF ("&sa2"=="DATA0"||"&sa2"=="!DATA0"||"&sa3"=="DATA0"||"&sa3"=="!DATA0"||"&sa4"=="DATA0"||"&sa4"=="!DATA0")
  (
    &mask=&ad&0y0001000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition DATA0: DATA0 not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1110111
  )
  IF ("&sa2"=="DATA1"||"&sa2"=="!DATA1"||"&sa3"=="DATA1"||"&sa3"=="!DATA1"||"&sa4"=="DATA1"||"&sa4"=="!DATA1")
  (
    &mask=&ad&0y0000100
    IF &mask==0y0
    (
      GOSUB ShowError "Condition DATA1: DATA1 not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1111011
  )
  IF ("&sa2"=="AB"||"&sa2"=="AB&&BB"||"&sa2"=="AB&&CB"||"&sa2"=="AB&&BB&&CB")
  (
    &mask=&ad&0y1000000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition A-Range: A-Range not/wrong defined!"
      &addr=""
    )
    &add=&add&0y0111111
  )
  IF ("&sa2"=="!AB"||"&sa2"=="!(AB&&BB)"||"&sa2"=="!(AB&&CB)"||"&sa2"=="!(AB&&BB&&CB)")
  (
    &mask=&ad&0y1000000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition A-Range: A-Range not/wrong defined!"
      &addr=""
    )
    &add=&add&0y0111111
  )
  IF ("&sa2"=="BB"||"&sa2"=="AB&&BB"||"&sa2"=="BB&&CB"||"&sa2"=="AB&&BB&&CB")
  (
    &mask=&ad&0y0100000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition B-Range: B-Range not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1011111
  )
  IF ("&sa2"=="!BB"||"&sa2"=="!(AB&&BB)"||"&sa2"=="!(BB&&CB)"||"&sa2"=="!(AB&&BB&&CB)")
  (
    &mask=&ad&0y0100000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition B-Range: B-Range not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1011111
  )
  IF ("&sa2"=="CB"||"&sa2"=="AB&&CB"||"&sa2"=="BB&&CB"||"&sa2"=="AB&&BB&&CB")
  (
    &mask=&ad&0y0010000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition C-Range: C-Range not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1101111
  )
  IF ("&sa2"=="!CB"||"&sa2"=="!(AB&&CB)"||"&sa2"=="!(BB&&CB)"||"&sa2"=="!(AB&&BB&&CB)")
  (
    &mask=&ad&0y0010000
    IF &mask==0y0
    (
      GOSUB ShowError "Condition C-Range: C-Range not/wrong defined!"
      &addr=""
    )
    &add=&add&0y1101111
  )
  RETURN "&addr" &add

ShowUnusedDefs:
  LOCAL &def &ret
  ENTRY &def
  &ret=0.
  &mask=&def&0y0000010
  IF &mask!=0y0&&&hac==0.
    GOSUB ShowWarn "COUNT0 defined but not used!"
  ELSE IF &mask!=0y0&&&hac==1.
  (
    GOSUB ShowError "COUNT0 defined but not used!"
    &ret=-1.
  )
  &mask=&def&0y0000001
  IF &ret==0.&&&mask!=0y0&&&hac==0.
    GOSUB ShowWarn "COUNT1 defined but not used!"
  ELSE IF &mask!=0y0&&&hac==1.
  (
    GOSUB ShowError "COUNT1 defined but not used!"
    &ret=-1.
  )

  &mask=&def&0y0000100
  IF &ret==0.&&&mask!=0y0
    GOSUB ShowWarn "DATA1 defined but not used!"
  &mask=&def&0y0001000
  IF &ret==0.&&&mask!=0y0
    GOSUB ShowWarn "DATA0 defined but not used!"
  &mask=&def&0y1000000
  IF &ret==0.&&&mask!=0y0
    GOSUB ShowWarn "A-Range defined but not used!"
  &mask=&def&0y0100000
  IF &ret==0.&&&mask!=0y0
    GOSUB ShowWarn "B-Range defined but not used!"
  &mask=&def&0y0010000
  IF &ret==0.&&&mask!=0y0
    GOSUB ShowWarn "C-Range defined but not used!"
  RETURN &ret


InitProgram:
  IF &subdialog!=0.
  (
    LOCAL &TEXT
    IF &subdialog==1.
      &TEXT="Please close Define Address Window first!"
    ELSE IF &subdialog==2.
      &TEXT="Please close Define Data Window first!"
    ELSE IF &subdialog==3.
      &TEXT="Please close Define Count Window first!"
    PRINT %ERROR "&TEXT"
  )
  ELSE
  (
    GOSUB InitDialogS1
    IF &debug==1.
      do readanaprogram &adir
    ELSE
      do ~~/demo/analyzer/trigger/readanaprogram &adir
    ENTRY %line &adir
  )
  RETURN

SetDir:
  LOCAL &i &j &p &file
  ENTRY %line &file
  &i=0.
  &j=string.len("&file")-1.
  &p=string.mid("&file",&j,1.)
  while "&p"!="/"&&"&p"!="\"&&&j>0.
  (
    &j=&j-1.
    &p=string.mid("&file",&j,1.)
    &i=&i+1.
  )
  IF &j>0.
  (
    &adir=string.cut("&file",-&i)
    &adir="&adir"+"*.ts"
  )
  ELSE
    &adir="*.ts"
  RETURN
; --------------------------------------------------------------------------------
;                          Spezialitaeten 166 Bondout
; --------------------------------------------------------------------------------
GetTrace:
  &oaw=0.
  &oar=0.
  &oaw1=""
  &oaw2=""
  &oar1=""
  &oar2=""
  &ab=""
  &bb=""
  &cb=""
  IF cpubondout()!=""&&ice()&&system.traceint()
     &trace=1.
  ELSE IF cpubondout()!=""&&fire()
     &trace=3.
  ELSE IF cpufamily()=="XA"&&system.traceint()
     &trace=2.
  ELSE
     &trace=0.
  RETURN

BreakDel166:
  LOCAL &ret
  &ret=1.
  IF &trace==1.
  (
    GOSUB WarnCancel "For programming all current breakpoints will be delete! Continue?"
    ENTRY &ret
    IF &ret!=0.
      b.d /anh
  )
  RETURN &ret

SetData166:
  LOCAL &nr &type &val &POS &pos2 &xx &xy &xz
  ENTRY &nr &type &val
  &POS=string.mid("&val",0.,1.)
  &pos2=string.mid("&val",1.,1.)
  &xx=string.scan("&val","x",0.)
  &xy=string.scan("&val","X",0.)
  &xz=string.mid("&val",string.len("&val")-1.,1.)
  IF "&POS"=="0"&&("&pos2"=="y"||"&pos2"=="Y")&&&xx==-1.&&&xy==-1.
    &val="P:"+"&val"
  IF radix()==0.&&"&xz"=="!"&&&xx==-1.&&&xy==-1.
    &val="P:"+"&val"
  IF &nr==0.
  (
    ; b.s &val /od
    &POS="ADDR OD "+"&val"
    WRITE #1 "&POS"
  )
  ELSE
  (
    b.s &val /odx
    &POS="ADDR ODX "+"&val"
    WRITE #1 "&POS"
  )
  RETURN

SetData166Fire:
  RETURN

SetCondition166:
  LOCAL &sa1 &sa2 &sa3 &sa4 &sat1 &sat2 &sat3 &saa &sab &sac &not
  ENTRY &sa1 &sa2 &sa3 &sa4
  ;trace=1. -> c166
  ;trace=2. -> XA
  IF &trace==1.||&trace==2.||&trace==3.
  (
    IF &trace==1.
    (
      GOSUB SetOD &sa1 &sa2 &sa3
      ENTRY &sat1 &sat2 &sat3
      IF "&sat1"!="0."
        &sa1="&sat1"
      ELSE IF "&sat2"!="0."
      (
        IF "&sa3"==""
          &sa3="&sat2"
        ELSE
          &sa2="&sat2"
      )
      ELSE IF "&sat3"!="0."
        &sa3="&sat3"
    )

    IF &trace==3.
    (
      GOSUB SetODFire &sa1 &sa2 &sa3
      ENTRY &sat1 &sat2 &sat3
      IF "&sat1"!="0."
        &sa1="&sat1"
      ELSE IF "&sat2"!="0."
      (
        IF "&sa3"==""
          &sa3="&sat2"
        ELSE
          &sa2="&sat2"
      )
      ELSE IF "&sat3"!="0."
        &sa3="&sat3"
    )

    &not=string.mid("&sa1",0.,1.)
    IF string.find("&sa1","&&")&&"&not"=="!"
      &not="!("
    IF "&not"!="!"&&"&not"!="!("
      &not=""
    IF "&sa1"=="AB"||"&sa1"=="!AB"||"&sa1"=="AB&&BB"||"&sa1"=="AB&&CB"||"&sa1"=="!(AB&&BB)"||"&sa1"=="!(AB&&CB)"||"&sa1"=="AB&&BB&&CB"||"&sa1"=="!(AB&&BB&&CB)"
    (
      IF "&ab"!=""
      (
        IF string.find("&ab","||")
          &saa="("+"&ab"+")"
        ELSE
          &saa="&ab"
        IF "&not"=="!"
          &saa="!"+"&sa1"
        IF string.find("&ab","OA")||string.find("&ab","ABR")||string.find("&ab","ABW")
        (
          IF "&sa2"=="READ"||"&sa2"=="WRITE"||"&sa2"=="(READ||WRITE)"
            &sa2=""
        )
        IF &trace==3.&&string.find("&ab","AB")
        (
          IF "&sa2"=="READ"||"&sa2"=="WRITE"||"&sa2"=="(READ||WRITE)"
            &sa2=""
        )
        IF "&sa1"=="AB"||"&sa1"=="!AB"
          &sa1="&saa"
      )
    )
    IF "&sa1"=="BB"||"&sa1"=="!BB"||"&sa1"=="AB&&BB"||"&sa1"=="BB&&CB"||"&sa1"=="!(AB&&BB)"||"&sa1"=="!(BB&&CB)"||"&sa1"=="AB&&BB&&CB"||"&sa1"=="!(AB&&BB&&CB)"
    (
      IF "&bb"!=""
      (
        IF string.find("&bb","||")
          &sab="("+"&bb"+")"
        ELSE
          &sab="&bb"
        IF "&not"=="!"
          &sab="!"+"&sa1"
        IF string.find("&bb","OA")||string.find("&bb","BBR")||string.find("&bb","BBW")
        (
          IF "&sa2"=="READ"||"&sa2"=="WRITE"||"&sa2"=="(READ||WRITE)"
            &sa2=""
        )
        IF &trace==3.&&string.find("&bb","BB")
        (
          IF "&sa2"=="READ"||"&sa2"=="WRITE"||"&sa2"=="(READ||WRITE)"
            &sa2=""
        )
        IF "&saa"!=""&&"&not"=="!("&&"&sa1"!="!(AB&&BB&&CB)"
          &sa1="&not"+"&saa"+"&&"+"&sab"+")"
        ELSE IF "&saa"!=""&&"&not"==""&&"&sa1"!="AB&&BB&&CB"
          &sa1="&saa"+"&&"+"&sab"
        ELSE IF "&sa1"=="BB"||"&sa1"=="!BB"
          &sa1="&sab"
      )
    )
    IF "&sa1"=="CB"||"&sa1"=="!CB"||"&sa1"=="AB&&CB"||"&sa1"=="BB&&CB"||"&sa1"=="!(AB&&CB)"||"&sa1"=="!(BB&&CB)"||"&sa1"=="AB&&BB&&CB"||"&sa1"=="!(AB&&BB&&CB)"
    (
      IF "&cb"!=""
      (
        IF string.find("&cb","||")
          &sac="("+"&cb"+")"
        ELSE
          &sac="&cb"
        IF "&not"=="!"
          &sac="!"+"&sa1"
        IF string.find("&cb","OA"); CBR oder CBW müssen hier noch berücksichtigt werden
        (
          IF "&sa2"=="READ"||"&sa2"=="WRITE"||"&sa2"=="(READ||WRITE)"
            &sa2=""
        )
        IF &trace==3.&&string.find("&cb","CB")
        (
          IF "&sa2"=="READ"||"&sa2"=="WRITE"||"&sa2"=="(READ||WRITE)"
            &sa2=""
        )
        IF "&saa"!=""&&"&sab"!=""&&"&not"=="!("
          &sa1="&not"+"&saa"+"&&"+"&sab"+"&&"+"&sac"+")"
        ELSE IF "&saa"!=""&&"&sab"!=""&&"&not"==""
          &sa1="&saa"+"&&"+"&sab"+"&&"+"&sac"
        ELSE IF "&saa"!=""&&"&not"=="!("
          &sa1="&not"+"&saa"+"&&"+"&sac"+")"
        ELSE IF "&saa"!=""&&"&not"==""
          &sa1="&saa"+"&&"+"&sac"
        ELSE IF "&sab"!=""&&"&not"=="!("
          &sa1="&not"+"&sab"+"&&"+"&sac"+")"
        ELSE IF "&sab"!=""&&"&not"==""
          &sa1="&sab"+"&&"+"&sac"
        ELSE IF "&sa1"=="CB"||"&sa1"=="!CB"
          &sa1="&sac"
      )
    )
  )
  RETURN &sa1 &sa2 &sa3 &sa4

SetOD:
  LOCAL &sa1 &sa2 &sa3
  ENTRY &sa1 &sa2 &sa3
  IF "&sa1"=="DATA0"
    &sa1="OD"
  ELSE IF "&sa1"=="DATA1"
    &sa1="ODX"
  ELSE IF "&sa1"=="!DATA0"
    &sa1="!OD"
  ELSE IF "&sa1"=="!DATA1"
    &sa1="!ODX"
  ELSE
    &sa1=0.

  IF "&sa2"=="DATA0"
    &sa2="OD"
  ELSE IF "&sa2"=="DATA1"
    &sa2="ODX"
  ELSE IF "&sa2"=="!DATA0"
    &sa2="!OD"
  ELSE IF "&sa2"=="!DATA1"
    &sa2="!ODX"
  ELSE
    &sa2=0.

  IF "&sa3"=="DATA0"
    &sa3="OD"
  ELSE IF "&sa3"=="DATA1"
    &sa3="ODX"
  ELSE IF "&sa3"=="!DATA0"
    &sa3="!OD"
  ELSE IF "&sa3"=="!DATA1"
    &sa3="!ODX"
  ELSE
    &sa3=0.

  RETURN &sa1 &sa2 &sa3


SetODFire:
  LOCAL &sa1 &sa2 &sa3
  ENTRY &sa1 &sa2 &sa3
  IF "&sa1"=="DATA0"
    &sa1=""
  ELSE IF "&sa1"=="DATA1"
    &sa1=""
  ELSE IF "&sa1"=="!DATA0"
    &sa1=""
  ELSE IF "&sa1"=="!DATA1"
    &sa1=""
  ELSE
    &sa1=0.

  IF "&sa2"=="DATA0"
    &sa2=""
  ELSE IF "&sa2"=="DATA1"
    &sa2=""
  ELSE IF "&sa2"=="!DATA0"
    &sa2=""
  ELSE IF "&sa2"=="!DATA1"
    &sa2=""
  ELSE
    &sa2=0.

  IF "&sa3"=="DATA0"
    &sa3=""
  ELSE IF "&sa3"=="DATA1"
    &sa3=""
  ELSE IF "&sa3"=="!DATA0"
    &sa3=""
  ELSE IF "&sa3"=="!DATA1"
    &sa3=""
  ELSE
    &sa3=0.

  RETURN &sa1 &sa2 &sa3

; --------------------------------------------------------------------------------
;                             Diverse Hilfsroutinen
; --------------------------------------------------------------------------------

CheckData:
  LOCAL &dval &dtype &dmax &x
  ENTRY &dval &dtype
  on error GOSUB
  (
    &dval=""
    RETURN
  )
  EVAL &dval
  &x=eval.type()
  IF (&x==&DAddress||&x==&DARange||&x==&DEmpty||&x==&DTime||&x==&DTRange)&&"&dval"!=""
  (
    &x="&dval"+" no valid data value!"
    PRINT %ERROR "&x"
    &dval=""
  )
  IF &x!=&DBitmask&&&x!=&DAscii&&&x!=&DString
  (
    GOSUB GetMaxDataVal &dtype
    ENTRY &dmax
    IF &dval>&dmax
    (
      &x="&dval"+" bigger than "+"&dmax"+" (maximum for "+"&dtype"+" )!"
      PRINT %ERROR "&x"
      &dval=""
    )
  )
  RETURN &dval

GetMaxDataVal:
  LOCAL &smax &type &type1
  ENTRY &type
  IF "&type"!=""
  (
    &type1=string.mid("&type",0.,1.)
    IF "&type1"=="B"
      &smax=255.
    ELSE IF "&type1"=="T"
      &smax=4095.
    ELSE IF "&type1"=="W"
      &smax=65535.
    ELSE IF "&type1"=="L"
      &smax=4.3e+9
  )
  ELSE
  (
    IF A.CONFIG.HAC()
      &smax=65535.
    ELSE
      &smax=5.5e+11
  )
  RETURN &smax

GetMaxCountVal:
  LOCAL &cnr &smax &unit
  ENTRY &cnr &unit
  IF "&unit"!=""
  (
    IF A.CONFIG.HAC()
      &smax=0.000065
    ELSE IF A.CONFIG.FEC()
      &smax=0.0053
    ELSE IF A.CONFIG.ECC8()
    (
      IF &cnr==1.
        &smax=0.0000065
      ELSE
        &smax=0.429
    )
    ELSE IF A.CONFIG.HA120()
      &smax=13.680
    ELSE IF A.CONFIG.SA120()
      &smax=12960.
    IF "&unit"!="ks"
    (
      &smax=&smax*1000.
      IF "&unit"!="s"
      (
        &smax=&smax*1000.
        IF "&unit"!="ms"
        (
          &smax=&smax*1000.
          IF "&unit"!="us"
            &smax=&smax*1000.
        )
      )
    )
  )
  ELSE
  (
    IF A.CONFIG.HAC()
      &smax=65535.
    ELSE IF A.CONFIG.FEC()
      &smax=2.6e+8
    ELSE IF A.CONFIG.ECC8()
    (
      IF &cnr==1.
        &smax=65535.
      ELSE
        &smax=4.2e+9
    )
    ELSE IF A.CONFIG.FEC()
      &smax=2.6e+8
    ELSE IF A.CONFIG.HA120()
      &smax=5.5e+11
    ELSE
      &smax=2.8e+14
  )
  RETURN &smax


ShowVersion:
; --------------------------------------------------------------------------------
;                             Dialoge
; --------------------------------------------------------------------------------
  PRINT "Version 1.7.0: 20.06.2001"
  RETURN

WarnCancel:
   LOCAL &stext &TEXT &ret
   ENTRY &stext
   &ret=1.
   &TEXT=&stext
   PRINT ""
   dialog
   (
          header "WARNING"
          POS 1. 1. 50.
     TEXT:EDIT "" ""
          POS 1. 3. 5.
          DEFBUTTON "OK" "goto oclose"
          POS 7. 3. 6.
          BUTTON "CANCEL" "goto canclose"
          CLOSE "goto oclose"
   )
   DIALOG.SET TEXT "&TEXT"
   stop
canclose:
   &ret=0.
oclose:
   DIALOG.END
   RETURN &ret

ShowError:
   LOCAL &stext &TEXT
   ENTRY &stext
   &TEXT=&stext
   PRINT ""
   dialog
   (
     header "ERROR"
     POS 1. 1. 40.
TEXT:EDIT "" ""
     POS 1. 3. 5.
     DEFBUTTON "OK" "goto occlose"
     CLOSE "goto occlose"
   )
   DIALOG.SET TEXT "&TEXT"
   stop
occlose:
   DIALOG.END

   RETURN

ShowWarn:
  LOCAL &stext &TEXT
  ENTRY &stext
  &TEXT=&stext
  PRINT ""
  dialog
  (
         header "WARNING"
         POS 1. 1. 50.
    TEXT:EDIT "" ""
         POS 1. 3. 5.
         DEFBUTTON "OK" "goto occclose"
         CLOSE "goto occclose"
  )
  DIALOG.SET TEXT "&TEXT"
  stop
occclose:
  DIALOG.END

  RETURN
