; --------------------------------------------------------------------------------
; @Title: Practice example that creates a log file using a message area
; @Description:
;   This example script shows how to create a log file using the message area
;   window. The log is store to the file testreprt_<cpu>_<date>_<time>.txt
;   For more information please refer to training_practice.pdf and ide_use.pdf
; @Keywords: area, logfile, logging, practice
; @Author: REI
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: area_log.cmm 13368 2018-10-23 10:52:22Z smeister $

  PRIVATE &sepline &timestr &filename &address
  &sepline="-">>80.

;create a new message area (here with name "REPORT")
  AREA.Create REPORT
  AREA.CLEAR  REPORT
  AREA.view   REPORT

;generate log file name
  &timestr=FORMAT.UnixTime("Ymd_His+",DATE.UnixTime(),0)
  &filename=OS.PPD()+"\testreport_"+CPU()+"_&timestr.txt"

;open file to receive message area outputs
  AREA.OPEN REPORT &filename

;now all PRINT outputs are stored to log.txt
  PRINT "Start of test report"
  PRINT "&sepline"

  PRINT "Connecting to target... "

  ON ERROR CONTinue     ;continue script execution in error case
  SYStem.Up
  ON ERROR              ;default: stop script execution in error case

  IF (SYStem.Mode()==0)
  (
    PRINT %CONTinue "failed."
    JUMPTO end_report
  )
  PRINT %CONTinue "success."

  PRINT "Instruction pointer at reset: 0x"+FORMAT.HEX(8.,Register(PP))

  &address=Register(PP)
  PRINT "Data at address 0x"+FORMAT.HEX(8.,&address)+":   "
  PRINT %CONTinue "0x"+FORMAT.HEX(8.,Data.Long(P:&address))

end_report:
  PRINT "&sepline"
  PRINT "End of test report."
;close file
  AREA.CLOSE REPORT

;open log file in editor to show result
  EDIT &filename

ENDDO
