*-----------------------------------------------------------------------------
*  Error messages
*-----------------------------------------------------------------------------
*  Module Description
*     Event mask in file EVENT.MEV
*     after translation see EVENT.PEV
*       SPAWN_ERROR;$MG_Error_marker_delete$==1;$0001;
*       SPAWN_ERROR;$NP_W274_code_pushed_key$==430;$0002;
*
*     Errors are diplayed beginning on the number who is in
*       KL_start_address_PET     K+xxx
*     defined.
*     In the PET table all errors from this range must have the property
*     "CE clears message" off (No=1).
*
*-----------------------------------------------------------------------------

#define /s    KL_start_address_PET                     K +200
#define /s    KL_wait_for_events                       K -1
#define /s    KL_event_gated_with_or                   K +0
#define /s    KL_event_masks                           K %011
#define /s    KL_active_PLC_error_message              K -2
#define /s    KL_error_displayed                       K +0

#define /s    ML_error_display_active                  M

#define /s    BL_staus_SUBM                            B

#define /s    DL_spawn_error_display                   D

#include Mac_Lib.inc

GLOBAL Error

;----------------------------
LBL Error

  L      K+0
  =X

  REPEAT
    L      MG_error[X]
*$WS Workaround NC Fehler (Spawn): bei häufiger CE-Tasten Betätigung wird Fehlermeldung nicht mehr angezeigt
;    AN     MG_Fehler_alt[X]
    IFT
      LX
      +      KL_start_address_PET
      PSW
      CM     9085                      ;PLC error display

      M_display_module_error

      L      MG_error[X]
      =      MG_error_cycle_before[X]
    ENDI

    LN     MG_error[X]
    A      MG_error_cycle_before[X]
    S      MG_error_marker_delete

    INCX

    LX
    >      K &MG_error_end - &MG_error
  UNTILT

  L      ML_error_display_active
  AN     NP_M4173_1st_PLC_run_after_compile
  EMT

  RPLY   BL_staus_SUBM
  ==     K+0
  IFT
    SUBM   Spawn_start
    =      BL_staus_SUBM
    ==     K+0
    S      PN_error_submit_spawn_queue_full
  ENDI

EM

;----------------------------
LBL Spawn_start

  SPAWN  Spawn_error
  =      DL_spawn_error_display
  ==     K-1
  S      PN_error_submit_spawn_queue_full

EM

;----------------------------
LBL Spawn_error

  L      MG_marker_one
  S      ML_error_display_active

  REPEAT
    PS     KL_wait_for_events
    PS     KL_event_gated_with_or
    PS     KL_event_masks
    CM     9260                        ;Receive or wait for events
    PLW
    PSW
    BT     K+0
    CMT    Error_marker_delete

    PLW
    BT     K+1
    CMT    CE_key

    M_display_module_error

    LN     ML_error_display_active
  UNTILT

  L      MG_marker_one
  R      ML_error_display_active

EM

;----------------------------
LBL Error_marker_delete

  L      K+0
  =X
  REPEAT

    LN     MG_error[X]
    A      MG_error_cycle_before[X]
    IFT
      LX
      +      KL_start_address_PET
      PSW
      CM     9086                      ;PLC error delete

      M_display_module_error

      L      MG_error[X]
      =      MG_error_cycle_before[X]
    ENDI

    INCX

    LX
    >      K &MG_error_end - &MG_error
    R      MG_error_marker_delete
  UNTILT

EM

;----------------------------
LBL CE_key

  L      K+0
  =X

  REPEAT
    LX
    +      KL_start_address_PET
    PSW
    CM     9087

      M_display_module_error

    PLW
    BT     KL_error_displayed
    IFT
      LX
      +      KL_start_address_PET
      PSW
      CM     9086                      ;PLC error delete
      M_display_module_error

      L      MG_marker_one
      R      MG_error[X]
      R      MG_error_cycle_before[X]
    ENDI

    INCX

    LX
    >      K &MG_error_end - &MG_error
  UNTILT

EM
