; ---------------------------------------------------------------------------
; codeflash_read.cmm
;
; This script is READING the complete codeflash area and saving it to a FILE
;
; NOTE: this script must be executed from the CYT2B Master-GUI (CM0+ Core)
;
; ---------------------------------------------------------------------------
  PMACRO.EXPLICIT

  ; show path and name of this script (present practice file)
  ECHO ""
  ECHO %COLOR.BLUE "### " OS.PPF() " ###"

; ---------------------------------------------------------------------------
  PRIVATE &filename &extension

; ---------------------------------------------------------------------------
; dialog to select the filename
  DIALOG.File.SELECT "*.hex"
  ENTRY %LINE &filename

  IF "&filename"!=""
  (
    IF OS.FILE.EXTENSION(&filename)==""
    (
      &filename="&filename.hex"
    )

    ECHO %COLOR.GREEN "Saving codeflash &codeflash_range to &filename"

    SYStem.Up

    FLASH.AUTO &codeflash_range

    Data.SAVE.S3record &filename &codeflash_range /SkipErrors

    FLASH.AUTO CANCEL
  )
  ELSE
  (
    ECHO %COLOR.RED "ERROR: No file name specified!"
  )

  ENDDO

